Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete RewardValue class and tests #1449

Open
wants to merge 2 commits into
base: flow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/RewardValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class RewardValue {
private double cashValue;
private int milesValue;

// Conversion rate from miles to cash
public static final double MILES_TO_CASH_CONVERSION_RATE = 0.0035;

// Constructor for cash value
public RewardValue(double cashValue) {
this.cashValue = cashValue;
this.milesValue = (int) (cashValue / MILES_TO_CASH_CONVERSION_RATE); // Convert cash to miles
}

// Constructor for miles value
public RewardValue(int milesValue) {
this.milesValue = milesValue;
this.cashValue = milesValue * MILES_TO_CASH_CONVERSION_RATE; // Convert miles to cash
}

// Method to get the cash value
public double getCashValue() {
return this.cashValue;
}

// Method to get the miles value
public int getMilesValue() {
return this.milesValue;
}
}
12 changes: 9 additions & 3 deletions src/test/java/RewardValueTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ void create_with_cash_value() {
void create_with_miles_value() {
int milesValue = 10000;
var rewardValue = new RewardValue(milesValue);
assertEquals(milesValue, rewardValue.getMilesValue());
assertEquals(milesValue, rewardValue.getMilesValue(), "Miles value should match");
}

@Test
void convert_from_cash_to_miles() {
assert false;
double cashValue = 100.0;
RewardValue rewardValue = new RewardValue(cashValue);
int expectedMiles = (int) (cashValue / RewardValue.MILES_TO_CASH_CONVERSION_RATE);
assertEquals(expectedMiles, rewardValue.getMilesValue(), "Cash to miles conversion failed");
}

@Test
void convert_from_miles_to_cash() {
assert false;
int milesValue = 10000;
RewardValue rewardValue = new RewardValue(milesValue);
double expectedCash = milesValue * RewardValue.MILES_TO_CASH_CONVERSION_RATE;
assertEquals(expectedCash, rewardValue.getCashValue(), "Miles to cash conversion failed");
}
}