From a9a88bb440871f3c80070dcf178eeb6fd7533169 Mon Sep 17 00:00:00 2001 From: Karousha Fennimore Date: Wed, 14 Feb 2018 18:28:26 -0500 Subject: [PATCH 1/2] complete --- pom.xml | 5 + src/main/java/CurrencyConverter.java | 51 +++++ src/main/java/DELETEME | 0 src/test/java/CurrencyConverterTest.java | 187 ++++++++++++++++++ src/test/java/DELETEME | 0 target/classes/CurrencyConverter.class | Bin 0 -> 1578 bytes .../test-classes/CurrencyConverterTest.class | Bin 0 -> 3066 bytes 7 files changed, 243 insertions(+) create mode 100644 src/main/java/CurrencyConverter.java delete mode 100644 src/main/java/DELETEME create mode 100644 src/test/java/CurrencyConverterTest.java delete mode 100644 src/test/java/DELETEME create mode 100644 target/classes/CurrencyConverter.class create mode 100644 target/test-classes/CurrencyConverterTest.class 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..779f6b1 --- /dev/null +++ b/src/main/java/CurrencyConverter.java @@ -0,0 +1,51 @@ + 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; + + + //method 'convert' to get the value(amount of money to exchange) * ending/starting + public double convert(double value, String starting, String ending) { + + 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..eb214e0 --- /dev/null +++ b/src/test/java/CurrencyConverterTest.java @@ -0,0 +1,187 @@ +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 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 0000000000000000000000000000000000000000..bed8db89c89d55d076b0cec2db57efbed2186040 GIT binary patch literal 1578 zcmZXSO-vg{6vzMLkM+hFY!*mDC=l{NY*-)(H2vViHpaM4j01K|MUm8u>}q)Khn|ExiA#7O^n^LzVd z_Pu%Y#E22>2H7*cUs#TgZ6RSc^b@gb{3 z|7_iQoVwepM1LP&|LRx&xDuP&^X%M|<8vjt)Aexfj}N<*=o1;b^;n7i72bLD$(4u_ zYu@$5u1H7ti4yCO5vjXAToiB@@>2qWYD}zEHf*C}&l}~c$pe@-2SbvD9Ou;JtbjLH zm`x^0@dCHF6LC4`Q=Glixp+1q;LD}6sZ{zB{R_#gfM=l)r%}dAm6AO{Z#XhfZ(?o9 z6bNQY6*F6XYtghW8H;6lw9H!3D9;;KN%F4KW3QAp1X?nQs%4p#;=4?B)3j{U8s!g* zH4q4gr!uR?rZH4DD$7H8+bUI-NB4UoGTTjAq=3qbEt_%j&-?Z=ZL_lEd<`y}cJiI# z3Qsn3hRv;Q;r$!r(Q0uwNnUB*Hj3A0jCH3DA9#WO{94s2n$sm&?7@BY49Xk=coF9U zm_&kG0+>TCfIN7k&HLg7LeH|kxVUN-?dM#zOJGtf#>PtR&e?#pEbQ&7QRbySS4QoG z(a2@=@THz)`x|fsy*R~Z5GJ`0A@|pDGg+_W7V$rn_rj9$w zXY06|JY2^;6FLPELr@$**2WkO$6{949F^qGT zn_q_qUfSTPzIM+8xUTmNa9-P{%Y|phv^dA~F_@vd$H>)$lb2jY5o2C*73a#s-E3~{ zC*ofccZ&7?8P|kOu_aI{Hv=1TD*Jzg@ z<{#1ihRC;R+P^)xw@Uki=gyly(SB@wmw2D{7hUt*hxaBvb5GpD4P8?l`p852K-YW@ zZFxymT~i$@E2L#zJK)e&A8A3?{0_~kqzk&%;Lv19hK}i4z`@~=j2+OmMh8!XWN??R zH96Q8IzSBSTF^lytXD%05hsMrSl}G>i)O-uTCPt0_jh@Y?@R CU@oHo literal 0 HcmV?d00001 diff --git a/target/test-classes/CurrencyConverterTest.class b/target/test-classes/CurrencyConverterTest.class new file mode 100644 index 0000000000000000000000000000000000000000..90aa583808419c3ac750e09f42899432a7b413a4 GIT binary patch literal 3066 zcmcK5&u`mg7zgmjZR~hyXi}5XW@X*FvMw348EnATu1(S;O>4TWO`2|n0&-JRTxE9W zye?yKKthNg5+F_5VFL*ykT?KE<**HqIB?_-fb(t$B*bMqBEE0tCWVGW4#~lO-zU%W zzR$;goBsUw_dgQRNqWIY5z0#OKSNjUWVb>xP0KXnCDlg~W%=b9X`*YS@y&CHi=Fc1xy3FP-<&1%ae9hH0<~f!ZU{MS(miYgHF0 zFl(54&bhdv+Y8!C84+dHDrx0K%{KVl4SLwiMn#~W*_313x>M&u}l&zU1fx6wg>J&Rby=Jib&TfENOS*}^-E2${aWsT{1 zd@`33$eW+ZWwSF2$XUwdaNL%PN!+^ktk0h{6!kZLZe<Nfg+Lg-V?Dm5``jI ze~HOT1qT#oP^%6ymv98|o~1}SosKTj03F5OEdO+nz#jyzk75?XUBF#Dc8i2<4BF^1 zT%~HzL&F&R?aEZ0qUV34N?e=^i&&|CNJN_ZGdn6I6Z+z zB$!TM)Q-wQ{4705BI*y)Qy598eTbf>Q>Y!p_otC3((O15m`m~0C~}SBuTg?EO1MTj@;{XEMif6N z0Tm2U>1viT49W;7F;I?!asrf-pqxTe0%1fXapsa&pf^w;)lw>1HFDQK~7@~5ZS&9S7CMd6fav7A@KzSXMH$Zu_rIg7= zls-`URWL;5P_vY`L3sz1cR_g%l=ngT0FFQqqkm1E4&jf*~qH%~HMu Date: Thu, 15 Feb 2018 15:36:48 -0500 Subject: [PATCH 2/2] revised --- src/main/java/CurrencyConverter.java | 7 +++++-- src/test/java/CurrencyConverterTest.java | 18 ++++++++++++++++++ target/classes/CurrencyConverter.class | Bin 1578 -> 1578 bytes .../test-classes/CurrencyConverterTest.class | Bin 3066 -> 3289 bytes 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/CurrencyConverter.java b/src/main/java/CurrencyConverter.java index 779f6b1..12d891e 100644 --- a/src/main/java/CurrencyConverter.java +++ b/src/main/java/CurrencyConverter.java @@ -1,5 +1,8 @@ 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; @@ -15,7 +18,7 @@ public class CurrencyConverter { //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); } diff --git a/src/test/java/CurrencyConverterTest.java b/src/test/java/CurrencyConverterTest.java index eb214e0..d94a082 100644 --- a/src/test/java/CurrencyConverterTest.java +++ b/src/test/java/CurrencyConverterTest.java @@ -20,6 +20,24 @@ public void convertDollartoEuro() { 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() { diff --git a/target/classes/CurrencyConverter.class b/target/classes/CurrencyConverter.class index bed8db89c89d55d076b0cec2db57efbed2186040..85a3b6b968ac6d12fd1d963baddee90a4429865b 100644 GIT binary patch delta 68 zcmZ3*vx;ZKQ)Wi7&Ci&RG8#%Vx-iHxx-rNzdNC+6`Y|Xo1~I5IhB2r!MlonI#xZC! YCNbzTrZMOTMh<)Hitl%t^hXsuQNel76(HhkS(_(@O7&^2SX5> z{Wp-gRS!8Bg4ygpXnZ}?AEU{k!w|yeAPAEPWpjuDiEDi0UWVNhdGLD)v0AYTu}uERVy4T+APba{W8h;@WDsXiVo+vKW6)vH zWY7hw_F!NK>0!`g&#N8rO%y&3*&b&r{2lpQSZtegSuqBa!&CKsewQ1KP0uut0 z98(euw!fy?SU7Kdq@Rx^W-!al&*IMci!2JvG0W+;=9$?(_2*1r!PCiW=WBmhz+q;` z|66SeEHbl|X*b+*R^+h6tZ?_R%&fBSXF38a%!>JOyC$&8vBt4}by3jjZH;Tj21*>8 zA(T-e9(dA>`dgr1qak6?y{-~5^db&{1VTun4