I'm a beginner at java and I just recently started to study interfaces so I triead to make a program that had classes which implemented intefaces. Anyways, i ran into a problem with the while loop in my program. I'm tryng to give the user the opportunity to choose between talking to a robor or a person, and as far as i understand &&
checks for both of the conditions (If either one of them is true it runs the loop).
import java.util.Scanner;
public class App {
public static void main(String[] args) {
Scanner ai = new Scanner(System.in);
Conversation guy = new Human();
Conversation rox = new Robot();
System.out.println("What do you want to talk to?");
String choice = ai.nextLine();
while (choice != "Robot" && choice!= "Person"){
System.out.println("Option not available, choose again.");
choice = ai.nextLine();
}
switch(choice){
case "Person":
System.out.println("What's my name?");
guy.greet();
guy.conv();
guy.bye();
break;
case "Robot":
System.out.println("What's my name?");
rox.greet();
rox.conv();
rox.bye();
break;
}
ai.close();
}
}
I'm trying to make it so that if the input is neither "Person"
or "Robot"
it scans again for new input but despite the input being either one the program always runs the loop, Why?