Trying to create a rock paper scissor game but after getting the users choice then randomly generating the computers choice and displaying it in the program. The program doesn't go onto the next set of code which determines the winner.
Scanner in = new Scanner(System.in);
int ComputerChoice = (int)(3 * Math.random()) + 1;
System.out.println("Please select one of the following [R/P/S]: ");
String UserChoice = in.nextLine();
if (UserChoice.equalsIgnoreCase("R") ) {
System.out.println("You chose: Rock"); }
else if (UserChoice.equalsIgnoreCase("P") ) {
System.out.println("You chose: Paper"); }
else if (UserChoice.equalsIgnoreCase("S") ) {
System.out.println("You chose: Scissors"); }
else if (UserChoice != "R" || UserChoice != "S" || UserChoice != "P") {
UserChoice = "R";
System.out.println("Invalid choice! Defaulting to Rock.");
}
if (ComputerChoice == 1) {
System.out.println("I chose: Rock");
}
else if (ComputerChoice == 2) {
System.out.println("I chose: Paper");
}
else if (ComputerChoice == 3) {
System.out.println("I chose: Scissors");
}
if (UserChoice == "R" && ComputerChoice == 1) {
System.out.println("A Tie!");
}
else if (UserChoice == "R" && ComputerChoice == 2) {
System.out.println("Paper beats rock - you lose!");
}
else if (UserChoice == "R" && ComputerChoice == 3) {
System.out.println("Rock beats scissors - you win!");
}
else if (UserChoice == "P" && ComputerChoice == 2) {
System.out.println("A Tie!");
}
else if (UserChoice == "P" && ComputerChoice == 1) {
System.out.println("Paper beats rock - you win!");
}
else if (UserChoice == "P" && ComputerChoice == 3) {
System.out.println("Scissors beats paper - you lose!");
}
else if (UserChoice == "S" && ComputerChoice == 1) {
System.out.println("Rock beats scissors - you lose!");
}
else if (UserChoice == "S" && ComputerChoice == 3) {
System.out.println("A Tie!");
}
else if (UserChoice == "s" && ComputerChoice == 2) {
System.out.println("Scissors beats paper - you win!");