From 4518fdf413cf449e1d2ed8ea1979c0714cc55a6a Mon Sep 17 00:00:00 2001 From: mbowe4 Date: Tue, 13 Feb 2018 18:43:41 -0500 Subject: [PATCH 1/3] first commit --- pom.xml | 5 +++ src/main/java/CurrencyConverter.java | 42 +++++++++++++++++++++++++ src/main/java/DELETEME | 0 src/test/java/DELETEME | 0 target/classes/CurrencyConverter.class | Bin 0 -> 1668 bytes 5 files changed, 47 insertions(+) create mode 100644 src/main/java/CurrencyConverter.java delete mode 100644 src/main/java/DELETEME delete mode 100644 src/test/java/DELETEME create mode 100644 target/classes/CurrencyConverter.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..0e9d798 --- /dev/null +++ b/src/main/java/CurrencyConverter.java @@ -0,0 +1,42 @@ +import java.util.HashMap; + +public class CurrencyConverter { + + + + private HashMap converter; + + + public CurrencyConverter () { + converter = new HashMap(); + converter.put("USD", 1.00F); + converter.put("EUR", 0.94F); + converter.put("GBP", 0.82F); + converter.put("INR", 68.32F); + converter.put("AUD", 1.35F); + converter.put("CAD", 1.32F); + converter.put("SGD", 1.43F); + converter.put("CHF", 1.01F); + converter.put("MYR", 4.47F); + converter.put("JPY", 115.84F); + converter.put("CNY", 6.92F); + + } + + + public Float makeConversion (String fromCurrencyCode, String toCurrencyCode, Float amountToConvert) { + return (converter.get(toCurrencyCode) / (converter.get(fromCurrencyCode)))* amountToConvert; + + + } + + + public static void main(String[] args) { + + CurrencyConverter test = new CurrencyConverter(); + System.out.println(test.makeConversion("CAD","CHF",200.00F)); + + + } + +} 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/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..40db545bd130603c023113dcfa0cfa825b50ce63 GIT binary patch literal 1668 zcmZuxOLN;)7(H^-SW#6cQ5;j~8)$Hxw&qR1X`IBV;|Ax^I&o{tOK}xP!InI-9HvVa zFzi_I3+SQ?rUSGj44q+^VaLFl6>Ao(*)p6fsYD%nJac`|_c-@_-*>Nm{rAV80K9~T ziu1_FF{dJi{1DDyUcrKjQz!__qJk@OzWvo73W{?6+TWilSdte$7q}$nzy9ra1y|+# zy?=gDuq@{f)XNIqmh+!1-B(bS=e`hlMPB&pep11zJojh&t{`2DV_lqZEspCdPvo%` zY{-QYAmFBoDsIGaQ^HW)vG+{ZGhGQ|$Zv!ofEv24qml`xQ=tV)mz&TSG7mo3{|?Y6c|cf;6f z(xR80y3wo}t|f42l)W9RBLo(@u4~%$JB7!p$((2zADMxnV>z~jQaYlbS5vPgP&paN z3M>*vwq2)nc&L!9N5VoXYVe#VqlS%^)3v<~CsZn7G?Mq2UTzr{1*g)tBF>Q1?~>s* zMBRPdY@ug%JPB&W>AH2ZXo>En4poF>y(DI;A%iJO=$WsE3B16WY*rRE)bNgmTX>iF z%I0;hOAG5rSNOj@Bu!g zfF5~qP}~;k8ehuGaopBmVw-(G%wOBuHS4T1zGpPM<{F*Jbg|#82HIVQO-F|xBChBjPB$((!&^KJ&7MHs!R53R_$!hn#r`SwEuvfWdvlZ}>>jhoVr`k4B-UAB)0-J{*N3`e+pD`dAbu_3Vf39c$+9K|p+e%Fq%x&(4W%NXIk9mNiGe2g)Ch9thkIPM~a z2RM#P%+%No_5fMD$bU)Pw4gt**&ms<3DJTJ`#AYCPVM8gKvVxC`yx%dRP_xbV-Si4 zea6#1dnRBA*~x`h@T%{hz-!#a1V3KK8$4?W(|9vH`zDU~zLSq|hGRKf{toA+^btL& sKkIkkxqUo;*nPiLq>`#tJVdXQdP~z`0aSXHn0glOqM*si- literal 0 HcmV?d00001 From 31cdcec97b0579bf3743af498e5c9cdf5d0b4125 Mon Sep 17 00:00:00 2001 From: mbowe4 Date: Tue, 13 Feb 2018 19:25:32 -0500 Subject: [PATCH 2/3] second commit --- src/main/java/CurrencyConverter.java | 7 +++-- src/test/java/CurrencyConverterTest.java | 2 ++ src/test/java/CurrencyConverterTestTest.java | 25 ++++++++++++++++++ target/classes/CurrencyConverter.class | Bin 1668 -> 1897 bytes .../test-classes/CurrencyConverterTest.class | Bin 0 -> 288 bytes .../CurrencyConverterTestTest$1.class | Bin 0 -> 1015 bytes .../CurrencyConverterTestTest.class | Bin 0 -> 1265 bytes 7 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/test/java/CurrencyConverterTest.java create mode 100644 src/test/java/CurrencyConverterTestTest.java create mode 100644 target/test-classes/CurrencyConverterTest.class create mode 100644 target/test-classes/CurrencyConverterTestTest$1.class create mode 100644 target/test-classes/CurrencyConverterTestTest.class diff --git a/src/main/java/CurrencyConverter.java b/src/main/java/CurrencyConverter.java index 0e9d798..8bf2144 100644 --- a/src/main/java/CurrencyConverter.java +++ b/src/main/java/CurrencyConverter.java @@ -1,3 +1,4 @@ +import java.text.NumberFormat; import java.util.HashMap; public class CurrencyConverter { @@ -24,8 +25,10 @@ public CurrencyConverter () { } - public Float makeConversion (String fromCurrencyCode, String toCurrencyCode, Float amountToConvert) { - return (converter.get(toCurrencyCode) / (converter.get(fromCurrencyCode)))* amountToConvert; + public String makeConversion (String fromCurrencyCode, String toCurrencyCode, Float amountToConvert) { + NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance(); + String result =currencyFormatter.format(converter.get(toCurrencyCode) / (converter.get(fromCurrencyCode))* amountToConvert); + return result; } diff --git a/src/test/java/CurrencyConverterTest.java b/src/test/java/CurrencyConverterTest.java new file mode 100644 index 0000000..a7df3a3 --- /dev/null +++ b/src/test/java/CurrencyConverterTest.java @@ -0,0 +1,2 @@ +public class CurrencyConverterTest { +} diff --git a/src/test/java/CurrencyConverterTestTest.java b/src/test/java/CurrencyConverterTestTest.java new file mode 100644 index 0000000..3b2b41d --- /dev/null +++ b/src/test/java/CurrencyConverterTestTest.java @@ -0,0 +1,25 @@ +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.util.HashMap; + +import static org.junit.Assert.*; + +public class CurrencyConverterTestTest { + private static CurrencyConverter tester; + + @Before + public void setUp() { + HashMaporiginalRecord = new HashMap(){{put("USD", 1.00F);put("EUR", 0.94F);put("GBP", 0.82F);put("INR", 68.32F); + put("AUD", 1.35F);put("CAD", 1.32F);put("SGD", 1.43F);put("CHF", 1.01F);put("MYR", 4.47F);put("JPY", 115.84F);put("CNY", 6.92F);}}; + tester = new CurrencyConverter(); + } + @Test + public void makeConversion() { + String expected = "$609.76"; + String actual = tester.makeConversion("GBP", "USD", 500.00F); + + Assert.assertEquals(expected, actual); + } +} \ No newline at end of file diff --git a/target/classes/CurrencyConverter.class b/target/classes/CurrencyConverter.class index 40db545bd130603c023113dcfa0cfa825b50ce63..718abb5d68ca09d28d9472fed3038cc053862baa 100644 GIT binary patch delta 926 zcmZuvOH30{6g@M2ZO3u=m5-u)L{JJ8i>RpOQ>3*N1QZYizYKLKV431{3c4a1HEs+s z6J59!6Bh=5q!3Ar32|d|t1H*WxHN8!cc#_2Ad|dz&wcNnd+wQcE9-mq!iV2)-U8SU zT|_m4P8=7(Be(?>2npyEQHHRY=@QV*{Iie02spv~{XcFC=wTgqP29`;&pv(<(8v5w ze{Bdj$^5HgtAJC?f1`6*KtF3=H1PoI__kaiV34(com~=f8be|OQ4c$D#_TgsBsEP@BiBQ5 zZAR90MdPr&XIh?b{i75^_R%uLDqux*~F6$DeaYaH5GejH6 z$O^>OIYlE`PN)*%Ao>G1=)_eC8WKi}Z9ZJIxmphSQAPjD)1@YKS&b+hcDQRcpU-%1 z3za)2EFU-&x`UZ}mcq1U&BjmLm^TyG43otb^#1{leh5uXdo3Xzb+A!P2GP3DxXIox zcq#8gHmzI1ARz}?C?)Kns2REFMjl4tB4_e3j{@95As(OzOW20jC`JQSO2h`N(6ei# zoimLv`6+%#oDSL>*HGeP#jJJ(%#%XtJCvnRPH2JE{ex;f<)-hYu*+vJw!fe<9;Uo( z5)Be%r&r}gxz(~QO`B;+4R8oemW)OmrieG2;s}mXt)0g8(J+jvZD^rWJGP(|ZFE0s zsvMz&Sx~Z$iqTcrR(8GJ0XF5 NI!5g|`Z}z-z#pN!xy%3n delta 702 zcmX|-NlX-B5QV>Pewe0hwh@VmETS;7437H-*f_&7B8Z3}xS$P=;Diih93Y;Ei5d?k z#&kS*mV*a_iexaF7!%{gs7F0{Hpa78Vs%4ICsp<8?|QH5{Vu#yu<&{9?R#J^6DGCT z0oqJ-?0l*?VGuQ`Am(-24LX!P^Yn*7r?UJ1+%@P@(fb~bEBpDEuLdWT{p{~YgKlN7 znym(>lzqEv$)HEIJ@jy|ivC(EH8`!>e$FgM(S=jLRuGh-2A zmqyOuK)b~V7c4Gv$z9W1IxH?Ts!`;ROgX8Eh)-y7g{#68n@y(^sqtH}>C{{zok^qv zI2L1!TVm6`0M{%MTz4Pj%)5Om>MpC%NZ(j8F`j9zAEH{;t`$QyIZyN@*9p?8Cr4^o zRbtq+b3ZLKN&gsy5=|7FD8dpa3J6QDSx`5{vUUlR1es?u_bBBtTUexw*KB3COj^PQ zD@52MS@ZVu_@z#Xo{}7DSV4uelz*TiOQnYzeYD`gRFj0{8}eStuR7jJc|K*OPv5Xk zu|Y3n?B{_09^#->x+lOP4vSbmM>x76K1{CvR{oBvkyW<$EK}VWEDn|icZgP&ompz^ mSN|moWgPLz5SO;e_TFV>>jdIZvmirmZ;=}{`C9$C;-2YsfBbJrFD|pfdvx5o^fUMZ2s?I|t|?Zdsqz GLvjTLnLpM5 literal 0 HcmV?d00001 diff --git a/target/test-classes/CurrencyConverterTestTest$1.class b/target/test-classes/CurrencyConverterTestTest$1.class new file mode 100644 index 0000000000000000000000000000000000000000..8a0c999e29fccd76b23c2a8ed0a82db5125a0708 GIT binary patch literal 1015 zcmaJ=%}*0i5dUpi=(4U9o`^!FqE;nB_JhQu2NN&G zKSB>442cKDc<^Gp7(ILP?7_2F zue%;!IdYpaEW;!JMCw0&qiX`hqP?jLh*bTr>>U_US6VY`{Voo>S*4oo3=~YmUM61-i$(3FpIo`Qy5l| zKwdyctvVM)K|v973g%HFYQA=lWVx_Pa&ejCd~J?oG0$bS9N-1+xwOuA@2sx#-DQ&T zwlyWQ0{RX$E?}^2gn&+0_i7Ewo#OWt3!;M=1rrev-PKHAUwJ5?KUEq%G%*Tn_#O>B z)v~p+v7^_$*6}u(*7zoc5qijRdgVfIFP|Alv=TT?dW6sybRa_dd3x*}g!DclY1W~9 zfcPGr57MlQMMEsH?hwoDNQf17G{ikD7UEvk7h=Yag}9#`5Agsy5#p0Yg5xu5IwgoOCjo==Ox23++~4iHdhvi743Z~&{Z-l`L20fkW#wPpJiLKH1hwo$LTP2Cje4#Bk=klMDJPF1cMULQx= zhH%-cX|Ee9deO&@{xfQ9)(e>z=xGa4(F09D8Jn9~oSx@Nh`w2U&vkeEm4XEoi+HZ$ zE(!{kRJ;IZo@v9l6vION;rOlHtQ@g+YR~>>(BA3ky3X;NPcbLD*_4|H0)5%FT&Q!w za0J$~A!qvx+dV;I80u;W-Pe;`;o)~ES@mv#&u3;hVrsCP)0_3c(`u^<5yc zM}TPQ0EA_z96n8w4|0gN9Q-F8 Date: Wed, 14 Feb 2018 15:17:31 -0500 Subject: [PATCH 3/3] added tests --- src/test/java/CurrencyConverterTest.java | 2 - src/test/java/CurrencyConverterTestTest.java | 118 +++++++++++++++++- .../test-classes/CurrencyConverterTest.class | Bin 288 -> 0 bytes .../CurrencyConverterTestTest$1.class | Bin 1015 -> 1059 bytes .../CurrencyConverterTestTest.class | Bin 1265 -> 2865 bytes 5 files changed, 113 insertions(+), 7 deletions(-) delete mode 100644 src/test/java/CurrencyConverterTest.java delete mode 100644 target/test-classes/CurrencyConverterTest.class diff --git a/src/test/java/CurrencyConverterTest.java b/src/test/java/CurrencyConverterTest.java deleted file mode 100644 index a7df3a3..0000000 --- a/src/test/java/CurrencyConverterTest.java +++ /dev/null @@ -1,2 +0,0 @@ -public class CurrencyConverterTest { -} diff --git a/src/test/java/CurrencyConverterTestTest.java b/src/test/java/CurrencyConverterTestTest.java index 3b2b41d..0ee0b5b 100644 --- a/src/test/java/CurrencyConverterTestTest.java +++ b/src/test/java/CurrencyConverterTestTest.java @@ -10,16 +10,124 @@ public class CurrencyConverterTestTest { private static CurrencyConverter tester; @Before - public void setUp() { - HashMaporiginalRecord = new HashMap(){{put("USD", 1.00F);put("EUR", 0.94F);put("GBP", 0.82F);put("INR", 68.32F); - put("AUD", 1.35F);put("CAD", 1.32F);put("SGD", 1.43F);put("CHF", 1.01F);put("MYR", 4.47F);put("JPY", 115.84F);put("CNY", 6.92F);}}; + public void setUp() { + HashMap originalRecord = new HashMap() {{ + put("USD", 1.00F); + put("EUR", 0.94F); + put("GBP", 0.82F); + put("INR", 68.32F); + put("AUD", 1.35F); + put("CAD", 1.32F); + put("SGD", 1.43F); + put("CHF", 1.01F); + put("MYR", 4.47F); + put("JPY", 115.84F); + put("CNY", 6.92F); + }}; tester = new CurrencyConverter(); } + + + @Test - public void makeConversion() { + public void GBP_to_USD() { String expected = "$609.76"; String actual = tester.makeConversion("GBP", "USD", 500.00F); Assert.assertEquals(expected, actual); } -} \ No newline at end of file + + + // 1. + @Test + public void USD_to_EUR() { + String expected = "$470.00"; + String actual = tester.makeConversion("USD", "EUR", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 2. + @Test + public void EUR_to_USD() { + String expected = "$531.91"; + String actual = tester.makeConversion("EUR", "USD", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 3. + @Test + public void EUR_to_GBP() { + String expected = "$436.17"; + String actual = tester.makeConversion("EUR", "GBP", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 4. + @Test + public void GBP_to_INR() { + String expected = "$41,658.54"; + String actual = tester.makeConversion("GBP", "INR", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 5. + @Test + public void INR_to_CAD() { + String expected = "$9.66"; + String actual = tester.makeConversion("INR", "CAD", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 6. + @Test + public void CAD_to_SGD() { + String expected = "$541.67"; + String actual = tester.makeConversion("CAD", "SGD", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 7. + @Test + public void SGD_to_CHF() { + String expected = "$353.15"; + String actual = tester.makeConversion("SGD", "CHF", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 8. + @Test + public void CHF_to_MYR() { + String expected = "$2,212.87"; + String actual = tester.makeConversion("CHF", "MYR", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 9. + @Test + public void MYR_to_JPY() { + String expected = "$12,957.50"; + String actual = tester.makeConversion("MYR", "JPY", 500.00F); + + Assert.assertEquals(expected, actual); + } + + // 10. + @Test + public void JPY_to_CNY() { + String expected = "$29.87"; + String actual = tester.makeConversion("JPY", "CNY", 500.00F); + + Assert.assertEquals(expected, actual); + } + + +} +// Convert Japanese Yen to Chinese Yuan Renminbi \ No newline at end of file diff --git a/target/test-classes/CurrencyConverterTest.class b/target/test-classes/CurrencyConverterTest.class deleted file mode 100644 index 4718be07a60b00e97b0305775cdbd9c991a5bb26..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 288 zcmZvXPiw+J5XIlb{LvVz6h!dmt$Jwa+0skEQ?Q2?@0+;TmAHX*BlKf=5_;$d=!YuK z29M6bW8RN91M~O)^9$ewqZl0wB0NMG62e!dm3;-2YsfBbJrFD|pfdvx5o^fUMZ2s?I|t|?Zdsqz GLvjTLnLpM5 diff --git a/target/test-classes/CurrencyConverterTestTest$1.class b/target/test-classes/CurrencyConverterTestTest$1.class index 8a0c999e29fccd76b23c2a8ed0a82db5125a0708..8e695accf165c0c37c3c2ed618eafebb198ae96b 100644 GIT binary patch delta 73 zcmey)zL;YJD>LKA$!yH?%*_~h85kJ&7&saD8AKQa7!();8FUzg7%Uis8C-xO0SuxH cF$`i184ThKB@7Y_4GfYDJq%Kl*E4$n0J%2{5&!@I delta 29 lcmZ3?@tu7GD>LKK$!yH?xVadZ7#JA%7%Uk0C*NlF003{{28RFu diff --git a/target/test-classes/CurrencyConverterTestTest.class b/target/test-classes/CurrencyConverterTestTest.class index e5e3837e051cc5ad63fafc42647445e86ba65c6c..e6b1a83c124627bd015a203ff63d2e8faaaf29d4 100644 GIT binary patch literal 2865 zcmbW3ZC4vb6vzLY0NJD|&<&+U+KM){(59OQNFY+F5C{(q4<&%6w&Id5un;!5*blbheDW5=XRLxoDJj49607eXz?t zw1^mPR^B31{7C4onC|weg5I)Y9ay$e+BA!0hZ_y$j*K%ST6L{bbjhe3t{SIwAN)7y z&FML8s@eTP-G?XQkyLU@ zPfpNHrl&ic)>A@X=7)yT8*f&9WNe4;+X#OEPfDCWdso?K6|ucfE6T6JZ})?@P=02|gHg6Ua?p=4 z_JcJCJitR*3L;$Wk&E}>We*s54^M#t-rRe172cxzSM&%iuhi=07wCl_!wBJ))Eum> zt84mk1&^RpJ4#Q%tBu6ii*rQmCc&?Q@e6j5ud&b_(tNpJ(4(oEUkkj$mERCteHeL% ztCzuObOk=9`(19}9&S=Z1U6C=sBglHK};Y?NQl4`d!7sUq=ZkkfcHwcU+ZfRj}Y~U z!coFw9l_Hr;QbQb_kWQm2~QC|MR>X+_@^!4*XnS!edIHQKOuaU@VSoQ(=Fgy{met{ z;fsVX5xzqB(~jVeTfhe-JfvN358ojC8R2=tw>pA<)&f2#;n%er?coK&pA-Iq@RuFI zXIj8-O85+wI{l z;Z?%FBm8wo@YxpdI}(0d`>;Lyd%}Mp{71rn>HzNH1r>h)GJGq=|GbKPq}lxk893HJ delta 476 zcmX|;%}WAN6vfY*85?IBtZ~w`vaGbs@~aQc%7PT7T@X?0#8qG*CA4VSE@<)o5?4Ws zgqE%PSK79S&Kn~J?mh3$y}x_j%pm$@wLX4c-vE?wWMcvu6Kgg!WKFEwFp#kj!bT9e zAo4*JjQTfVqll7vxoKky+a`8Qlm`z@AsdD(KSfPGYdPJ+lpJcwmWPUfTfgh|I^Fht z{ifUR^lm#n2QI<_W~yAQ<|}0Zy>)!bcz)I}vFo6UJqL@}H*w&ghC?~jAGMQ=ycP-B z7cu!{TwR7}7!Wi>7L`uTwTuy-3e18zkbQv|P-uuUj`>9k)6~wW0WrjR5}4tzhKOti z(if^XM5KxqCJA=^nJ7EJzR`?@am-?lvk6ueZ&aD5T3|(OOEL@IWyF3DWZQ}z<_A<9 son}3fV|OV