-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNation.java
More file actions
executable file
·101 lines (86 loc) · 3.1 KB
/
Nation.java
File metadata and controls
executable file
·101 lines (86 loc) · 3.1 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
package Project01;
import java.util.Collection;
import java.util.Collections;
import java.util.ArrayList;
import Project01.Tribe;
import Project01.People;
/**
* This class creates named Nation objects with undefined number of life points.
* Defines a Nation is made up of 3 Tribes, each tribe gets 1/3 of Nation's life points.
* Keeps track of population of Nation and Tribes and determines if Nation and Tribes are alive or dead.
*/
public class Nation {
private int nationLifePoints;
public static int nationCount = 0;
private String nationName;
private ArrayList<Tribe> tribes = new ArrayList<>();
private ArrayList<People> population = new ArrayList<>();
private ArrayList<People> livingPopulation = new ArrayList<>();
/**
* Create a nation with name and number of lifepoints.
* This nation has 3 tribes with equal amounts of lifepoints (nation's life points / 3)
*
* @param name name of the Nation
* @param lifePoints number of lifepoints assigned to nation
*/
public Nation(String name, int lifePoints) {
nationCount++;
nationName = name;
nationLifePoints = lifePoints;
for (int i = 1; i <= 3; i++) {
this.tribes.add(new Tribe(nationName, "Tribe" + i, nationLifePoints / 3));
}
population.addAll(getNationPopulation());
livingPopulation.addAll(population);
}
/**
* @return true if this nation has life points remaining
*/
public Boolean isNationAlive() {
return (nationLifePoints > 0);
}
/**
* @return population of this nation
*/
public ArrayList<People> getNationPopulation() {
nationLifePoints = 0;
livingPopulation.clear();
for (int tribe = 0; tribe < this.tribes.size(); tribe++) {
if (tribes.get(tribe).isTribeAlive()) {
//System.out.println(tribes.get(tribe));
livingPopulation.addAll(tribes.get(tribe).getLivingTribeMembers());
//System.out.println(tribes.get(tribe).getLivingTribeMembers());
nationLifePoints += tribes.get(tribe).getTribeLifePoints();
}
}
return livingPopulation;
}
/**
* @return name of this nation
*/
public String getNationName() {
return nationName;
}
/**
* Print whether tribe is still alive(and number of members alive) or is dead
*/
public void printTribesStatus() {
for (int tribe = 0; tribe < 1; tribe++) {
if (tribes.get(tribe).isTribeAlive()) {
System.out.print(tribes.get(tribe).getTribeName() + " is alive and has ");
System.out.println(tribes.get(tribe).getTribeSize() + " members.");
} else {
System.out.println(tribes.get(tribe).getTribeName() + " is dead.");
}
}
}
public String toString() {
String result = "\0";
result = nationName;
for (int i = 0; i < tribes.size(); i++) {
result = result + '\n' + tribes.get(i).toString();
}
result = result + '\n';
return result;
}
}