Tommy Rogers 6 anni fa
parent
commit
e541ebf1db
3 ha cambiato i file con 145 aggiunte e 11 eliminazioni
  1. 34
    0
      CurrencyConverter.java
  2. 82
    0
      CurrencyConverterTest.java
  3. 29
    11
      package.bluej

+ 34
- 0
CurrencyConverter.java Vedi File

@@ -1,2 +1,36 @@
1
+import java.text.DecimalFormat; 
2
+
1 3
 public class CurrencyConverter {
4
+
5
+    static final Double USDOLLAREXR = 1.00;
6
+    static final Double EUROEXR = 0.94;
7
+    static final Double BRITPOUNDEXR = 0.82;
8
+    static final Double INDIARUPEEEXR = 68.32;
9
+    static final Double AUSTDOLLAREXR = 1.35;
10
+    static final Double CANADADOLLAREXR = 1.32;
11
+    static final Double SINGDOLLAREXR = 1.43;
12
+    static final Double SWISSFRANCEXR = 1.01;
13
+    static final Double MALAYSRINGGITEXR = 4.47;
14
+    static final Double JAPANYENEXR = 115.84;
15
+    static final Double CHINAYUANEXR = 6.92;
16
+
17
+    private Double currentC;
18
+    private Double convertedC;
19
+    private Double currentA;
20
+
21
+    public CurrencyConverter(Double currentC, Double convertedC, Double currentA){
22
+        this.currentC = currentC;
23
+        this.convertedC = convertedC;
24
+        this.currentA = currentA;
25
+
26
+    }
27
+
28
+    public static Double convertCurrency(Double currentA, Double currentC, Double convertedC){
29
+        Double convertedA = (currentA * convertedC) / currentC;
30
+        convertedA = convertedA * 100;
31
+        long temp = Math.round(convertedA);
32
+        return (double) temp / 100;
33
+    }
34
+
2 35
 }
36
+

+ 82
- 0
CurrencyConverterTest.java Vedi File

@@ -1,2 +1,84 @@
1
+import org.junit.Assert;
2
+import org.junit.Before;
3
+import org.junit.Test;
4
+
5
+import java.util.Arrays;
6
+
1 7
 public class CurrencyConverterTest {
8
+    Double USDOLLAREXR = 1.00;
9
+    Double EUROEXR = 0.94;
10
+    Double BRITPOUNDEXR = 0.82;
11
+    Double INDIARUPEEEXR = 68.32;
12
+    Double AUSTDOLLAREXR = 1.35;
13
+    Double CANADADOLLAREXR = 1.32;
14
+    Double SINGDOLLAREXR = 1.43;
15
+    Double SWISSFRANCEXR = 1.01;
16
+    Double MALAYSRINGGITEXR = 4.47;
17
+    Double JAPANYENEXR = 115.84;
18
+    Double CHINAYUANEXR = 6.92;
19
+
20
+    @Test
21
+    public void testDollarToEuro(){
22
+        Double actual = CurrencyConverter.convertCurrency(50_000.00, USDOLLAREXR, EUROEXR);
23
+        Double expected = 47_000.00;
24
+
25
+        Assert.assertEquals(expected, actual);
26
+    }
27
+
28
+    @Test
29
+    public void testEuroToDollar(){
30
+        Double actual = CurrencyConverter.convertCurrency(50000.00, EUROEXR, USDOLLAREXR);
31
+        Double expected = 53_191.49;
32
+
33
+        Assert.assertEquals(expected, actual);
34
+    }
35
+
36
+    @Test
37
+    public void testEuroToBritishPound(){
38
+        Double actual = CurrencyConverter.convertCurrency(50000.00, EUROEXR, BRITPOUNDEXR);
39
+        Double expected = 43_617.02;
40
+
41
+        Assert.assertEquals(expected, actual);
42
+    }
43
+
44
+    @Test
45
+    public void testBritishPoundToIndianRupee(){
46
+        Double actual = CurrencyConverter.convertCurrency(50000.00, BRITPOUNDEXR, INDIARUPEEEXR);
47
+        Double expected = 4_165_853.66;
48
+
49
+        Assert.assertEquals(expected, actual);
50
+    }
51
+
52
+    @Test
53
+    public void testRupeeToCanadianDollar(){
54
+        Double actual = CurrencyConverter.convertCurrency(50000.00, INDIARUPEEEXR, CANADADOLLAREXR);
55
+        Double expected = 966.04;
56
+
57
+        Assert.assertEquals(expected, actual);
58
+    }
59
+
60
+    @Test
61
+    public void testCanadianDollarToSingaporeDollar(){
62
+        Double actual = CurrencyConverter.convertCurrency(50000.00, CANADADOLLAREXR, SINGDOLLAREXR);
63
+        Double expected = 54_166.67;
64
+
65
+        Assert.assertEquals(expected, actual);
66
+    }
67
+
68
+    @Test
69
+    public void testSingaporeDollarToSwissFranc(){
70
+        Double actual = CurrencyConverter.convertCurrency(50000.00, SINGDOLLAREXR, SWISSFRANCEXR);
71
+        Double expected = 35_314.69;
72
+
73
+        Assert.assertEquals(expected, actual);
74
+    }
75
+
76
+    @Test
77
+    public void testSwissFrancToMalaysianRinggit(){
78
+        Double actual = CurrencyConverter.convertCurrency(50000.00, SWISSFRANCEXR, MALAYSRINGGITEXR);
79
+        Double expected = 221_287.13;
80
+
81
+        Assert.assertEquals(expected, actual);
82
+    }
83
+
2 84
 }

+ 29
- 11
package.bluej Vedi File

@@ -1,20 +1,23 @@
1 1
 #BlueJ package file
2
+dependency1.from=CurrencyConverterTest
3
+dependency1.to=CurrencyConverter
4
+dependency1.type=UsesDependency
2 5
 editor.fx.0.height=722
3
-editor.fx.0.width=800
4
-editor.fx.0.x=560
5
-editor.fx.0.y=117
6
-objectbench.height=101
7
-objectbench.width=461
6
+editor.fx.0.width=938
7
+editor.fx.0.x=187
8
+editor.fx.0.y=29
9
+objectbench.height=151
10
+objectbench.width=776
8 11
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
12
+package.divider.vertical=0.7084870848708487
13
+package.editor.height=377
11 14
 package.editor.width=674
12
-package.editor.x=141
13
-package.editor.y=59
15
+package.editor.x=32
16
+package.editor.y=23
14 17
 package.frame.height=600
15 18
 package.frame.width=800
16
-package.numDependencies=0
17
-package.numTargets=0
19
+package.numDependencies=1
20
+package.numTargets=2
18 21
 package.showExtends=true
19 22
 package.showUses=true
20 23
 project.charset=UTF-8
@@ -23,3 +26,18 @@ readme.name=@README
23 26
 readme.width=47
24 27
 readme.x=10
25 28
 readme.y=10
29
+target1.height=50
30
+target1.name=CurrencyConverterTest
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=140
34
+target1.x=40
35
+target1.y=90
36
+target2.association=CurrencyConverterTest
37
+target2.height=50
38
+target2.name=CurrencyConverter
39
+target2.showInterface=false
40
+target2.type=ClassTarget
41
+target2.width=140
42
+target2.x=10
43
+target2.y=120