Skip to content

Lab Complete #75

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

Open
wants to merge 1 commit into
base: master
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
23 changes: 21 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,26 @@
<artifactId>wu-tang-financial</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>

<dependencies><!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
50 changes: 50 additions & 0 deletions src/main/java/CurrencyConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
public class CurrencyConverter {

private static final double USD = 1.00;
private static final double EUR = 0.94;
private static final double GBP = 0.82;
private static final double RUPEE = 68.32;
private static final double AUD = 1.35;
private static final double CAD = 1.32;
private static final double SGD = 1.43;
private static final double FRANC = 1.01;
private static final double RINGGIT = 4.47;
private static final double YEN = 115.84;
private static final double YUAN = 6.92;


public double convert(double value, String starting, String ending) {

return value * getExchangeRate(ending)/getExchangeRate(starting);
}

private double getExchangeRate(String currency) {
switch (currency) {
case "USD":
return USD;
case "EUR":
return EUR;
case "GBP":
return GBP;
case "RUPEE":
return RUPEE;
case "AUD":
return AUD;
case "CAD":
return CAD;
case "SGD":
return SGD;
case "FRANC":
return FRANC;
case "RINGGIT":
return RINGGIT;
case "YEN":
return YEN;
case "YUAN":
return YUAN;

}

return 0;
}
}
Empty file removed src/main/java/DELETEME
Empty file.
166 changes: 166 additions & 0 deletions src/test/java/CurrencyConverterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import org.junit.Assert;
import org.junit.Test;

public class CurrencyConverterTest {

@Test
public void convert_DollarToEuro() {
// Arrange
double initialValue = 1;
double expectedValue = .94;
String startingCurrency = "USD";
String endingCurrency = "EUR";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_EuroToDollar() {
// Arrange
double initialValue = .94;
double expectedValue = 1;
String startingCurrency = "EUR";
String endingCurrency = "USD";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}
@Test
public void convert_EuroToGBP() {
// Arrange
double initialValue = .94;
double expectedValue = .82;
String startingCurrency = "EUR";
String endingCurrency = "GBP";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_GBPToRUPEE() {
// Arrange
double initialValue = .82;
double expectedValue = 68.32;
String startingCurrency = "GBP";
String endingCurrency = "RUPEE";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_RUPEEToCAD() {
// Arrange
double initialValue = 68.32;
double expectedValue = 1.32;
String startingCurrency = "RUPEE";
String endingCurrency = "CAD";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_CADToSGD() {
// Arrange
double initialValue = 1.32;
double expectedValue = 1.43;
String startingCurrency = "CAD";
String endingCurrency = "SGD";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_SGDToFRANC() {
// Arrange
double initialValue = 1.43;
double expectedValue = 1.01;
String startingCurrency = "SGD";
String endingCurrency = "FRANC";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_FRANCToRINGGIT() {
// Arrange
double initialValue = 1.01;
double expectedValue = 4.47;
String startingCurrency = "FRANC";
String endingCurrency = "RINGGIT";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_RINGGIToYEN() {
// Arrange
double initialValue = 4.47;
double expectedValue = 115.84;
String startingCurrency = "RINGGIT";
String endingCurrency = "YEN";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}

@Test
public void convert_YENToYUAN() {
// Arrange
double initialValue = 115.84;
double expectedValue = 6.92;
String startingCurrency = "YEN";
String endingCurrency = "YUAN";

// Act
CurrencyConverter currencyConverter = new CurrencyConverter();
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);

// Assert
Assert.assertEquals(expectedValue, actual, .000000001);
}


}
Empty file removed src/test/java/DELETEME
Empty file.
Binary file added target/classes/CurrencyConverter.class
Binary file not shown.
Binary file added target/test-classes/CurrencyConverterTest.class
Binary file not shown.