Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a Java Rock, Paper, and Scissors Game as follows: It has 3 options: 1.Pla

ID: 3768561 • Letter: D

Question

Design a Java Rock, Paper, and Scissors Game as follows:

It has 3 options:

1.Play one game

2.Play five games

3.Play an infinite number of games When the game is finished you need to:

1.Change the winners face from a normal face to asm iley face.

2.Change the loser’s face from normal face to a sad face.

Normal Face:

Happy Face:

Sad Face:

You are welcome to use your images.

When you move your mouse into the smiley face area, it will play a happy sound. Sad sound will be

played when you move your mouse into the sad face area

1 Geme YOU ME Start Play

Explanation / Answer

public class RockPaperScissors { static int cScore, pScore, tie, rounds; enum RPS { R("Rock", "S"), P("Paper", "R"), S("Scissors", "P"); private final String beats, name; RPS(String name, String beats) { this.beats = beats; this.name = name; } int compare(RPS other) { return other == this? 0 : other == valueOf(beats)? 1 : -1; } String fullName() { return name; } } public static void main (String[] args) { final Scanner input = new Scanner(System.in); final Random rgen = new Random(); System.out.println("Hello, for this exercise we're going to be playing everyone's favourite game, Rock-Paper-Scissors!"); while (true) { final RPS playerChoice, compChoice = RPS.values()[rgen.nextInt(3)]; System.out.println("Please make your selection: R - Rock. P - Paper. S - Scissors"); try { playerChoice = RPS.valueOf(input.nextLine().toUpperCase()); } catch (Exception e) { System.out.println( "Sorry, you didn't pick Rock, Paper, or Scissors. The game will end now. " + "Here are the final scores after " + rounds +" rounds: You Computer Ties " + " "+ pScore +" " + cScore + " " + tie); return; } System.out.println(" Computer picked " + compChoice.fullName() + "!"); switch (playerChoice.compare(compChoice)) { case 0: System.out.println("Tie Game! "); tie++; break; case -1: System.out.println(compChoice.fullName() + " beats " + playerChoice.fullName() + "!"); System.out.println("**Computer Wins!** "); cScore++; break; case 1: System.out.println(playerChoice.fullName() + " beats " + compChoice.fullName() + "!"); System.out.println("**Player Wins!** "); pScore++; } rounds++; } } }