Hi, y'all!
I'm new to the forums, and also to Java programming. I'm trying to write a Cash Till program for a project but I keep having a problem with my input.
//Main Method
public static void main(String[] args)
{
userVerify();
drawMainMenu();
userInput();
while (inputStr != "1" && inputStr != "2")
{
System.out.println("\n--------------------------" +
"\nERROR: Input Out of Range." +
"\n--------------------------\n\n");
drawMainMenu();
userInput();
}
//DUMMY EFFECTS: This part includes what happens
// after the selection is made.
System.out.println(inputStr);
System.exit(0);
}//end main
.
.
.
//Method to acquire input from user
static String userInput()
{
try
{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
inputStr = br.readLine();
}//end try
catch (IOException ioe)
{
ioe.printStackTrace();
System.exit(1);
}//end catch
return inputStr;
}//end method userInput
The drawMainMenu() method does no logic; it just displays the menu. It displays, however, the two choices the user can take: "1" to go to Transactions, and "2" to Exit. The String inputStr is declared globally as a static String.
There seems to be nothing wrong with userInput(), 'coz the userVerify() method also calls the same method and it works just fine. At the main method, however, if I enter "1" or "2" from userInput(), it still goes through the while loop! I can't understand what's wrong. Please help!
Thanks so much in advance for any advice/comment. All suggestions are very much appreciated.