-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeam.java
93 lines (82 loc) · 1.59 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
import java.util.ArrayList;
/**
*
* @author Alyza Diaz Rodriguez
*
*/
public class Team {
private String teamName;
private ArrayList<Player> roster;
/**
* Initializes a new team
* @param n
*/
public Team(String n) {
teamName = n;
roster = new ArrayList<>();
}
/**
* Returns the team's name
* @return team name
*/
public String getTeamName() {
return teamName;
}
/**
* Returns all of the players on a team in an ArrayList
* @return team roster
*/
public ArrayList<Player> getRoster(){
return roster;
}
/**
* Adds a player to the team
* @param p
*/
public void addPlayer(Player p) {
roster.add(p);
}
/**
* Removes a player from a team
* @param p
*/
public void removePlayer(Player p) {
int index = playerIndex(p);
roster.remove(index);
}
/**
* Finds a player within the team by looking for their name
* @param name
* @return the player
*/
public Player findPlayer(String name) {
for(int i=0;i<roster.size();i++) {
if(roster.get(i).getName().equals(name)) {
return roster.get(i);
}
}
return null;
}
/**
* Finds a player's index
* @param p
* @return index
*/
public int playerIndex(Player p) {
String name = p.getName();
for(int i=0;i<roster.size();i++) {
if(roster.get(i).getName().equals(name)) {
return i;
}
}
return -1;
}
/**
* Prints all the information of all players on a team
*/
public void printRoster() {
for(int i=0;i<roster.size();i++) {
roster.get(i).print();
}
}
}