From 510f086955c9f4718f1b54dff1953efdcb032308 Mon Sep 17 00:00:00 2001 From: Katrice Williams-Dredden Date: Wed, 14 Feb 2018 08:33:12 -0500 Subject: [PATCH 1/2] almost done just a couple of errors --- pom.xml | 10 +++++++ src/main/java/Rate.java | 59 +++++++++++++++++++++++++++++++++++++ src/test/java/RateTest.java | 24 +++++++++++++++ 3 files changed, 93 insertions(+) create mode 100644 src/main/java/Rate.java create mode 100644 src/test/java/RateTest.java diff --git a/pom.xml b/pom.xml index 682d6db..4812776 100644 --- a/pom.xml +++ b/pom.xml @@ -10,5 +10,15 @@ + + org.junit.jupiter + junit-jupiter-api + RELEASE + + + junit + junit + RELEASE + \ No newline at end of file diff --git a/src/main/java/Rate.java b/src/main/java/Rate.java new file mode 100644 index 0000000..56f6c8d --- /dev/null +++ b/src/main/java/Rate.java @@ -0,0 +1,59 @@ +public class Rate { + //created finals because the rates do not change and no one else needs to change them + private static double final USD = 1.00; + private static double final EUR = 0.94; + private static double final GBP = 0.82; + private static double final INR = 68.32; + private static double final AUD = 1.35; + private static double final CAD = 1.32; + private static double final SGD = 1.43; + private static double final CHF = 1.01; + private static double final MYR = 4.47; + private static double final JPY = 115.84; + private static double final CNY = 6.92; + //created my action that will convert the rates and be used in RateTest + public double rateConverter(double value, String start, String end){ + + return value * getRateOfExchange(end)/getRateOfExchange(start); + + } + //used a switch statement to hold all the values and go through each one. + private double rateOfExchange(String rateConverter){ + + switch (currency){ + case "USD": + return USD; + + case "EUR": + return EUR; + + case "GBP": + return GBP; + + case "INR": + return INR; + + case "AUD": + return AUD; + + case "CAD": + return CAD; + + case "SGD": + return SGD; + + case "CHF": + return CHF; + + case "MYR": + return MYR; + + case "JPY": + return JPY; + + case "CNY": + return CNY; + } + return 0; + } +} diff --git a/src/test/java/RateTest.java b/src/test/java/RateTest.java new file mode 100644 index 0000000..2c14305 --- /dev/null +++ b/src/test/java/RateTest.java @@ -0,0 +1,24 @@ +import org.junit.Assert; +import org.junit.Test; + + +public class RateTest { + + @Test + public void convertDollarToEuro() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 1; + double expectedValue = .94; + String startingCurrency = "USD"; + String endingCurrency = "EUR"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateOfExchange(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } +} From 1d49f596d382dfce015954b46490127a60581774 Mon Sep 17 00:00:00 2001 From: Katrice Williams-Dredden Date: Wed, 14 Feb 2018 13:31:39 -0500 Subject: [PATCH 2/2] done --- pom.xml | 12 +++ src/main/java/Rate.java | 31 +++---- src/test/java/RateTest.java | 130 ++++++++++++++++++++++++++++- target/classes/Rate.class | Bin 0 -> 1518 bytes target/test-classes/RateTest.class | Bin 0 -> 2554 bytes 5 files changed, 157 insertions(+), 16 deletions(-) create mode 100644 target/classes/Rate.class create mode 100644 target/test-classes/RateTest.class diff --git a/pom.xml b/pom.xml index 4812776..cb902f2 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,18 @@ io.zipcoder wu-tang-financial 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + + + + diff --git a/src/main/java/Rate.java b/src/main/java/Rate.java index 56f6c8d..9eafb0f 100644 --- a/src/main/java/Rate.java +++ b/src/main/java/Rate.java @@ -1,16 +1,19 @@ public class Rate { + //created finals because the rates do not change and no one else needs to change them - private static double final USD = 1.00; - private static double final EUR = 0.94; - private static double final GBP = 0.82; - private static double final INR = 68.32; - private static double final AUD = 1.35; - private static double final CAD = 1.32; - private static double final SGD = 1.43; - private static double final CHF = 1.01; - private static double final MYR = 4.47; - private static double final JPY = 115.84; - private static double final CNY = 6.92; + 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 INR = 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 CHF = 1.01; + private static final double MYR = 4.47; + private static final double JPY = 115.84; + private static final double CNY = 6.92; + + //created my action that will convert the rates and be used in RateTest public double rateConverter(double value, String start, String end){ @@ -18,11 +21,11 @@ public double rateConverter(double value, String start, String end){ } //used a switch statement to hold all the values and go through each one. - private double rateOfExchange(String rateConverter){ + private double getRateOfExchange(String rateConverter){ - switch (currency){ + switch (rateConverter){ case "USD": - return USD; + return USD; case "EUR": return EUR; diff --git a/src/test/java/RateTest.java b/src/test/java/RateTest.java index 2c14305..993ff40 100644 --- a/src/test/java/RateTest.java +++ b/src/test/java/RateTest.java @@ -18,7 +18,133 @@ public void convertDollarToEuro() { Rate rate = new Rate(); //THEN - double results = rate.rateOfExchange(initialValue, startingCurrency, endingCurrency); + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); Assert.assertEquals(expectedValue, results, .000000001); - } + } + + @Test + public void convertEuroToDollar() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = .94; + double expectedValue = 1; + String startingCurrency = "EUR"; + String endingCurrency = "USD"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertEuroToGreatBritishPd() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = .94; + double expectedValue = .82; + String startingCurrency = "EUR"; + String endingCurrency = "GBP"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertIndianRToCanadianDollar() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 68.32; + double expectedValue = 1.32; + String startingCurrency = "INR"; + String endingCurrency = "CAD"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertCanadianDollarToSwissFranc() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 1.32; + double expectedValue = 1.01; + String startingCurrency = "CAD"; + String endingCurrency = "CHF"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertSwissFrancToMalayR() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 1.01; + double expectedValue = 4.47; + String startingCurrency = "CHF"; + String endingCurrency = "MYR"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertMalayRToJYen() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 4.47; + double expectedValue = 115.84; + String startingCurrency = "MYR"; + String endingCurrency = "JPY"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } + + @Test + public void convertJYenToChineseYR() { + /*So just like the other test we created, we want the one value to test against another and then we specify which + country those values are from. */ + //GIVEN + double initialValue = 115.84; + double expectedValue = 6.92; + String startingCurrency = "JPY"; + String endingCurrency = "CNY"; + + //WHEN + Rate rate = new Rate(); + + //THEN + double results = rate.rateConverter(initialValue, startingCurrency, endingCurrency); + Assert.assertEquals(expectedValue, results, .000000001); + } } diff --git a/target/classes/Rate.class b/target/classes/Rate.class new file mode 100644 index 0000000000000000000000000000000000000000..02cefbb7f78b5ad3fcd728ee35b62ad813a9d47b GIT binary patch literal 1518 zcmZXSO-x)>6vzLEnR)XVW|-j>tQ0As6*|BJO2JkO%nTm`9XbpjBN&?6&R`#-zrTCYscw#7*0{aN)+p#FbIkUAWQ2xR53$+W5b3Abp0L{O>ux`_4V@ z+gdzauj8VQ0Ueig4C)y2Bdx{% zXxx7^eXmiA|2Dew*)M@nEwOOCa(G9LkG1&W*@p|iztg70AFI&)M_T;P=;62T-|W&7 z4M!`9n`$BYSWC31i0ONN%nCe9*-3#=p^0K)w`>*4%T~T(GXd-7U`TRlk@NKUJm*wK z`D07m;F%axb9UPCuT9aPT~S|W=2z6$3}>udUjp zm#x)2SB!LV&B`xZrJUlUMQ?d4x62&qMXPKNv%(TBtK73oWxFJZMkmwT)}Ga$w+fs6 z*>WjY*c?8&(#86Gd+JcMJYlJ<{&!*{YqSgNf`(1ItbRDRk$huqi1HrPkJ2bF=G3LUI1;Q&d1Lgv+|6cIeReR#fPpsItT4tVkb z?I#e==d^br-nVGKgZMJEe?dZ@(v~2`Pqc4BT7IB?57PD{?XM8CllEswVu$u2B(*`i zZW`YE@ZG^jp4b=o&@?oM-u05+HVwZ+`#w^|G<1jZ8fnusY8|@eC#{%9z@d4ablo)S z92$?P&=J!JIye|nvAw1da`5?x3O;KZ^$s>gYKdXf2s@}n0@S6$})Q72KwX{24odOvVkkIjjK}NGf|J{8Fr7oJMKEY5q4NG$#3WI?7ztS Yk(7`#>N)C$#dAFVcHZg~BWp1IAD}-JNB{r; literal 0 HcmV?d00001 diff --git a/target/test-classes/RateTest.class b/target/test-classes/RateTest.class new file mode 100644 index 0000000000000000000000000000000000000000..33210ba7fabf54218e45e7cf3ed7d6fed0f69bf9 GIT binary patch literal 2554 zcmcJPOK%%h6vxllp7GRm632DYn25AV`mjqHw+*j2P3**W>`a|Bu_s1B1vGJnWTNRz zI*-x>2?-DzpaKc{3D_5P(^f@d!IBRE>+TRph)r1{{?~SFO3cC%mZdxAo_k)u`=9ZT ze?9r0h^9ym&={qJ)bEjlr}_I4k`#%d z3F%?x&EFTP=%-~rt#Bk<)eOy<9iDK}tSWj% zu{5@CIDO8JW^)uMmJ~;oRoj{2=tR{tZmX7)HFaIFWHaYlCPzWmMPmhY7uC2dM?LDD zJ+JqBr<&Oqq(GH&0STSv5y z1qA6jt@>##NF^%cB)_nVb!i3X-po9U%@h`~F0=YxX?25nRdDIg}!%$0_dE3UzgcnGu8M#}oqC-6)md$446&l5F3?CKIG2$2> z*0b0p@Z|91FFYdd0SphF!z$FBbRKrFVaF(r9Y+_C?5QPxi?{%M7yAkk@;eyGDc#pyoY*Fs28RBu!iX*4Pe4Snt;Uy zD3G5uq51$GdI`S?3?kt4A}lX5$7vEQJn~P`C0GJ-2kA0hLGC!trw}L7%c#T9Ucr;2 zSC4`KqtGV-f(J~8AS2{MbAe8y-6#e*QyYIAV^84bj)M5${eM7SYl1vLf2K%+fkY@+ zN9pYpiK*b|?ct8Ipj(hhOLv