-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeam.java
276 lines (251 loc) · 7.04 KB
/
Team.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
import java.util.ArrayList;
/**
* The Team class is used to store attributes of each team.
* And also initialize collection of players,test if players' name are same,display team result.
*
* @author (Pan Qi)
* @version (20/5/2018)
*/
public class Team
{
private String name;//Name of team.
private int ranking;//The ranking of team.
private int cardScore;//The total score of cards of the team.
private ArrayList<Player> playerList;//Collection of players in the team.
private int totalWin;//Total win times of the team in all games.
private int totalLost;//Total lost times of the team in all games.
private int totalDrawn;//Total drawn times of the team in all games.
/**
* Default constructor for objects of class Team
*/
public Team()
{
name = " ";
ranking = 0;
cardScore = 0;
playerList = new ArrayList<Player>();
totalWin = 0;
totalLost = 0;
totalDrawn = 0;
}
/**
* Constructor for objects of class Team
*
* @param String which is the name of team.
* @param Integer which is the rank of the name.
* @param Integer which is the card card score of team.
* @param ArrayList<Player> whih is the collection of players of the team.
* @param Integer which is the total win times of the team in all games.
* @param Integer which is the total lost times of the team in all games.
* @param Integer which is the total drawn times of the team in all games.
*/
public Team(String teamName,int rank,int score,ArrayList<Player> list,int winNumber,int lostNumber,int drawnNumber)
{
name = teamName;
ranking = rank;
cardScore = score;
playerList = list;
totalWin = winNumber;
totalLost = lostNumber;
totalDrawn = drawnNumber;
}
/**
* Display the players' name,team and goals result.
*/
public void displayPlayer()
{
for (int i = 0;i < playerList.size();i++)
{
String playerDetails = String.format("|%-40s|%-8s|",playerList.get(i).getName() + " (" + name + ")"," " + playerList.get(i).getGoals());
System.out.println(playerDetails);
}
}
/**
* Display the team result of all games.
* String.format from google.
*/
public void displayTeam()
{
int totalPlay = totalWin + totalLost + totalDrawn;//How many games a team played totally.
String teamDetails = String.format("|%-16s|%-8s|%-8s|%-8s|%-8s|%-8s|%-8s|%-15s|",
name," " + totalPlay," " + totalWin," " + totalLost," " +
totalDrawn," " + getTeamGoals()," " + getTotalPoints()," " + cardScore);
System.out.println(teamDetails);
}
/**
* Get total card score (fair play score).
*
* @return Integer which is the total card score.
*/
public int getCardScore()
{
return cardScore;
}
/**
* Get name of the team.
*
* @return String which is the name of team.
*/
public String getName()
{
return name;
}
/**
* Get the collection of players.
*
* @return ArrayList<Player> which is the collection of players.
*/
public ArrayList<Player> getPlayerList()
{
return playerList;
}
/**
* Get the ranking of team.
*
* @return Integer which is the ranking of team.
*/
public int getRanking()
{
return ranking;
}
/**
* Get total goals of the team.
*
* @return Integer which is the total goals of the team.
*/
public int getTeamGoals()
{
int teamGoals = 0;//Total goals of team.
for (int i = 0;i < playerList.size();i++)
teamGoals = teamGoals + playerList.get(i).getGoals();
return teamGoals;
}
/**
* Get the total drawn number.
*
* @return Integer which is the total drawn number of team.
*/
public int getTotalDrawn()
{
return totalDrawn;
}
/**
* Get the total lost number.
*
* @return Integer which is the total lost number of team.
*/
public int getTotalLost()
{
return totalLost;
}
/**
* Get the total points.
*
* @return Integer which is the total points of team.
*/
public int getTotalPoints()
{
return totalWin * 3 + totalDrawn;
}
/**
* Get the total win number.
*
* @return Integer which is the total win number of team.
*/
public int getTotalWin()
{
return totalWin;
}
/**
* Test if the player's name is same as the previous players' names.
*
* @param Integer which is the number of player.
* @param String which is the name of player.
* @return Boolean true when name same as previous player,false when name not same as previous players' names.
*/
public boolean ifPlayerNameSame(int playerNumber,String playerName)
{
if (playerNumber > 1)
{
for (int i = playerNumber - 2;i >= 0;i--)
if (playerList.get(i).getName().toUpperCase().equals(playerName.toUpperCase()))
{
System.out.println("Name same with other players!");
return true;
}
}
return false;
}
/**
* Initialize the collection of players.
*/
public void initializePlayerList()
{
int playerNumber = 2;//Number of players that each team have.
while (playerList.size() < playerNumber)
playerList.add(new Player());
}
/**
* Set total card score of team.
*
* @param Integer which is the total card score of team.
*/
public void setCardScore(int score)
{
cardScore = score;
}
/**
* Set name of team
*
* @param String which is the name of the team.
*/
public void setName(String teamName)
{
name = teamName;
}
/**
* Set the collection of players
*
* @param ArrayList<Player> which is the collecton of players.
*/
public void setPlayerList(ArrayList<Player> list)
{
playerList = list;
}
/**
* Set the team ranking.
*
* @param Integer which is the ranking of the team.
*/
public void setRanking(int rank)
{
ranking = rank;
}
/**
* Set the total number of drawn of team.
*
* @param Integer which is the total drawn number of team.
*/
public void setTotalDrawn(int drawnNumber)
{
totalDrawn = drawnNumber;
}
/**
* Set the total number of lost of team.
*
* @param Integer which is the total lost number of team.
*/
public void setTotalLost(int lostNumber)
{
totalLost = lostNumber;
}
/**
* Set the total number of win of team.
*
* @param Integer which is the total win number of team.
*/
public void setTotalWin(int winNumber)
{
totalWin = winNumber;
}
}