diff --git a/src/main/java/RewardValue.java b/src/main/java/RewardValue.java new file mode 100644 index 000000000..2c55ea737 --- /dev/null +++ b/src/main/java/RewardValue.java @@ -0,0 +1,27 @@ +public class RewardValue { + private Double Cash = null; + private Integer Miles = null; + public static final double MILES_TO_CASH = 0.0035; + + public RewardValue(double CashValue) { + this.Cash = CashValue; + } + + public RewardValue(int MilesValue) { + this.Miles = MilesValue; + } + + public double getCashValue() { + if (Cash != null) { + return Cash; + } + return MILES_TO_CASH * Miles; + } + + public Integer getMilesValue() { + if (Miles != null) { + return Miles; + } + return (int) (1 / MILES_TO_CASH * Cash); + } +} diff --git a/src/test/java/RewardValueTests.java b/src/test/java/RewardValueTests.java index b3a78de7d..9688b7953 100644 --- a/src/test/java/RewardValueTests.java +++ b/src/test/java/RewardValueTests.java @@ -20,11 +20,19 @@ void create_with_miles_value() { @Test void convert_from_cash_to_miles() { - assert false; + // assert false; + double cashValue = 100; + var rewardValue = new RewardValue(cashValue); + int milesValue = rewardValue.getMilesValue(); + assertEquals(milesValue, (int) (cashValue / RewardValue.MILES_TO_CASH)); } @Test void convert_from_miles_to_cash() { - assert false; + //assert false; + int milesValue = 1000; + var rewardValue = new RewardValue(milesValue); + double cashValue = rewardValue.getCashValue(); + assertEquals(cashValue, milesValue * RewardValue.MILES_TO_CASH); } }