forked from dencesun/Head-First-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestLifeSupportSim.java
More file actions
executable file
·65 lines (61 loc) · 1.45 KB
/
Copy pathTestLifeSupportSim.java
File metadata and controls
executable file
·65 lines (61 loc) · 1.45 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
package chap09;
import java.util.ArrayList;
public class TestLifeSupportSim
{
public static void main(String[] args)
{
ArrayList aList = new ArrayList();
V2Radiator v2 = new V2Radiator(aList);
V3Radiator v3 = new V3Radiator(aList);
for (int z = 0; z < 20; z++)
{
RetentionBot ret = new RetentionBot(aList);
}
//adding this to make sure the power is correct:
int totalPower = 0;
for(Object o : aList)
{
totalPower += ((SimUnit) o).powerUse();
}
System.out.println("Total power: " + totalPower);
}
}
class V2Radiator {
V2Radiator(ArrayList list) {
System.out.println("making a v2 radiator");
for(int x=0; x<5; x++)
{
list.add(new SimUnit("V2Radiator"));
}
}
}
class V3Radiator extends V2Radiator{
V3Radiator(ArrayList list) {
super(list);
for(int g=0; g<10; g++)
{
list.add(new SimUnit("V3Radiator"));
}
}
}
class RetentionBot {
RetentionBot(ArrayList rlist) {
rlist.add(new SimUnit("Retention"));
}
}
class SimUnit {
String botType;
SimUnit(String type) {
botType = type;
}
int powerUse() {
if ("Retention".equals(botType))
{
return 2;
}
else
{
return 4;
}
}
}