import java.util.*;import javax.swing.*;public class RockTUI{ public static void main(String args[]) { int shouldRun = 1; while (shouldRun == 1){ System.out.println("Play a(nother) game? Enter 1 for Yes; 0 for No."); // Asks Users if they wish to play the Game. Scanner in = new Scanner(System.in); if (in.nextInt() == 0) { shouldRun = 0; System.out.println("Goodbye!"); // Goodbye displayed and program ends, if No is Selected. }else{ // Game Runs if No is not Selected. System.out.println("Enter the target score."); // Asks User to input Target Score to Win the Game. int wins = in.nextInt(); // Inputs the Number of Wins needed. Player Player1 = new Player(); Player Player2 = new Player(); while ((Player1.getWins() != wins) && (Player2.getWins() != wins)){ // Game Continues to play While there is no Winner. int player1Move = Player1.useMove(); int player2Move = Player2.useMove(); String player1Choice = ""; // Displays what Player 1's choice was. String player2Choice = ""; // Displays what Player 2's choice was. String matchWinner = ""; // Displays who won the current Match. // Rock = 0, Paper = 1, Scissors = 2 if ((player1Move == 0) && (player2Move == 0)){ // Tie Game player1Choice = "Rock"; player2Choice = "Rock"; matchWinner = "Tie Game"; } else if ((player1Move == 0) && (player2Move == 1)){ Player2.setWins(); // Player 2 Wins player1Choice = "Rock"; player2Choice = "Paper"; matchWinner = "Player 2"; } else if ((player1Move == 0) && (player2Move == 2)){ Player1.setWins(); // Player 1 Win player1Choice = "Rock"; player2Choice = "Scissors"; matchWinner = "Player 1"; } else if ((player1Move == 1) && (player2Move == 0)){ Player1.setWins(); // Player 1 Wins player1Choice = "Paper"; player2Choice = "Rock"; matchWinner = "Player 1"; } else if ((player1Move == 1) && (player2Move == 1)){ // Tie Game player1Choice = "Paper"; player2Choice = "Paper"; matchWinner = "Tie Game"; } else if ((player1Move == 1) && (player2Move == 2)){ Player2.setWins(); // Player 2 Wins player1Choice = "Paper"; player2Choice = "Scissors"; matchWinner = "Player 2"; } else if ((player1Move == 2) && (player2Move == 0)){ Player2.setWins(); // Player 2 Wins player1Choice = "Scissors"; player2Choice = "Rock"; matchWinner = "Player 2"; } else if ((player1Move == 2) && (player2Move == 1)){ Player1.setWins(); // Player 1 Wins player1Choice = "Scissors"; player2Choice = "Paper"; matchWinner = "Player 1"; } else if ((player1Move == 2) && (player2Move == 2)){ // Tie Game player1Choice = "Scissors"; player2Choice = "Scissors"; matchWinner = "Tie Game"; } JOptionPane.showMessageDialog(null, "Player 1 chose: " + player1Choice + "\nPlayer 2 chose: " + player2Choice + "\nWinner: " + matchWinner + "\n\nPlayer 1's Score: " + Player1.getWins() + "\nPlayer 2's Score: " + Player2.getWins() + "\nPoints needed to Win: " + wins); } // A Prompt of the Game, Displaying what moves the Players made, Who won the Match, the Player's Total Score and how many points are needed to win the Game. if(Player1.getWins() > Player2.getWins()){ // Displays who won the game, when the Game reaches it's Points needed to Win System.out.println("Player 1 has won the Game!"); } else { System.out.println("Player 2 has won the Game!"); } } } } }class Player{ // Constructs a Player class, creating the Players for the Game. private int wins; public Player(){ wins = 0; } public int getWins(){ // Gives the Players win total return wins; } public void setWins(){ // Adds to the Player's win total. wins++; } public int useMove(){ // Gets a Random number between 0 and 2. Random r = new Random(); int play = r.nextInt(3); return play; }}