Question: Question 1: Write a program that lets the user to play the game of Rock, Paper, Scissors against the computer. In the program, 1 means
Question 1: Write a program that lets the user to play the game of Rock, Paper, Scissors against the computer.
In the program, 1 means rock, 2 means paper, 3 means scissors.
The program should work as follows:
1. Write a method named compChoice to generate and return a random integer number in the range of 1 through 3. The method also displays the computer's choice. if the random number is 1, display rock. if the random number is 2, display paper. if the random number is 3, display scissors.
2. Write a method named userChoice to return the user's choice (an integer). The user enters his or her choice of "rock", "paper", "scissors" at the keyboard. The method then use a decision structure to decide the corresponding number (1 means rock, 2 means paper, 3 means scissors) and return that number. Input validation is required.
3. Write a method named checkWinner to check and display the winner. The method accepts two integer arguments (one argument for computer's choice, the other argument for user's choice). A winner is selected according to the following rules:
- rock smashes scissors. Rock wins
- Scissors cuts paper. Scissor wins
- Paper wraps rocks. Paper wins
- If the same, it is a tie
4. In the main method: call the above methods in proper order to play the game. After each round, ask the user if she/he wants to play again. Play the game until the user says no or quit.
Requirements:
1. programs should be well-documented
2. pay attention to the return type and parameters for each method
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
