Bladeren bron

working on calc

Jennifer Chao 5 jaren geleden
bovenliggende
commit
f175c2782f

+ 10
- 8
src/main/java/rocks/zipcode/quiz5/collections/Food.java Bestand weergeven

@@ -2,25 +2,21 @@ package rocks.zipcode.quiz5.collections;
2 2
 
3 3
 import rocks.zipcode.quiz5.objectorientation.Spice;
4 4
 
5
-import java.util.ArrayList;
6
-import java.util.HashMap;
7
-import java.util.List;
8
-import java.util.Map;
5
+import java.util.*;
9 6
 
10 7
 /**
11 8
  * @author leon on 27/12/2018.
12 9
  */
13 10
 public class Food {
14 11
 
15
-    private Map<Class<? extends Spice>, Integer> spices;
12
+    private Map<Spice, Integer> spices;
16 13
 
17 14
     public Food() {
18
-        this.spices = new HashMap<>();
15
+        this.spices = new TreeMap<>();
19 16
     }
20 17
 
21 18
     public List<Spice> getAllSpices() {
22
-        return null;
23
-       // return new ArrayList<>(spices.keySet());
19
+       return new ArrayList<>(spices.keySet());
24 20
     }
25 21
 
26 22
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
@@ -28,5 +24,11 @@ public class Food {
28 24
     }
29 25
 
30 26
     public void applySpice(Spice spice) {
27
+        if (!spices.containsKey(spice)) {
28
+            spices.put(spice, 1);
29
+        } else {
30
+            spices.put(spice, spices.get(spice) + 1);
31
+        }
31 32
     }
33
+
32 34
 }

+ 14
- 7
src/main/java/rocks/zipcode/quiz5/fundamentals/Calculator.java Bestand weergeven

@@ -5,31 +5,38 @@ package rocks.zipcode.quiz5.fundamentals;
5 5
  */
6 6
 public class Calculator {
7 7
     public static Double squareRoot(Double value) {
8
-        return null;
8
+        return Math.sqrt(value);
9 9
     }
10 10
 
11 11
     public static Double square(Double value) {
12
-        return null;
12
+        return value * value;
13 13
     }
14 14
 
15 15
     public static Double[] squareRoots(Double... value) {
16
-        return null;
16
+        for (int i = 0; i < value.length; i++) {
17
+            value[i] = squareRoot(value[i]);
18
+        }
19
+        return value;
17 20
     }
18 21
 
19 22
     public static Double[] squares(Double... values) {
20
-        return null;
23
+        for (int i = 0; i < values.length; i++) {
24
+            values[i] = square(values[i]);
25
+        }
26
+        return values;
21 27
     }
22 28
 
23 29
     public static Double add(Double value1, Double value2) {
24
-        return null;
30
+        return value1 + value2;
31
+        // return (Math.floor(value1 + value2) * 100) / 100;
25 32
     }
26 33
 
27 34
     public static Double subtract(Double value1, Double value2) {
28
-        return null;
35
+        return value1 - value2;
29 36
     }
30 37
 
31 38
 
32 39
     public static Double divide(Double divisor, Double dividend) {
33
-        return null;
40
+        return (divisor / dividend);
34 41
     }
35 42
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java Bestand weergeven

@@ -1,4 +1,4 @@
1 1
 package rocks.zipcode.quiz5.objectorientation;
2 2
 
3
-public class Curry {
3
+public class Curry implements Spice {
4 4
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Ginger.java Bestand weergeven

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Ginger {
6
+public class Ginger implements Spice {
7 7
 }

+ 1
- 1
src/main/java/rocks/zipcode/quiz5/objectorientation/Pepper.java Bestand weergeven

@@ -3,5 +3,5 @@ package rocks.zipcode.quiz5.objectorientation;
3 3
 /**
4 4
  * @author leon on 27/12/2018.
5 5
  */
6
-public class Pepper {
6
+public class Pepper implements Spice {
7 7
 }