Question: In Java Write a program that lets the user play the game of Rock Scissors Paper against the computer Use a random generator and generate
In Java
Write a program that lets the user play the game of Rock Scissors Paper against the computer Use a random generator and generate one number from 1,2,3 representing rock , paper , scissors respectively for the computer. Let that be a computers choice method Input from user a value : Use a menu rock (1), paper (2) and scissor (3). Let that be a users choice method 3points Do an input validation on users choice. Let that be a isValid method. Determine if User or computer wins. Let that be a determineWinner method.
Main method: Play this game for ten times. Keep a count of who wins each time and finally display who the winner is after ten runs. So, this method should call users choice, computers choice, determine the winner each time, have the results of each play and maintain a count of each win. Finally call a max overloading methods max(countUser,countComputer, countTied); to determine who the winner is after 5 games. If there is tie between number of user and computer wins, User is the winner. . If there is tie between number of computer wins and number of ties, computer is the winner. A winner is selected on following rules for each play: if one player choose rock and the other scissors, rock wins (Rock smashes the scissors) If one player choose rock and the other paper, paper wins ( Paper wraps the rock) If one player choose paper and the other scissors, scissors wins ( scissors cuts paper) If both players chooses the same it is a tie
Output : Here I am showing for 5 games. Enter 1 for rock, 2 for paper, or 3 for scissors: 1 The computer's choice was rock. The user's choice was rock. The game is tied!
Enter 1 for rock, 2 for paper, or 3 for scissors: 2 The computer's choice was rock. The user's choice was paper. Paper wraps rock. The user wins!
Enter 1 for rock, 2 for paper, or 3 for scissors: 1 The computer's choice was paper. The user's choice was rock. Paper wraps rock. The computer wins!
Enter 1 for rock, 2 for paper, or 3 for scissors: 3 The computer's choice was rock. The user's choice was scissors. Rock smashes scissors. The computer wins!
Enter 1 for rock, 2 for paper, or 3 for scissors: 3 The computer's choice was scissors. The user's choice was scissors. The game is tied! The number of ties is 2 The number of user wins is 2 The number of computer wins is 1 User is the winner
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
