forked from mastifikator/FantasyJavaPatterns
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
38 lines (30 loc) · 1.57 KB
/
Copy pathMain.java
File metadata and controls
38 lines (30 loc) · 1.57 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
package Iterator;
import java.util.Iterator;
public class Main {
public static void main(String[] args) {
Helm helm = new Helm(EquipmentMaterial.METALL);
Body body = new Body(EquipmentMaterial.BRIGANDINE);
Pants pants = new Pants(EquipmentMaterial.PLATE);
Gauntlets gauntlets = new Gauntlets(EquipmentMaterial.GLASS);
Boots boots = new Boots(EquipmentMaterial.METALL);
Equipment equipment = new Equipment(helm, body, gauntlets, boots, pants);
int equipmentArmor = 0;
Equipment halfEquipment = new Equipment(body, boots, pants);
int halfEquipmentArmor = 0;
Iterator armorIterator = equipment.iterator();
while(armorIterator.hasNext()){
EquipmentPart part = (EquipmentPart)armorIterator.next();
System.out.println("Броня элемента " + part.getName() + " составляет " + part.getArmor());
equipmentArmor += pants.getArmor();
}
System.out.println("Броня полного набора составляет " + equipmentArmor);
System.out.println();
armorIterator = halfEquipment.iterator();
while(armorIterator.hasNext()){
EquipmentPart part = (EquipmentPart)armorIterator.next();
System.out.println("Броня элемента " + part.getName() + " составляет " + part.getArmor());
halfEquipmentArmor += pants.getArmor();
}
System.out.println("Броня половинного набора составляет " + halfEquipmentArmor);
}
}