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

You will be creating only a driver class in netbeans/java. As part of writing th

ID: 3600356 • Letter: Y

Question

You will be creating only a driver class in netbeans/java. As part of writing this Rock-Paper-Scissors program, be sure to include a message to the user explaining the program. Also, there is one additional element required in this program. You must validate the data entered by the user to ensure that his/her choice is one of the three allowed options. If bad data is entered, the program must provide feedback about the error and again prompt for and read in the user’s choice. make the program randomly generate rock paper or scissors(1,2, or 3). include clear comments throughout the program that explain what functionality the various lines/small sections of code/methods are as related to the execution of the program.

Sample output

Explanation / Answer

RockPaperScissors.java

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

public class RockPaperScissors {

public static void main(String[] args) {
// Declaring variables
int userChoice, pcChoice, winCnt = 0, loseCnt = 0, tieCnt = 0;

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

// Getting the input entered by the user
System.out.println("Welcome to Rock, Paper, Scissors! ");

/* This while loop continues to execute
* until the user enters a valid number or
*/
while (true) {
System.out.println("Please enter your choice from the following menu ");
System.out.print("Rock - 1, Paper - 2, Scissors - 3 :");
userChoice = sc.nextInt();
if (userChoice != 1 && userChoice != 2 && userChoice != 3) {
System.out.println("Invalid choice!");
continue;
}

//Getting the cmputer choice
pcChoice = ComputerSelection();
if (userChoice == 1 && pcChoice == 1) {
System.out.println("Your Choice is Rock");
System.out.println("My Choice is Rock");
System.out.println("We tie!");
tieCnt++;
} else if (userChoice == 1 && pcChoice == 2) {
System.out.println("Your Choice is Rock");
System.out.println("My Choice is Paper");
System.out.println("You Lose!");
loseCnt++;
} else if (userChoice == 1 && pcChoice == 3) {
System.out.println("Your Choice is Rock");
System.out.println("My Choice is Scissors");
System.out.println("You Win!");
winCnt++;
} else if (userChoice == 2 && pcChoice == 1) {
System.out.println("Your Choice is Paper");
System.out.println("My Choice is Rock");
System.out.println("You Win!!");
winCnt++;
} else if (userChoice == 2 && pcChoice == 2) {
System.out.println("Your Choice is Paper");
System.out.println("My Choice is Paper");
System.out.println("We tie!");
tieCnt++;
} else if (userChoice == 2 && pcChoice == 3) {
System.out.println("Your Choice is Paper");
System.out.println("My Choice is Scissors");
System.out.println("You Lose!");
loseCnt++;
} else if (userChoice == 3 && pcChoice == 1) {
System.out.println("Your Choice is Scissors");
System.out.println("My Choice is Rock");
System.out.println("You Lose!");
loseCnt++;
} else if (userChoice == 3 && pcChoice == 2) {
System.out.println("Your Choice is Scissors");
System.out.println("My Choice is Paper");
System.out.println("You Win!");
winCnt++;
} else if (userChoice == 3 && pcChoice == 3) {
System.out.println("Your Choice is Scissors");
System.out.println("My Choice is Scissors");
System.out.println("We tie!");
tieCnt++;
}
// Getting the character from the user 'Y' or 'y' or 'N' or 'n'
System.out.print("Would you like to play another game (Y/N) ::");
char ch = sc.next(".").charAt(0);
if (ch == 'Y' || ch == 'y')
continue;
else {

break;
}

}

//Displaying the result
System.out.println("After playing, the results are you have " + winCnt + " win(s), " + loseCnt + " loss(es), and " + tieCnt + " tie(s).");

}

// This method will chooses the computer selection randomly
private static int ComputerSelection() {

Random rand = new Random();
int computerInt = 1 + rand.nextInt((3 - 1) + 1);

return computerInt;
}

}

________________

Output:

Welcome to Rock, Paper, Scissors!

Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :1
Your Choice is Rock
My Choice is Rock
We tie!
Would you like to play another game (Y/N) ::y
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :1
Your Choice is Rock
My Choice is Rock
We tie!
Would you like to play another game (Y/N) ::y
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :1
Your Choice is Rock
My Choice is Scissors
You Win!
Would you like to play another game (Y/N) ::y
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :2
Your Choice is Paper
My Choice is Paper
We tie!
Would you like to play another game (Y/N) ::y
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :3
Your Choice is Scissors
My Choice is Paper
You Win!
Would you like to play another game (Y/N) ::y
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :2
Your Choice is Paper
My Choice is Paper
We tie!
Would you like to play another game (Y/N) ::y
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :3
Your Choice is Scissors
My Choice is Paper
You Win!
Would you like to play another game (Y/N) ::y
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :4
Invalid choice!
Please enter your choice from the following menu

Rock - 1, Paper - 2, Scissors - 3 :1
Your Choice is Rock
My Choice is Paper
You Lose!
Would you like to play another game (Y/N) ::n
After playing, the results are you have 3 win(s), 1 loss(es), and 4 tie(s).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote