diff --git a/src/main/java/RewardValue.java b/src/main/java/RewardValue.java new file mode 100644 index 000000000..d80148e7f --- /dev/null +++ b/src/main/java/RewardValue.java @@ -0,0 +1,35 @@ + + +public class RewardValue{ + static final double mToc = 0.0035; //miles to cash conversion rate + static final double cTom = 1/mToc; //cash to miles conversion rate + static int miles; + static double cash; + + public RewardValue(double cashVal){ + cash = cashVal; + //miles = (int)(cashVal * cTom); + } + + public RewardValue(int mileage){ + miles = mileage; + //cash = mileage * mToc; + } + + public static double getCashValue(){ + return cash; + } + + public static int getMilesValue(){ + return miles; + } + + public static int convertToMiles(){ + return (int)(cash*cTom); + } + + public static double convertToCash(){ + return (miles*mToc); + } +} + diff --git a/src/test/java/RewardValueTests.java b/src/test/java/RewardValueTests.java index b3a78de7d..e6ed83cb7 100644 --- a/src/test/java/RewardValueTests.java +++ b/src/test/java/RewardValueTests.java @@ -20,11 +20,17 @@ void create_with_miles_value() { @Test void convert_from_cash_to_miles() { - assert false; + double cashValue = 100; + int expectedMiles = (int)(cashValue * RewardValue.cTom); + var rewardValue = new RewardValue(cashValue); + assertEquals(expectedMiles,rewardValue.convertToMiles()); } @Test void convert_from_miles_to_cash() { - assert false; + int milesValue = 1000; + double expectedCash = (milesValue * RewardValue.mToc); + var rewardValue = new RewardValue(milesValue); + assertEquals(expectedCash, rewardValue.convertToCash()); } }