From ea612991d33375a1a73c891c92c19acfc5b613a2 Mon Sep 17 00:00:00 2001 From: Eric Cordell Date: Fri, 16 Feb 2018 18:01:16 -0500 Subject: [PATCH] C.R.E.A.M. Get the money --- pom.xml | 5 ++ src/main/java/WuTangCurrency.java | 31 +++++++ src/test/java/WuTangCurrencyTest.java | 89 +++++++++++++++++++ target/classes/WuTangCurrency.class | Bin 0 -> 1042 bytes target/test-classes/WuTangCurrencyTest.class | Bin 0 -> 2553 bytes 5 files changed, 125 insertions(+) create mode 100644 src/main/java/WuTangCurrency.java create mode 100644 src/test/java/WuTangCurrencyTest.java create mode 100644 target/classes/WuTangCurrency.class create mode 100644 target/test-classes/WuTangCurrencyTest.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/WuTangCurrency.java b/src/main/java/WuTangCurrency.java new file mode 100644 index 0000000..ef8e71a --- /dev/null +++ b/src/main/java/WuTangCurrency.java @@ -0,0 +1,31 @@ +import java.text.DecimalFormat; + +public class WuTangCurrency { + + + protected static final double US_DOLLAR = 1.00; + protected static final double EURO = 0.94; + protected static final double BRITISH = 0.82; + protected static final double INDIAN_RUPEE = 68.32; + protected static final double AUSTRALIAN_DOLLAR = 1.35; + protected static final double CANADIAN_DOLLAR = 1.32; + protected static final double SINGAPORE_DOLLAR = 1.43; + protected static final double SWISS_FRANC = 1.01; + protected static final double MALAYSIAN_RINGGIT = 4.47; + protected static final double JAPANESE_YEN = 115.84; + protected static final double CHINESE_YUAN_RENMINBI = 6.92; + + public static double currencyExchangeFormula(double amountFrom, double rateTo, double rateFrom) { + + double amountTo = amountFrom * (rateFrom / rateTo); + + // tried rounding to 2 decimal places but was unsuccessful + // double amountToRounded = (double)Math.round(amountTo * 100d) / 100d; + + System.out.println(amountTo); + return amountTo; + } + +} + + diff --git a/src/test/java/WuTangCurrencyTest.java b/src/test/java/WuTangCurrencyTest.java new file mode 100644 index 0000000..0760aeb --- /dev/null +++ b/src/test/java/WuTangCurrencyTest.java @@ -0,0 +1,89 @@ +import org.junit.Assert; +import org.junit.Test; + +public class WuTangCurrencyTest { + + WuTangCurrency exchangeRate = new WuTangCurrency(); //created to test currencyExchangeFormula() + + @Test + public void usDollarToEuroTest() { + double amountFrom = 1.00; + double expected = 0.94; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.US_DOLLAR, exchangeRate.EURO); + Assert.assertEquals(expected, actual, 0.01); //delta measures accuracy, within .01 + } + + @Test + public void EuroToUsDollarTest() { + double amountFrom = 0.94; + double expected = 1.00; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.EURO, exchangeRate.US_DOLLAR); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void EuroToBritishPoundTest() { + double amountFrom = 0.94; + double expected = 0.82; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.EURO, exchangeRate.BRITISH); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void BritishPoundToINDIAN_RUPEETest() { + double amountFrom = 0.82; + double expected = 68.32; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.BRITISH, exchangeRate.INDIAN_RUPEE); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void IndianRupeeToCanadianDollarTest(){ + double amountFrom = 68.82; + double expected = 1.32; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.INDIAN_RUPEE, exchangeRate.CANADIAN_DOLLAR); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void CanadianDollarToSingaporeDollarTest(){ + double amountFrom = 1.32; + double expected = 1.43; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.CANADIAN_DOLLAR, exchangeRate.SINGAPORE_DOLLAR); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void SingaporeDollarToSwissFrancTest(){ + double amountFrom = 1.43; + double expected = 1.01; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.SINGAPORE_DOLLAR, exchangeRate.SWISS_FRANC); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void SwissFrancToMalaysianRinggitTest(){ + double amountFrom = 1.01; + double expected = 4.47; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.SWISS_FRANC, exchangeRate.MALAYSIAN_RINGGIT); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void MalaysianRinggitToJapaneseYenTest(){ + double amountFrom = 4.47; + double expected = 115.84; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.MALAYSIAN_RINGGIT, exchangeRate.JAPANESE_YEN); + Assert.assertEquals(expected, actual, 0.01); + } + + @Test + public void JapaneseYenToChineseYuanRenminbiTest(){ + double amountFrom = 115.84; + double expected = 6.92; + double actual = exchangeRate.currencyExchangeFormula(amountFrom, exchangeRate.JAPANESE_YEN, exchangeRate.CHINESE_YUAN_RENMINBI); + Assert.assertEquals(expected, actual, 0.01); + } + + +} \ No newline at end of file diff --git a/target/classes/WuTangCurrency.class b/target/classes/WuTangCurrency.class new file mode 100644 index 0000000000000000000000000000000000000000..c3eed1cf7899fe0a1dd1eb5ac9eca504b73fe17c GIT binary patch literal 1042 zcmZvb&rj1}7{{M?8}DGNz}N^=6eSwmP?^6K0k^Vtqo#DD-9|`AmQoujZY?RT5$>Kn z>(x6(4{AJk@aR9_nJXs73mlEly8$VQJ-mHB&-;D)e4lske*FFV4FGO|7=s>o*ay?_ zCQ+g?L&`6kW(!D@U6M8vvUq50pboxSpI zia>N;m1>fn-MZQxN9ou?)`mo3{={PvpZ*7UU&W`<TR4Y`JXginoTBZ*?5K-A=`j)h~TvZh{JiH z5XEcOixh%BUV#n@eKPM!O;}NhLaZZ9)u?Ks zBau{=XqZ1b<}HKo!@^pI$=VX7>qt>Lys794x~-|IFqokT70seGp&jIpOsMm(8` z?(24Tqj4v=t|^A1AKpdNeMd0m35m_^^5)w1r}f>tm5P%vy{YaiOs$*8oHs;?smywG z{}sFT%&DN*QPcx=EHvJoHGMiNcD_(_y{a*_<#amR6%cn=n?2U8#wd267*5K$x58qJ z9W#~d`~g>;oZ0S(C>`SLuxg?bS38Qjr#NY$9bsxMURA8~OnGmDl`((BK4%d+N9QFv z<6Vx>G@XsmI+cP{j!=cFI9_jx(<5rt$hUFF@}KM-;at(F<=(c6dl#!h>zHkZ^UjpZ zB2-wh;a_=G}lnv7EbFIug_C}Qp22nwIE8|Kg&Mcsxzw9Qfujb${w zjM)&fLv#hR0L>v&#@amoN|b+_2E*;qZW;m(u|I7Lh&W0o&@2hscn_K%vHwf^;9uHP zRJC?(&Y~qK+zW?rf8KlGP0%pCk3E^hUQBiI=G>k01LyFDvFhyH%zy0M)n2?Xcq3k3 z*ge>h{=DxNwh?+SQx80QD%UGK$)ZT@zUT;czJ1; aH_@M02X6