public int displayMenuGetChoice(){
System.out.println("Specialty Auto");
System.out.print("\n(1) Display the Entire automobile list"
+ "\n(2) Display the entire automobile inventory sorted by year"
+ "\n(3) Display automobiles available for sale"
+ "\n(4) Display list of recently sold automobiles"
+ "\n(5) Output a mailing list of recent buyers"
+ "\n(6) Find automobile by VIN number"
+ "\n(7) Quit"
+ "\n\nEnter your choice (1-7): ");
while (!keyboard.hasNextInt() || keyboard.nextInt() < 1 || keyboard.nextInt() > 7){
System.out.println("Invalid Input");
System.out.println("Specialty Auto");
System.out.print("\n(1) Display the Entire automobile list"
+ "\n(2) Display the entire automobile inventory sorted by year"
+ "\n(3) Display automobiles available for sale"
+ "\n(4) Display list of recently sold automobiles"
+ "\n(5) Output a mailing list of recent buyers"
+ "\n(6) Find automobile by VIN number"
+ "\n(7) Quit"
+ "\n\nEnter your choice (1-7): ");
keyboard.nextInt();
}
return keyboard.nextInt();
}
Here is what I have, I need to validate to make sure the user is inputting a number 1 through 7 but also not entering any letters, it works sort of. When I test it for when I dont make an intentional error (using the number 1) I have to enter it 3 times before the proper dialog comes up. what am I doing wrong?
edit: I'm not sure why you tagged to that other post, it didn't clear anything up for me it seems like a similar but different question.