You will notice that, in this code, we are associating rock, paper, and scissors with the numbers 1, 2 and 3, respectively. This means that you can use arithmetic to tell who wins. If subtracting the computer's choice from the player's choice yields a result of 2 or -1, then that means the computer won.

import java.util.Scanner;
import java.util.Random;

public class RockPaperScissors {
  
  private static String[] choices = { "Rock", "Paper", "Scissors" };
  
  public static void main (String[] args){
    
    Scanner scan = new Scanner(System.in);
    Random rGen = new Random();
    
    String name;
    int playerChoiceNum;
    String playerChoice;
    
    int computerChoiceNum;
    String computerChoice;
    
    char tryAgain;
    String playerMessage;
    
    System.out.print("What is your name? ");
    name = scan.nextLine();
    System.out.println();
    
    System.out.print("1 = Rock\n2 = Paper\n3 = Scissors\nPlease choose 1, 2, or 3: ");
    playerChoiceNum = scan.nextInt(); scan.nextLine();
    playerChoice = choices[playerChoiceNum - 1];
    System.out.println();
    
    computerChoiceNum = Math.abs(rGen.nextInt()) % 3 + 1;
    computerChoice = choices[computerChoiceNum - 1];
    
    // If the player and computer are tied OR the 
    // computer is beating the player, then...
    //   Ask the user if he is sure about his choice, 
    //      as a yes/no
    //   Store the first character of the user's 
    //      response in the variable tryAgain
    //   If the answer is no, then...
    //      Repeat the lines of code that got the 
    //         user's choice the first time
    
    // YOUR CODE GOES HERE







    
    
    System.out.printf("%s, you chose %s.%n", name, playerChoice);
    System.out.printf("The computer chose %s.%n", computerChoice);
    System.out.println();
    
    // If the player and computer made the same choice, then...
    //    Announce that it's a tie.
    // Otherwise, based upon the player's and computer's 
    //    respective choices, announce what beats what and 
    //    and tell the player whether he wins or loses.

    // YOUR CODE GOES HERE






    
    
    System.out.println(playerMessage);
    
  }
  
}
Your task, then, is to follow the directions in the comments in order to direct the program to carry out the appropriate steps depending on various conditions. Note that because some values are being assigned at random or based on user input, the output will look different each time you run the program. To this end, I have provided multiple examples of how the output could look.

Program output examples:

Example 1:

What is your name? Bob

1 = Rock
2 = Paper
3 = Scissors
Please choose 1, 2, or 3: 1

Bob, are you SURE you want to choose Rock?  (Yes or No)
Yes
Bob, you chose Rock.
The computer chose Rock.

Bob, you and the computer both chose Rock, so it's a tie.
(Bob and the computer chose the same thing, so the program prompted him to confirm his choice. He said "Yes", so the result turned out to be a tie. If Bob changed his choice, he would have either won or lost.)

Example 2:

What is your name? Bob

1 = Rock
2 = Paper
3 = Scissors
Please choose 1, 2, or 3: 1

Bob, you chose Rock.
The computer chose Scissors.

Rock breaks Scissors...you win!
(Bob made the winning choice, so the program never asked him to confirm his choice.)

Example 3:

What is your name? Bob

1 = Rock
2 = Paper
3 = Scissors
Please choose 1, 2, or 3: 3

Bob, are you SURE you want to choose Scissors?  (Yes or No)
No
1 = Rock
2 = Paper
3 = Scissors
Please choose 1, 2, or 3: 2

Bob, you chose Paper.
The computer chose Scissors.

Scissors cut Paper...you lose!
(Bob and the computer chose the same thing (Scissors), so the program prompted him to confirm his choice. He said "No", so he got the chance to change his choice. He chose Paper instead, so he lost; if he had chosen Rock the second time, he would have won. If he had kept his original choice it would have been a tie.)

Questions:
  1. How did the process of creating these programs go for you?
  2. What were your main challenges and how did you overcome them?
  3. What did you learn that may be of use as you move along in this class?