Java Reference
In-Depth Information
/**
* Create a TeamImpl object, with the name
* supplied.
*/
public TeamImpl(String teamName) {
name = teamName;
}
/**
* Return a <code>String</code> that is the name of
* this team.
*/
public String getName() {
return name;
}
/**
* Return a list of the players that are on this
* team.
*/
public Set getRoster() {
return new HashSet(players);
}
/**
* Add a player to the team.
*/
public void addPlayer(Player toAdd) {
players.add(toAdd);
}
/**
* Remove a player from the team.
*/
public void removePlayer(Player toRemove) {
players.remove(toRemove);
}
}
Note that this simplifies the implementations of our addPlayer() and removePlayer()
methods. We no longer need to check for duplicates, because this is done for us in the HashSet
implementation.
Search WWH ::




Custom Search