import java.util.Scanner;
import java.util.Random;
public class Game {
public static void main(String[] args) {
System.out.println(" O");
System.out.println("/|\\");
System.out.println("/ \\");
Scanner scanner = new Scanner(System.in);
System.out.println("Bob says: Pick Rock (1), Paper (2), or Scissors (3): ");
String inputString = scanner.nextLine();
int userChoice = 0; // Use int instead of var to explicitly define the variable type
if (inputString.equalsIgnoreCase("Rock") || inputString.equals("1")) {
System.out.println("You picked Rock");
userChoice = 1;
} else if (inputString.equalsIgnoreCase("Paper") || inputString.equals("2")) {
System.out.println("You picked Paper");
userChoice = 2;
} else if (inputString.equalsIgnoreCase("Scissors") || inputString.equals("3")) {
System.out.println("You picked Scissors");
userChoice = 3;
} else {
System.out.println("You didn't pick Rock, Paper, or Scissors");
System.out.println("Game Over");
scanner.close(); // Close the scanner before exiting
return;
}
// Generate Bob's random choice
Random rand = new Random();
int int_random = rand.nextInt(3) + 1; // Generate a random number between 1 and 3
// Check for ties and handle the situation
if (int_random == userChoice) {
System.out.println("You and Bob both picked the same choice");
System.out.println("Bob says: Pick Rock (1), Paper (2), or Scissors (3): ");
inputString = scanner.nextLine();
// Update userChoice based on the new input
if (inputString.equalsIgnoreCase("Rock") || inputString.equals("1")) {
System.out.println("You picked Rock");
userChoice = 1;
} else if (inputString.equalsIgnoreCase("Paper") || inputString.equals("2")) {
System.out.println("You picked Paper");
userChoice = 2;
} else if (inputString.equalsIgnoreCase("Scissors") || inputString.equals("3")) {
System.out.println("You picked Scissors");
userChoice = 3;
} else {
System.out.println("You didn't pick Rock, Paper, or Scissors");
System.out.println("Game Over");
scanner.close(); // Close the scanner before exiting
return;
}
}
if (userChoice == 1 && int_random == 2) {
System.out.println("Bob Picked Paper");
System.out.println("Bob Wins!");
} else if (int_random == 3) {
System.out.println("Bob picked Scissors");
System.out.println("You Win!");
}
if (userChoice == 2 && int_random == 1) {
System.out.println("Bob Picked Rock");
System.out.println("You Win!");
} else if (int_random == 3) {
System.out.println("Bob picked Scissors");
System.out.println("Bob Wins!");
}
if (userChoice == 3 && int_random == 1) {
System.out.println("Bob Picked Rock");
System.out.println("You Win!");
} else if (int_random == 3) {
System.out.println("Bob picked Scissors");
System.out.println("You uui!");
}
// Continue with checking and displaying the winner
// ...
// Close the scanner
scanner.close();
}
}
Game.main(null);
O
/|\
/ \
Bob says: Pick Rock (1), Paper (2), or Scissors (3):
You picked Scissors
Bob Picked Rock
You Win!