Answer to Question #279449 in Java | JSP | JSF for Hab1bti

Question #279449

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.



1
Expert's answer
2021-12-14T01:15:56-0500
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)";
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment