diff --git a/pom.xml b/pom.xml index 682d6db..956fa2e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,5 +10,10 @@ + + junit + junit + RELEASE + \ No newline at end of file diff --git a/src/main/java/CurrencyConverter.java b/src/main/java/CurrencyConverter.java new file mode 100644 index 0000000..12d891e --- /dev/null +++ b/src/main/java/CurrencyConverter.java @@ -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; + } + } diff --git a/src/main/java/DELETEME b/src/main/java/DELETEME deleted file mode 100644 index e69de29..0000000 diff --git a/src/test/java/CurrencyConverterTest.java b/src/test/java/CurrencyConverterTest.java new file mode 100644 index 0000000..d94a082 --- /dev/null +++ b/src/test/java/CurrencyConverterTest.java @@ -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 + + } + +} \ No newline at end of file diff --git a/src/test/java/DELETEME b/src/test/java/DELETEME deleted file mode 100644 index e69de29..0000000 diff --git a/target/classes/CurrencyConverter.class b/target/classes/CurrencyConverter.class new file mode 100644 index 0000000..85a3b6b Binary files /dev/null and b/target/classes/CurrencyConverter.class differ diff --git a/target/test-classes/CurrencyConverterTest.class b/target/test-classes/CurrencyConverterTest.class new file mode 100644 index 0000000..561d984 Binary files /dev/null and b/target/test-classes/CurrencyConverterTest.class differ