|
@@ -2,6 +2,8 @@ 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;
|
5
|
7
|
import java.util.List;
|
6
|
8
|
import java.util.Map;
|
7
|
9
|
|
|
@@ -9,14 +11,30 @@ import java.util.Map;
|
9
|
11
|
* @author leon on 27/12/2018.
|
10
|
12
|
*/
|
11
|
13
|
public class Food {
|
|
14
|
+
|
|
15
|
+ List<Spice> spices = new ArrayList<>();
|
|
16
|
+
|
12
|
17
|
public List<Spice> getAllSpices() {
|
13
|
|
- return null;
|
|
18
|
+ return spices;
|
14
|
19
|
}
|
15
|
20
|
|
16
|
21
|
public <SpiceType extends Class<? extends Spice>> Map<SpiceType, Integer> getSpiceCount() {
|
17
|
|
- return null;
|
|
22
|
+ Map<SpiceType, Integer> spiceCount = new HashMap<>();
|
|
23
|
+
|
|
24
|
+ for(Spice spice : spices){
|
|
25
|
+ if(spiceCount.containsKey(spice.getClass())){
|
|
26
|
+ int amount = spiceCount.get(spice.getClass());
|
|
27
|
+ amount = amount + 1;
|
|
28
|
+ spiceCount.put((SpiceType) spice.getClass(), amount);
|
|
29
|
+ } else {
|
|
30
|
+ spiceCount.put((SpiceType) spice.getClass(), 1);
|
|
31
|
+ }
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+ return spiceCount;
|
18
|
35
|
}
|
19
|
36
|
|
20
|
37
|
public void applySpice(Spice spice) {
|
|
38
|
+ spices.add(spice);
|
21
|
39
|
}
|
22
|
40
|
}
|