A
method
addWin()
,
which
takes
no
arguments
and
increments
the
number
of
times
the
player has won.
•
A
toString()
method,
which
takes
no
arguments
and
returns
(as
a
String
)
the
player’s
name, followed by the number of points in parentheses.
For example, if the player’s name
is
Jeff
and the player has 25 points, you’ll return
"Jeff (25 points)"
.
note
that the auto-
grader is vary particular about the formatting of your return String here.
class Player {
private String name;
private int numberTimesWon;
public Player() {
this.numberTimesWon = 0;
}
public Player(String name) {
this.name = name;
this.numberTimesWon = 0;
}
/**
* A method addWin(), which takes no arguments and incrementsthe number of times
* the player has won.
*/
public void addWin() {
this.numberTimesWon++;
}
public String toString() {
return this.name+" ("+this.numberTimesWon+" points)";
}
}
Comments
Leave a comment