From 21e7318ac8157a2032177e8df64fb89f80127a09 Mon Sep 17 00:00:00 2001 From: Navnath Jadhav <131193155+Navnathjadhav08@users.noreply.github.com> Date: Tue, 12 Sep 2023 22:51:39 +0530 Subject: [PATCH] Update RewardsConverter.java --- src/main/java/RewardsConverter.java | 31 ++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/main/java/RewardsConverter.java b/src/main/java/RewardsConverter.java index 2c35d11a5..276c3e6d7 100644 --- a/src/main/java/RewardsConverter.java +++ b/src/main/java/RewardsConverter.java @@ -17,4 +17,33 @@ public static void main(String[] args) { var rewardsValue = new RewardValue(cashValue); System.out.println("$" + input_value + " is worth " + rewardsValue.getMilesValue() + " miles"); } -} \ No newline at end of file +} + +public class RewardValue { + private final double cashValue; + public static final double MILES_TO_CASH_CONVERSION_RATE = 0.0035; + + public RewardValue(double cashValue) { + this.cashValue = cashValue; + } + + public RewardValue(int milesValue) { + this.cashValue = convertToCash(milesValue); + } + + private static int convertToMiles(double cashValue) { + return (int) (cashValue / MILES_TO_CASH_CONVERSION_RATE); + } + + private static double convertToCash(int milesaValue) { + return milesaValue * MILES_TO_CASH_CONVERSION_RATE; + } + + public double getCashValue() { + return cashValue; + } + + public int getMilesValue() { + return convertToMiles(this.cashValue); + } +}