diff --git a/src/main/java/RewardValue.java b/src/main/java/RewardValue.java new file mode 100644 index 000000000..44489d1ee --- /dev/null +++ b/src/main/java/RewardValue.java @@ -0,0 +1,25 @@ +public class RewardValue { + private double cashValue; + private int milesValue; + public static final double MILES_TO_CASH_RATE = 0.0035; + public RewardValue(double cashValue) + { + this.cashValue=cashValue; + this.milesValue=(int)(cashValue/MILES_TO_CASH_RATE); + } + public RewardValue(int milesValue) + { + this.milesValue=milesValue; + this.cashValue=milesValue * MILES_TO_CASH_RATE; + } + + public double getCashValue() + { + return cashValue; + } + + public int getMilesValue() + { + return milesValue; + } +} \ No newline at end of file diff --git a/src/test/java/RewardValueTests.java b/src/test/java/RewardValueTests.java index b3a78de7d..bd07108e6 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; + var rv = new RewardValue(cashValue); + int expmiles = (int) (cashValue/RewardValue.MILES_TO_CASH_RATE); + assertEquals (expmiles,rv.getMilesValue()); } @Test void convert_from_miles_to_cash() { - assert false; + int milesValue = 1000; + var rv = new RewardValue(milesValue); + double expCash = milesValue*RewardValue.MILES_TO_CASH_RATE; + assertEquals (expCash,rv.getCashValue()); } }