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

Add RewardValue class and implement cash-to-miles conversion #1445

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
5 changes: 5 additions & 0 deletions .run/rewards value.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="rewards value" type="JavascriptDebugType" uri="http://https//:C:\Users\Admin\Desktop\Github\rewards-converter\src\main\java\RewardValue.java" useFirstLineBreakpoints="true">
<method v="2" />
</configuration>
</component>
26 changes: 26 additions & 0 deletions src/main/java/RewardValue.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
public class RewardValue {
private double cashValue;
private int milesValue;

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

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

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

// Method to get miles value
public int getMilesValue() {
return milesValue;
}
}
5 changes: 3 additions & 2 deletions src/main/java/RewardsConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public static void main(String[] args) {
return;
}
System.out.println("converting $" + input_value + " to miles");
var rewardsValue = new RewardValue(cashValue);
var rewardsValue = new RewardValue((int) cashValue);
System.out.println("$" + input_value + " is worth " + rewardsValue.getMilesValue() + " miles");
}
}
}

18 changes: 14 additions & 4 deletions src/test/java/RewardValueTests.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;


public class RewardValueTests {

@Test
void create_with_cash_value() {
double cashValue = 100;
double cashValue = 100.0;
var rewardValue = new RewardValue(cashValue);
assertEquals(cashValue, rewardValue.getCashValue());
}
Expand All @@ -20,11 +20,21 @@ void create_with_miles_value() {

@Test
void convert_from_cash_to_miles() {
assert false;
double cashValue = 100.0;
var rewardValue = new RewardValue(cashValue);
// Miles = cashValue / 0.0035
int expectedMiles = (int) (cashValue / 0.0035);
assertEquals(expectedMiles, rewardValue.getMilesValue());
// assert false;
}

@Test
void convert_from_miles_to_cash() {
assert false;
int milesValue = 10000;
var rewardValue = new RewardValue(milesValue);
// Cash = milesValue * 0.0035
double expectedCash = milesValue * 0.0035;
assertEquals(expectedCash, rewardValue.getCashValue(),0.001); // Add tolerance for floating point
// assert false;
}
}