Question
Produce one (1) program that allows to the User to play the Rock, Paper, Scissors Game against the computer via three (3) java class files.
Produce one (1) program that allows to the User to play the Rock, Paper, Scissors Game against the computer via three (3) java class files. 1. When the program starts it must ask the User for his/her Name, give its own name, and welcome the person to the game. 2. It will then present instructions to the user on how to play the game. a. Pressing R will play Rock b. Pressing P will play Paper c. Pressing S will play Scissors d. Pressing 0 will end the game 3. The program will then start the game and ask the user for his/her first pick of R, P, or S (and of course 0). Example: Output: What is your name?: Input: Eric Output: Hi Eric, its very nice to meet you. Output: My name is Bob, your computer opponent. Output: Lets play Rock, Paper, Scissors! Output: (R)ock, (P)aper, or (S)cissors?...0 to end game: 4. Game play continues in a loop until the User presses 0 to end the game. 5. At the end of the game, the program must provide statistics for the winning percentage for each the User and the Computer 6. If the Users winning percentage is greater than or equal to the Computers winning percentage, then the User wins (the User wins if the final percentage is a tie).
1. You program must include three (3) .java class files:
a. Java class file #1 - RockPaperScissors.java
i. This class will include the main method and must include the main loop for running the game
ii. This class will create one User object from the User class you will be creating
iii. The reference identifier for this User object must be the word human
iv. This class will create one Computer object from the Computer class you will be creating
v. The reference identifier for this Computer object must be the word robot
vi. This class will check to see if the User has typed in 0 before starting each round of play and will skip the round of play if 0 has indeed been entered
vii. Before the program ends, this class will display the win percentage for each the User and the Computer in a formatted output to 3 decimal places, and will announce which one is the overall winner of the game.
b. Java class file #2 - User.java
i. This class will be the blueprint of the user
ii. This class must include encapsulated (private) instance variables for storing the following information about the user: 1. The Users Name 2. The Users current or most recently played choice (R,P,S, or 0) 3. A running count of the number of wins for the User during the course of the game 4. A running count of the number of ties for the User during the course of the game 5. A running count of the number of loses for the User during the course of the game 6. A win percentage that is calculated after each result
iii. This class must include the following publically available methods: 1. A method to retrieve the Users Name 2. A method to retrieve the Users current or most recently played choice (R,P,S, or 0) 3. A method to retrieve the current count of User wins 4. A method to retrieve the current count of User ties 5. A method to retrieve the current count of User losses 6. A method called .play() that will ask the User for their choice (R,P,S, or 0) and save it into the current or most recently played choice variable a. This method must continue to ask the User for (R,P,S, or 0) if they do not enter in one of these values. Put another way, this method must ensure that the User data is one of these 4 allowable values b. This method must also echo back, as output, the play from the User as confirmation. 7. A method (or more than one method) to store the result of each play of the game. a. If the User wins then increment the win variable b. If the User ties then increment the tie variable c. If the User loses then increment the loss variable 8. A method that calculates the Users win percentage after each play a. Win percentage = count of wins / total number of games played
c. Computer.java
i. This class will be the blueprint of the computer, however, the computers choices will be random rather than User input from the keyboard.
ii. This class must include encapsulated (private) instance variables for storing the following information about the Computer: 1. A string constant to hold the Computers name 2. The Computers current or most recently played choice (R,P,S, or 0) 3. A running count of the number of wins for the Computer during the course of the game 4. A running count of the number of ties for the Computer during the course of the game 5. A running count of the number of loses for the Computer during the course of the game 6. A win percentage that is calculated after each result
iii. This class must include the following publically available methods: 1. A method to retrieve the Computers Name 2. A method to retrieve the Computers current or most recently played choice (R,P,S, or 0) 3. A method to retrieve the current count of Computer wins 4. A method to retrieve the current count of Computer ties 5. A method to retrieve the current count of Computer losses 6. A method called .play() that will randomly assign an R,P,or S to the current or most recently played variable for the Computer. This method will also output the Computers play to the screen so the User knows what the random selection was. 7. A method (or more than one method) to store the result of each play of the game. a. If the Computer wins then increment the win variable b. If the Computer ties then increment the tie variable c. If the Computer loses then increment the loss variable 8. A method that calculates the Computers win percentage after each play a. Win percentage = count of wins / total number of games played
The following is a high level look at what the flow of control should be for your Rock, Paper, Scissors game:
1. The program starts in the main method
2. Create a new User object called human (the creation involves asking the User for their Name and welcoming them to the game)
3. Create a new Computer objected called robot
4. Output to the screen to say Lets play Rock, Paper, Scissors!
5. While the user still wants to play (while the User has typed in R,P, or S but not 0) a. human.play(); b. robot.play(); c. Conditional logic to see if the User won the round or if the Computer won, or if its a tie d. If the User won, increment the Users win count and increment the Computers loss count e. If the Computer won, increment the Computers win count and increment the Users loss count f. If its a tie, increment the Users tie count and increment the Computers tie count g. Recalculate the win percentage for the User h. Recalculate the win percentage for the Computer
6. When the User eventually types in 0, show the calculated win percentages a. Win percentage of the User b. Win percentage of the Computer
7. Output who has won the overall game
8. End of program
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