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

Write a game that plays many rounds of Rock Paper Scissor. The user and computer

ID: 3760217 • Letter: W

Question

Write a game that plays many rounds of Rock Paper Scissor. The user and computer will each choose between three items: rock (defeats scissor, but loses to paper), paper (defeats rock, but loses to scissors), and scissors (defeats paper, but loses to rock). If the player and computer choose the same item, the game is a tie. Extend this program to include different algorithmic strategies for choosing the best item. Should the computer pick randomly? Should the computer always pick a particular item or a repeating pattern of items? Should it count the number of times the opponent chooses various items and base its strategy on this history? Be creative here. Each strategy should be in its own method, and at the start of a round of games the user should be able to choose which strategy to play against. Include at least two strategies.

Explanation / Answer

Program code:

import java.util.Scanner;

import java.util.Random;

public class rock {

public static void main(String[] args) throws java.lang.Exception {

Scanner sc1 = new Scanner(System. in );

Random random = new Random();

int number;

int flag = 1;

System.out.println("choose 1,2, or 3 for:");

System.out.println("ROCK (1), PAPER(2), or SCISSOR (3)");

while (flag != 0) {

int Rock = 1, Paper = 2, Scissor = 3;

number = sc1.nextInt();

int randomNumber = random.nextInt(3 - 1 + 1) + 1;

//System.out.println("computer choose:");

if (randomNumber == Rock) {

if (number == Rock) {

System.out.println("computer choose:"+randomNumber);

System.out.println("user choose:"+Rock);

System.out.println("Rock Vs. Rock: TIE");

} else if (number == Paper) {

System.out.println("computer choose:"+randomNumber);

System.out.println("user choose:"+Paper);

System.out.println("Paper Vs. Rock: YOU WIN");

} else if (number == Scissor) {

System.out.println("computer choose:"+randomNumber);

System.out.println("user choose:"+number);

System.out.println("Scissor Vs. Rock: YOU LOSE");

}

} else if (randomNumber == Paper) {

if (number == Rock) {

System.out.println("computer choose:"+randomNumber);

System.out.println("user choose:"+number);

System.out.println("Rock Vs. Paper: YOU LOSE");

} else if (number == Paper) {

System.out.println("computer choose:"+randomNumber);

System.out.println("user choose:"+number);

System.out.println("Paper Vs. Paper: TIE");

} else if (number == Scissor) {

System.out.println("computer choose:"+randomNumber);

System.out.println("user choose:"+number);

System.out.println("Scissor Vs. Paper: YOU WIN");

}

} else if (randomNumber == Scissor) {

if (number == Rock) {

System.out.println("Rock Vs. Scissor: YOU WIN");

} else if (number == Paper) {

System.out.println("Paper Vs. Scissor: YOU LOSE");

} else if (number == Scissor) {

System.out.println("Scissor Vs. Scissor: TIE");

}

}

System.out.println("Do you want to play ? Y(4)/N(5)");

int Y =4,N=5;

number=sc1.nextInt();

if(number==Y){

flag=1;

System.out.println("Rock, Paper,SCISSOR");

}

else if(number==N)

{System.exit(0);

}

}

}

}

sample output:

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