forked from nus-cs2113-AY2324S2/circus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircus.java
40 lines (37 loc) · 1.1 KB
/
Circus.java
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
public class Circus {
private static Animal[] animals = {
new Duck(),
new Parrot()
};
private static Equipment[] equipments = {
new Ladder(50),
new Cannon(5),
new Cannon(100)
};
private static void makeAnimalsTalk() {
for (Animal a : animals) {
System.out.println(a);
System.out.println(a.speak());
}
}
private static int calculateValue(Equipment[] equipments) {
int total = 0;
for (Equipment e : equipments) {
if (e.getValue() <= 5) {
System.out.println("Ignoring low value item: " + e.getValue());
} else {
total += e.getValue();
System.out.println("Adding item value: " + e.getValue());
// some
// more
// code
// here ...
}
}
return total;
}
public static void main(String[] args) {
makeAnimalsTalk();
System.out.println("Total value of equipments " + calculateValue(equipments));
}
}