A constructor which takes in a
String
, the player’s name.
If the
String
given is
null
or the
empty string (
""
), set the player’s name to a
unique
non-empty value (in my reference code,
I use ”Player 1”, ”Player 2”, etc).
Otherwise, set the name to the given
String
.
Score and
number of wins should both start at zero.
A constructor which takes no arguments. It sets the name to a
unique
non-empty string. (In
my reference code, I use ”Player 1”, ”Player 2”, etc).
public class Player {
private String name;
private int score;
private int wins;
private static int counter = 1;
public Player(String name) {
if (name == null) {
this.name = "Player " + counter++;
} else {
this.name = name;
}
score = 0;
wins = 0;
}
public Player() {
this(null);
}
}
Comments
Leave a comment