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

Completed RewardValue Class and Unit Tests for Cash-to-Miles and Miles-to-Cash Conversions #1440

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
33 changes: 33 additions & 0 deletions src/main/java/RewardValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Make sure this matches the actual package name

public class RewardValue {
// Conversion rate from miles to cash
private static final double MILES_TO_CASH_RATE = 0.0035;

// Store the value in cash or miles
private double cashValue;
private double milesValue;

// Constructor that accepts a cash value
public RewardValue(double cashValue) {
this.cashValue = cashValue;
this.milesValue = cashValue / MILES_TO_CASH_RATE; // Convert cash to miles
}

// Constructor that accepts a miles value
public RewardValue(int milesValue) {
this.milesValue = milesValue;
this.cashValue = milesValue * MILES_TO_CASH_RATE; // Convert miles to cash
}

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

// Method to get the miles value
public double getMilesValue() {
return this.milesValue;
}
}

13 changes: 11 additions & 2 deletions src/test/java/RewardValueTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,20 @@ void create_with_miles_value() {

@Test
void convert_from_cash_to_miles() {
assert false;
double cash=100;
var rewardValue=new RewardValue(cash);
double miles=rewardValue.getMilesValue();
double milesTest=cash/0.0035;
assertEquals(miles,milesTest);
}

@Test
void convert_from_miles_to_cash() {
assert false;

int miles=1000;
double cashTest=miles*0.0035;
var rewardValue=new RewardValue(miles);
double cash=rewardValue.getCashValue();
assertEquals(cash,cashTest);
}
}