-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeam.java
More file actions
63 lines (57 loc) · 1.86 KB
/
Team.java
File metadata and controls
63 lines (57 loc) · 1.86 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
import java.util.ArrayList;
import java.util.Collections;
/**
* @author John Henry Cooper
* @version 15.0.2
* Includes all methods and properties to construct a Team object.
* Includes two property fields, an overloaded constructor, accessor and mutator methods,
* and an overridden toString method
*/
public class Team {
protected String teamColor;
protected ArrayList<Piece> teamPieces ;
/**
* Two parameter constructor for a Team Object
* @param teamColor String
* @param teamPieces ArrayList<Piece>
*/
public Team(String teamColor, ArrayList<Piece> teamPieces){
this.teamColor = teamColor;
this.teamPieces = teamPieces;
}
public String getTeamColor(){
return teamColor;
}
public ArrayList<Piece> getTeamPieces(){
return teamPieces;
}
/**
* Removes a piece from the teamPieces array list
* @param removedPiece Piece piece to be removed from the team
*/
public void removePieceFromTeam(Piece removedPiece){
teamPieces.remove(removedPiece);
}
/**
* Adds a piece to the teamPieces array list
* @param addedPiece Piece piece to be removed
*/
public void addPieceToTeam(Piece addedPiece){
addedPiece.setTeamColor(teamColor);
teamPieces.add(addedPiece);
}
/**
* Overridden toString method that returns "Team (teamColor) Pieces : " followed by the super toString for each Piece object in the teamPieces array on a new line
* @return String
*/
@Override
public String toString(){
int i;
String ret = "Team " + getTeamColor() + " Pieces :\n";
Collections.sort(teamPieces);
for (i=0; i< this.teamPieces.size(); i++){
ret += teamPieces.get(i).toString() +" ";
}
return ret;
}
}