Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Scissors beats paper beats scissors Rock Paper beats rock Given a Player A, the following instance methods should be defined: Method Description A.playOpponent (Player player2,
Scissors beats paper beats scissors Rock Paper beats rock Given a Player A, the following instance methods should be defined: Method Description A.playOpponent (Player player2, String plchoice, String p2choice) Player A will play against player2. Both players will store the outcome of the match. Ties are not counted. A.printWinPercentage () Prints player A's win percentage formatted to two decimal places. Ties are not counted. A.printties () Prints the number of tie games for player A. A.getWinPercentage () Return A's win percentage as a double. A.getTies() Return the number of tie games for player A as an integer. Your implementation should meet the following additional criteria: There is a default constructor that sets the attributes to the default values. In this case, the number of wins, losses, and ties should be set to 0. The player's name should also be set to an empty string. Also, there should be a constructor Player (String name) that can be used to create a Player object with the specified name. source file is named player.java compile without any warnings The following program is a trivial example of how your class will be tested. The following program is a trivial example of how your class will be tested. public class Sample public static void main(String[] args) Player pl = new Player("John Doe"); Player p2 = new Player("Jane Doe"); pl.playOpponent (p2, "rock", "paper"); pl.printWinPercentage(); pl.printTies(); System.out.println(p2.getWinPercentage()); System.out.println(p2.getTies()); The output of the above program should look like this: John Doe's win rate: 0.00 John Doe has 0 tie(s) 1.00
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started