I just started programming with java and I have started to make a text-based game, Here is the code:
The problem is every time I run it and type either ‘left’ or ‘right’ it prints out “Unknown Command”
import javax.swing.JOptionPane;
public class netProject1 {
public static void main(String[] args) {
String userInput = JOptionPane.showInputDialog("What's your name?");
System.out.println("Hello " + userInput + "!");
System.out.println("");
System.out.println("Let's Play!");
String userInput1 = JOptionPane.showInputDialog("Do you go left or right?");
String room = "";
if (userInput1 == "left") {
room = ("Kitchen");
System.out.println("You are in the "+room);
} else if (userInput1 == "right") {
room = ("Living Room");
System.out.println("You are in the "+room);
} else {
System.out.println("Unknown Command");
}
}
}