Write a program to play a game of rock/paper/scissors; the user will play agains
ID: 3640605 • Letter: W
Question
Write a program to play a game of rock/paper/scissors; the user will play against the computer.Requirements:
* All screen input/output will be from gui display and input boxes. (Valid inputs are R, S and P)
* The computer’s set of moves will be stored in a file, so the user only get’s to see their own selection.
* Exceptions handling will be implemented for the file access using try/catch statements.
* The game will start by displaying a nice information box explaining the game, and then it will ask the user for their name. The computers name will be set in the constructor, so you as a programmer can name your “computer”.
* Ask the user how many times you want to play the game, as long as the total number is less than 10. It is possible that the computer data file has less number of moves than the number of times entered by the player:
o Player enters 6 but the computer move file has 5; the game will be played 5 times.
o Player enters 5 but the computer move file as 10 entries, the game will be played 5 times.
o A maximum of 10 rounds can be played in one session.
* The game will determine who wins each round, and then display a final winner after all rounds have been played.
The program will consist of three classes:
* Test Game: Driver program that runs the game
* Player: Store the player information (Name, # of win, ties, loss). Remember the computer player name will be set through the constructor. Give a creative name for your computer.
* RockPaperScissor: Implements logic to instantiates players, set player choice, play game, display the result of the game and the final winner.
Game Rules
Player Computer Results
R R Tie
R P P2 win
R S P1 win
P R P1 win
P P tie
P S P2win
S R P2win
S P P1win
S S Tie
Explanation / Answer
import java.util.Scanner; import java.util.Random; public class Rock { public static void main(String[] args) { Scanner scan= new Scanner (system.in) String personPlay; //User's play -- "R", "P", or "S" String computerPlay; //Computer's play -- "R", "P", or "S" int computerInt; //Randomly generated number used to determine //computer's play System.out.print ("Enter your play: r, p, or s") personPlay = scan.nextLine(); personPlay = personPlay.toUpperCase(); Random generator = new Random(); computerPlay = generator.nextInt (3) +1; System.out.println ("From 1 to 3: " + computerPlay); int computerPlay = computerInt; int 1=R 2=P 3=S; System.outprintln ("computerPlay:" + computerPlay); if (personPlay.equals(computerPlay)); System.out.println ("It's a tie!); else if (personPlay.equals("R")) if (computerPlay.equals("S")) System.out.println ("Rock crushes scissors. You win!"); else if (computerPlay.equals("P")); System.out.println ("Paper beats rock. Computer wins!); else if (personPlay.equals("P") if (computerPlay.equals("R") System.out.println ("Paper beats rock. You win!"); else if (computerPlay.equals("S"); System.out.println ("Scissors cut paper. Computer wins!"); else if (personPlay.equals("S") if (computerPlay.equals("R") System.out.println ("Rock crushes scissors. Computer wins!"); else if (computerPlay.equals("P"); System.out.println ("Scissors cut paper. You win!"); } } U CAN TRY WITH THE FOLLOWING ALSO import tio.*; public class RockPaperScissors { public static void main (String[] args) { int US = 0; int CS= 0; String USRMVE, CMPMVE; int WINR; System.out.println("ROCK - PAPER - SCISSORS"); System.out.println("This game plays 10 rounds."); // Loop once for each round of the game. for (int rnd=1; rndRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.