From 3a57706ee06663abc5a5031cf1fee87afda10064 Mon Sep 17 00:00:00 2001 From: Rowan Harris Date: Sat, 17 Aug 2024 20:51:08 +0100 Subject: [PATCH 1/3] created RewardValue class --- src/main/java/RewardValue.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/RewardValue.java diff --git a/src/main/java/RewardValue.java b/src/main/java/RewardValue.java new file mode 100644 index 000000000..0abf5f164 --- /dev/null +++ b/src/main/java/RewardValue.java @@ -0,0 +1,16 @@ +import java.util.Scanner; +import java.math.BigDecimal; + +public class RewardValue{ + public static BigDecimal RewardValue(){ + + } + + public static double RewardValue(){ + + } + + public static get(){ + + } +} \ No newline at end of file From be734cdc0acb050796a1cababc60630cc877f40c Mon Sep 17 00:00:00 2001 From: Rowan Harris Date: Thu, 22 Aug 2024 12:26:24 +0100 Subject: [PATCH 2/3] create the RewardValue class --- src/main/java/RewardValue.java | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/RewardValue.java b/src/main/java/RewardValue.java index 0abf5f164..2f739d2d7 100644 --- a/src/main/java/RewardValue.java +++ b/src/main/java/RewardValue.java @@ -1,16 +1,26 @@ -import java.util.Scanner; -import java.math.BigDecimal; + public class RewardValue{ - public static BigDecimal 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 static double RewardValue(){ - + public RewardValue(int mileage){ + miles = mileage; + cash = mileage * mToc; } - public static get(){ + public static double getCashValue(){ + return cash; + } + public static int getMilesValue(){ + return miles; } } \ No newline at end of file From 1e69a438a75f4ce2270cbd36028703f15f1cddd8 Mon Sep 17 00:00:00 2001 From: Rowan Harris Date: Wed, 2 Oct 2024 14:19:51 +0100 Subject: [PATCH 3/3] added 2 tests to test suite to check conversions between cash and miles --- src/main/java/RewardValue.java | 15 ++++++++++++--- src/test/java/RewardValueTests.java | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/RewardValue.java b/src/main/java/RewardValue.java index 2f739d2d7..d80148e7f 100644 --- a/src/main/java/RewardValue.java +++ b/src/main/java/RewardValue.java @@ -8,12 +8,12 @@ public class RewardValue{ public RewardValue(double cashVal){ cash = cashVal; - miles = (int)(cashVal * cTom); + //miles = (int)(cashVal * cTom); } public RewardValue(int mileage){ miles = mileage; - cash = mileage * mToc; + //cash = mileage * mToc; } public static double getCashValue(){ @@ -23,4 +23,13 @@ public static double getCashValue(){ public static int getMilesValue(){ return miles; } -} \ No newline at end of file + + 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()); } }