public class Player
extends java.lang.Object
You do not need to modify this class (except to fix one checkstyle error). But you are encouraged to study it since it does some of the things that you need to do to complete ConnectN.
Constructor and Description |
---|
Player(Player other)
Create a copy of an existing player.
|
Player(java.lang.String setName)
Create a new player with the given name.
|
Player(java.lang.String setName,
int setScore)
Create a new player with the given name and score.
|
Modifier and Type | Method and Description |
---|---|
void |
addScore()
Add one to this player's score.
|
boolean |
equals(java.lang.Object obj)
Define equality for the Player class.
|
java.lang.String |
getName()
Get the player's name.
|
int |
getScore()
Get this player's score.
|
int |
hashCode()
Define the hash code for the Player class.
|
void |
setName(java.lang.String setName)
Set the player's name.
|
public Player(java.lang.String setName)
Each player's score begins at zero, and each receives a monotonically increasing unique ID.
setName
- the name for the new playerpublic Player(java.lang.String setName, int setScore)
This is used by the app the reconstitute player instances.
setName
- the name of the playersetScore
- the score of the playerpublic Player(Player other)
This copy constructor creates a copy of an existing player, so that player information can be exposed without allowing the copy to modify the state of the original player.
The id is copied, meaning that the copy will be considered equal to the original.
other
- the otherpublic java.lang.String getName()
public void setName(java.lang.String setName)
setName
- the player's new namepublic int getScore()
public void addScore()
public int hashCode()
This method should only use the id field of the instance. This implements what is known as
entity semantics. Two players with the same name and same score may not be equal if
they were created at different times. Note that Android Studio can auto-generate this and
equals
.
hashCode
in class java.lang.Object
Object.hashCode()
public final boolean equals(java.lang.Object obj)
This method should only use the id field of the instance. This implements what is known as
entity semantics. Two players with the same name and same score may not be equal if
they were created at different times. Note that Android Studio can auto-generate this and
hashCode()
.
equals
in class java.lang.Object
Object.equals(java.lang.Object)