Browse Source

tests pass

mpierse 5 years ago
parent
commit
31df552d4f

+ 22
- 12
src/main/java/rocks/zipcode/quiz5/collections/Food.java View File

@@ -7,27 +7,37 @@ import java.util.*;
7 7
 /**
8 8
  * @author leon on 27/12/2018.
9 9
  */
10
-public class Food  {
10
+public class Food {
11
+
12
+    public Food(){
13
+
14
+    }
15
+
16
+    ArrayList<Spice> spices= new ArrayList<>();
11 17
 
12
-    Map<Spice, Integer> spiceCount = new LinkedHashMap<>();
13 18
 
14 19
     public List<Spice> getAllSpices() {
15
-        Set<Spice> spicekeys = spiceCount.keySet();
16
-        List<Spice> result = new ArrayList<>();
17
-        result.addAll(spicekeys);
18
-        return result;
20
+        return spices;
19 21
     }
20 22
 
23
+
21 24
     public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
22
-      
25
+      LinkedHashMap<SpiceType, Integer> spiceCount = new LinkedHashMap<>();
26
+        for (Spice s : spices) {
27
+            spiceCount.put((SpiceType) s.getClass(), s.getSpiciness());
28
+        }
29
+        for (Spice s : spices) {
30
+            s.setSpiciness(0);
31
+        }
32
+        return spiceCount;
23 33
     }
24 34
 
35
+
36
+
25 37
     public void applySpice(Spice spice) {
26
-        if(spiceCount.containsKey(spice)) {
27
-            spiceCount.replace(spice, spiceCount.get(spice) + 1);
28
-        } else {
29
-            spiceCount.put(spice, 1);
38
+        if(!spices.contains(spice)){
39
+            spices.add(spice);
30 40
         }
31
-
41
+        spice.setSpiciness(spice.getSpiciness()+1);
32 42
     }
33 43
 }

+ 16
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/Curry.java View File

@@ -1,4 +1,20 @@
1 1
 package rocks.zipcode.quiz5.objectorientation;
2 2
 
3 3
 public class Curry implements Spice {
4
+
5
+    private static Integer spiciness = 0;
6
+
7
+    public Curry() {
8
+
9
+    }
10
+
11
+    @Override
12
+    public void setSpiciness(Integer spiciness) {
13
+        this.spiciness=spiciness;
14
+    }
15
+
16
+    public Integer getSpiciness(){
17
+        return spiciness;
18
+    }
19
+
4 20
 }

+ 15
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/Ginger.java View File

@@ -4,4 +4,19 @@ package rocks.zipcode.quiz5.objectorientation;
4 4
  * @author leon on 27/12/2018.
5 5
  */
6 6
 public class Ginger implements Spice{
7
+
8
+    private static Integer spiciness=0;
9
+
10
+    public Ginger() {
11
+
12
+    }
13
+
14
+    public Integer getSpiciness() {
15
+        return spiciness;
16
+    }
17
+
18
+    @Override
19
+    public void setSpiciness(Integer spiciness) {
20
+        this.spiciness = spiciness;
21
+    }
7 22
 }

+ 15
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/Pepper.java View File

@@ -4,4 +4,19 @@ package rocks.zipcode.quiz5.objectorientation;
4 4
  * @author leon on 27/12/2018.
5 5
  */
6 6
 public class Pepper implements Spice {
7
+
8
+    private static Integer spiciness=0;
9
+
10
+    public Pepper() {
11
+
12
+    }
13
+
14
+    public Integer getSpiciness() {
15
+        return spiciness;
16
+    }
17
+
18
+    @Override
19
+    public void setSpiciness(Integer spiciness) {
20
+        this.spiciness = spiciness;
21
+    }
7 22
 }

+ 5
- 0
src/main/java/rocks/zipcode/quiz5/objectorientation/Spice.java View File

@@ -4,4 +4,9 @@ package rocks.zipcode.quiz5.objectorientation;
4 4
  * @author leon on 27/12/2018.
5 5
  */
6 6
 public interface Spice {
7
+
8
+    void setSpiciness(Integer spiciness);
9
+
10
+    Integer getSpiciness();
11
+
7 12
 }