import java.util.ArrayList;
import java.util.List;
class V2Radiator {
V2Radiator(List<SimUnit> list) {
for (int x = 0; x < 5; x++) {
SimUnit unit = new SimUnit("V2Radiator");
list.add(unit);
// 这里应该使用能源
unit.powerUse();
}
}
}
class V3Radiator extends V2Radiator {
V3Radiator(List<SimUnit> list) {
super(list);
for (int g = 0; g < 10; g++) {
SimUnit unit = new SimUnit("V3Radiator");
list.add(unit);
// 这里应该使用能源
unit.powerUse();
}
}
}
class RetentionBot {
RetentionBot(List<SimUnit> list) {
SimUnit unit = new SimUnit("Retention");
list.add(unit);
// 这里应该使用能源
unit.powerUse();
}
}
class SimUnit {
String botType;
int powerUse;
SimUnit(String type) {
botType = type;
}
int powerUse() {
if ("Retention".equals(botType)) {
powerUse = 2;
return 2;
} else {
powerUse = 4;
return 4;
}
}
}
public class TestLifeSupportSim {
public static void main(String[] args) {
List<SimUnit> list = new ArrayList<SimUnit>();
// 这里不用写了,因为V3继承了V3,在测试V3的时候也会测试V2
// 当测试V3时,首先V2会测试5次,然后V3在测试10次,这样V3和V2的测试比例正好是2:1
// V2Radiator v2 = new V2Radiator(aList);
V3Radiator v3 = new V3Radiator(list);
// retention测试了20次,raditor(V2和V3)测试了15次,所以retention与radiator的比例正好是4:3
for (int z = 0; z < 20; z++) {
RetentionBot ret = new RetentionBot(list);
}
// 能源消耗
int retentionPowerUse = 0;
int radiatorPower = 0;
for (SimUnit unit : list) {
if (unit.botType.equals("Retention")) {
retentionPowerUse += unit.powerUse;
} else {
radiatorPower += unit.powerUse;
}
}
System.out.println("radiatorPower = " + radiatorPower);
System.out.println("retentionPowerUse = " + retentionPowerUse);
// 结果为:整体能源消耗率是3:2(radiator:retention)
// radiatorPower = 60
// retentionPowerUse = 40
}
}