public class ElectronicCounter {
public ElectronicCounter(User user)throws IOException{
Scanner scanner = new Scanner(System.in);
boolean done = false;
loginName = user.getName();
System.out.println("--------------------------------------------------------");
System.out.println("Welcome to the Electronic-Sales Counter! ");
while(!done){
try{
System.out.print("Please enter '1' to record sales or '2' to exit:");
input = scanner.nextLine();
System.out.println("bug");
if(input=="1"){
System.out.println("Please enter a list of purchasing-product ID and number");
done = true;
}
else if(input=="2"){
System.out.println("<LOG> User " +loginName+ " has successfully logged off! ");
done = true;
}
else{
System.out.println("<LOG> Invalid command");
}
}
catch (NoSuchElementException e){
System.out.println("<LOG> No Such Element");
}
catch (IllegalStateException e){
System.out.println("<LOG> IllegalState");
}
}
scanner.close();
}
static String loginName;
static String input;
}
The scanner doesn't stop to search the token when scanner.nextLine()
is computed. I would like to ask how can I stop the scanner to wait input??Thanks