Skip to content
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 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
</dependency>
</dependencies>
</project>
54 changes: 54 additions & 0 deletions src/main/java/CurrencyConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
public class CurrencyConverter {
//private forces encapsulation
//static only one value shared by entire class
//final cannot be changed
//double type
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;


//method 'convert' to get the value(amount of money to exchange) * ending/starting
public double convert(double value, String starting, String ending) {
//to convert you need to take the value given and
return value * getExchangeRate(ending) / getExchangeRate(starting);
}

//use a switch statement to get and return currencies
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.
205 changes: 205 additions & 0 deletions src/test/java/CurrencyConverterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
import org.junit.Assert;
import org.junit.Test;

public class CurrencyConverterTest {

@Test
public void convertDollartoEuro() {
//Arrange
double initialValue = 1; //starting currency
double expectedValue = .94; //what you want your currency to exchange
String startingCurrency = "USD";
String endingCurrency = "EUR";

//Act - what we are actually doing
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go!!

}
@Test
public void convertEurotoDollar() {
//Arrange
double initialValue = .94; //starting currency
double expectedValue = 1; //what you want your currency to exchange
String startingCurrency = "EUR";
String endingCurrency = "USD";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertEurotoPound() {
//Arrange
double initialValue = .94; //starting currency
double expectedValue = .82; //what you want your currency to exchange
String startingCurrency = "EUR";
String endingCurrency = "GBP";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertPoundtoRupee() {
//Arrange
double initialValue = .82; //starting currency
double expectedValue = 68.32; //what you want your currency to exchange
String startingCurrency = "GBP";
String endingCurrency = "RUPEE";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertRupeetoAUD() {
//Arrange
double initialValue = 68.32; //starting currency
double expectedValue = 1.35; //what you want your currency to exchange
String startingCurrency = "RUPEE";
String endingCurrency = "AUD";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertAUDtoCAD() {
//Arrange
double initialValue = 1.35; //starting currency
double expectedValue = 1.32; //what you want your currency to exchange
String startingCurrency = "AUD";
String endingCurrency = "CAD";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertCADtoSGD() {
//Arrange
double initialValue = 1.32; //starting currency
double expectedValue = 1.43; //what you want your currency to exchange
String startingCurrency = "CAD";
String endingCurrency = "SGD";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertSGDtoFranc() {
//Arrange
double initialValue = 1.43; //starting currency
double expectedValue = 1.01; //what you want your currency to exchange
String startingCurrency = "SGD";
String endingCurrency = "FRANC";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertFranctoRinggit() {
//Arrange
double initialValue = 1.01; //starting currency
double expectedValue = 4.47; //what you want your currency to exchange
String startingCurrency = "FRANC";
String endingCurrency = "RINGGIT";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertRinggittoYen() {
//Arrange
double initialValue = 4.47; //starting currency
double expectedValue = 115.84; //what you want your currency to exchange
String startingCurrency = "RINGGIT";
String endingCurrency = "YEN";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}
@Test
public void convertYentoYuan() {
//Arrange
double initialValue = 115.84; //starting currency
double expectedValue = 6.92; //what you want your currency to exchange
String startingCurrency = "YEN";
String endingCurrency = "YUAN";

//Act
CurrencyConverter currencyConverter = new CurrencyConverter(); //new object to test method
double actual = currencyConverter.convert(initialValue, startingCurrency, endingCurrency);
//call on our method 'convert; with values to test

//Assert
Assert.assertEquals(expectedValue, actual, .000000001);
//delta means how long we want our decimal to go

}

}
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.