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

Java (BlueJ) In this lab, you will write a Rock Scissor Paper game. It will be c

ID: 668691 • Letter: J

Question

Java (BlueJ)

In this lab, you will write a Rock Scissor Paper game. It will be computer against human. You need to use Random object/class for computer to decide each move. The human players can decide their moves. This is a best-of-seven game. The one who wins 4 rounds first will be the winner. But this program is a cheater. It allows the player to win up to 3 times. Once the player wins three times, your program will control the game to make the computer finally wins the game.

Sample run:
R for rock, S for scissor, P for paper
Round 1:
Your move: R
Computer's move: S
YOU WON!
Your score: 1
Computer's score: 0
Round 2:
Your move: R
Computer's move: P
YOU LOSE!
Your score: 1
Computer's score: 1
Round 3:
Your move: P
Computer's move: R
YOU WON!
Your score: 2
Computer's score: 1
Round 4:
Your move: R
Computer's move: P
YOU LOSE!
Your score: 2
Computer's score: 2
Round 5:
Your move: S
Computer's move: P
YOU WON!
Your score: 3
Computer's score: 2
Round 6:
Your move: P
Computer's move: S
YOU LOSE!
Your score: 3
Computer's score: 3
Round 7:
Your move: S
Computer's move: R
YOU LOSE!
Your score: 3
Computer's score: 4
!!! GAME OVER !!!
HA HA YOU LOSER!

Explanation / Answer

public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int computer, user;
  
System.out.print("scissor (0), rock (1), paper (2):");
user = s.nextInt();
computer = (int)(Math.random() * 3);
  
if(computer == 0) {
System.out.print("The computer is scissor.");
} else if(computer == 1) {
System.out.print("The computer is rock.");
} else if(computer == 2) {
System.out.print("The computer is paper.");
}
  
if((user == 0 && computer == 2) || (user == 1 && computer == 0) || (user == 2 && computer == 1)) {
if(user == 0) {
System.out.print(" You are scissor. You won.");
} else if(user == 1) {
System.out.print(" You are rock. You won.");
} else if(user == 2) {
System.out.print(" You are paper. You won.");
}
} else if(user == computer) {
if(user == 0) {
System.out.print(" You are scissor too. It is a draw.");
} else if(user == 1) {
System.out.print(" You are rock too. It is a draw.");
} else if(user == 2) {
System.out.print(" You are paper too. It is a draw.");
}
} else {
if(user == 0) {
System.out.print(" You are scissor. You lose.");
} else if(user == 1) {
System.out.print(" You are rock. You lose.");
} else if(user == 2) {
System.out.print(" You are paper. You lose.");
}
}
}

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