I am an extreme coding noob and I've just started. I designed a rock paper scissors game and can't figure out why it won't work. For some reason the user input isn't working in the if statement. Please take a look.
package com.youtube.njillatactics;
import javax.swing.JOptionPane;
public class RPS {
public static void main(String args[]){
//start message
JOptionPane.showMessageDialog(null, "Welcome to Nick's rock paper scissors game!");
//get user input and convert to lower case
String userInput = JOptionPane.showInputDialog("Choose rock, paper, or scissors.").toLowerCase();
//generate random computer input
double computerInput = Math.random();
//match user input to converted computer input
JOptionPane.showMessageDialog(null, match(userInput, convert(computerInput)));
}
//convert random computer input into choice
public static String convert(double x){
if(x < 0.33){
return "rock";
}else if(x < 0.66){
return "paper";
}else
return "scissors";
}
//check to see who wins
public static String match(String x,String y){
if(x == y){
return "Tie!";
}else
if(x == "rock"){
if(y == "paper"){
return "Computer wins!";
}else
return "User wins!";
}
if(x == "paper"){
if(y == "scissors"){
return "Computer wins!";
}else
return "User wins!";
}
if(x == "scissors"){
if(y == "rock"){
return "Computer wins!";
}else
return "User wins!";
}else
return x + ", " + y;
}
}