Question: Take the following code and make the output into a GUI. Coding is java. // ************************************************************ // Rock.java // // Play Rock, Paper, Scissors with

Take the following code and make the output into a GUI. Coding is java.

// ************************************************************ // Rock.java // // Play Rock, Paper, Scissors with the user // ************************************************************

import java.util.Scanner; import java.util.Random; public class Rock { public static void main(String[] args) { String personPlay, computerPlay = ""; int computerInt; String response ; Scanner scan = new Scanner(System.in); Random generator = new Random(); System.out.println(" Lets play rock, paper, scissors! "); System.out.println("R = Rock P = Paper S = Scissors"); System.out.println(); do{ System.out.print("Enter your play: "); personPlay = scan.next(); personPlay = personPlay.toUpperCase(); computerInt = generator.nextInt(3); switch (computerInt) { case 0: computerPlay = "R"; break; case 1: computerPlay = "P"; break; case 2: computerPlay = "S"; break; default: System.out.println("Invalid Choice" ); } System.out.println("Computer play is: " + 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 eats rock. You lose!"); else if (personPlay.equals("P")) if (computerPlay.equals("S")) System.out.println("Scissor cuts paper. You lose!"); else if (computerPlay.equals("R")) System.out.println("Paper eats rock. You win!"); else if (personPlay.equals("S")) if (computerPlay.equals("P")) System.out.println("Scissor cuts paper. You win!"); else if (computerPlay.equals("R")) System.out.println("Rock breaks scissors. You lose!"); if (!personPlay.equals("R") && !personPlay.equals("P") && !personPlay.equals("S")) System.out.println("Invalid user input."); System.out.println("Do you want to play again (enter y/n)"); response = scan.next(); } while ( response.equalsIgnoreCase("Y") ); { System.out.println("Thanks"); } scan.close(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!