-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimalData.java
More file actions
197 lines (167 loc) · 6.61 KB
/
AnimalData.java
File metadata and controls
197 lines (167 loc) · 6.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import java.util.HashSet;
import java.util.HashMap;
/**
* Stores the data for all the animals.
*
* @author Saathveekan Satheshkumar, Manik Aggarwal, David J. Barnes and Michael Kölling
* @version 2022.03.02 (2)
*/
public class AnimalData {
// Creates the hashmaps to store all the data for each animal.
private HashSet<String> listOfAnimal = new HashSet<>();
private HashMap<String, Integer> breedingAge = new HashMap<>();
private HashMap<String, Integer> maxAge = new HashMap<>();
private HashMap<String, Double> breedingProbability = new HashMap<>();
private HashMap<String, Integer> maxLitterSize = new HashMap<>();
private HashMap<String, Integer> foodValue = new HashMap<>();
private HashMap<String, Boolean> oppoGenderRequired = new HashMap<>();
private HashMap<String, Boolean> isNocturnal = new HashMap<>();
private HashMap<String, HashSet<String>> prey = new HashMap<>();
/**
* Fills data into each of the corresponding hashmaps.
*/
public AnimalData() {
// Fills in data for all the animals
HashSet<String> werewolfPrey = new HashSet<>();
werewolfPrey.add("Jackalope");
werewolfPrey.add("Unicorn");
HashSet<String> griffonPrey = new HashSet<>();
griffonPrey.add("Jackalope");
griffonPrey.add("Pegasus");
HashSet<String> cyclopsPrey = new HashSet<>();
cyclopsPrey.add("Werewolf");
cyclopsPrey.add("Griffon");
HashSet<String> jackalopePrey = new HashSet<>();
jackalopePrey.add("Hyacinth");
jackalopePrey.add("Mandrake");
HashSet<String> unicornPrey = new HashSet<>();
unicornPrey.add("Hyacinth");
unicornPrey.add("Mandrake");
HashSet<String> pegasusPrey = new HashSet<>();
pegasusPrey.add("Hyacinth");
pegasusPrey.add("Mandrake");
fillAnimalData("Jackalope", 7, 100, 0., 5, 4, jackalopePrey, true, false);
fillAnimalData("Unicorn", 7, 100, 0.1, 3, 12, unicornPrey, false, false);
fillAnimalData("Pegasus", 7, 100, 0.1, 3, 12, pegasusPrey, true, false);
fillAnimalData("Werewolf", 9, 70, 0.03, 2, 20, werewolfPrey, false, true);
fillAnimalData("Griffon", 9, 80, 0.06, 2, 20, griffonPrey, false, true);
fillAnimalData("Cyclops", 10, 80, 0.06, 3, 50, cyclopsPrey, false, false);
fillAnimalData("Mandrake", 0, 60, 0.01, 4, 3, null, false, false);
fillAnimalData("Hyacinth", 0, 60, 0.01, 4, 3, null, false, false);
}
/**
* Places each value into the hashmap.
* @param animalName The name of the animal
* @param breedingAge The age at which an animal can start to breed.
* @param maxAge The age to which an animal can live.
* @param breedingProbability The likelihood of an animal breeding.
* @param maxLitterSize The maximum number of births.
* @param foodValue The food value.
* @param prey A list of all the prey that the animal can eat.
* @param oppGenderRequired If the animal requires the opposite gender to reproduce.
* @param isNocturnal If whether the animal is nocturnal or not
*/
public void fillAnimalData(String animalName, int breedingAge, int maxAge, double breedingProbability, int maxLitterSize, int foodValue, HashSet<String> prey, boolean oppGenderRequired, boolean isNocturnal) {
this.listOfAnimal.add(animalName);
this.breedingAge.put(animalName, breedingAge);
this.maxAge.put(animalName, maxAge);
this.breedingProbability.put(animalName, breedingProbability);
this.maxLitterSize.put(animalName, maxLitterSize);
this.foodValue.put(animalName, foodValue);
this.prey.put(animalName, prey);
this.oppoGenderRequired.put(animalName, oppGenderRequired);
this.isNocturnal.put(animalName, isNocturnal);
}
/**
* Return age at which an animal can start to breed.
* @param nameOfAnimal name of the animal
* @return Returns the breeding age,
*/
public int getBreedingAge(String nameOfAnimal) {
return breedingAge.get(nameOfAnimal);
}
/**
* Gets the maximum age to which an animal can live.
* @param nameOfAnimal name of the animal.
* @return max age.
*/
public int getMaxAge(String nameOfAnimal) {
return maxAge.get(nameOfAnimal);
}
/**
* Gets the likelihood of an animal breeding.
* @param nameOfAnimal name of animal.
* @return breeding probability.
*/
public double getBreedingProbability(String nameOfAnimal) {
return breedingProbability.get(nameOfAnimal);
}
/**
* Gets the maximum number of births.
* @param nameOfAnimal name of animal
* @return max litter size
*/
public int getMaxLitterSize(String nameOfAnimal) {
return maxLitterSize.get(nameOfAnimal);
}
/**
* Gets the food value.
* @param nameOfAnimal name of animal
* @return food value
*/
public int getFoodValue(String nameOfAnimal) {
return foodValue.get(nameOfAnimal);
}
/**
* Gets the list of prey that the animal can eat.
* @param nameOfAnimal name of animal.
* @return list of prey.
*/
public HashSet<String> getPrey(String nameOfAnimal) {
return prey.get(nameOfAnimal);
}
/**
* Gets the number of prey that the animal can eat.
* @param nameOfAnimal name of animal.
* @return the number of prey.
*/
public int getNumberOfPrey(String nameOfAnimal) {
return getPrey(nameOfAnimal).size();
}
/**
* Calculates the total food value for the list of prey.
* @param nameOfAnimal name of animal.
* @return total prey food value.
*/
public int getPreyValueTotal(String nameOfAnimal) {
int x = 0;
for (String prey : getPrey(nameOfAnimal)) {
x = x + getFoodValue(prey);
}
return x;
}
/**
* Calculates the average food value for the list of prey.
* @param a name of animal.
* @return average prey food value.
*/
public int getAverageOfPreyValue(String a) {
return getPreyValueTotal(a) / getNumberOfPrey(a);
}
/**
* Gets whether the opposite gender is required.
* @param animalName name of animal
* @return true if opposite gender is required.
*/
public Boolean getOppoGenderRequired(String animalName) {
return oppoGenderRequired.get(animalName);
}
/**
* Gets whether the animal is nocturnal or not.
* @param nameOfAnimal name of animal.
* @return whether it is nocturnal or not.
*/
public boolean getIsNocturnal(String nameOfAnimal) {
return isNocturnal.get(nameOfAnimal);
}
}