I am trying to do a while loop but it kept failing on me. So while date is not entered by the user, this will keep running until a valid date is entered. isValidDate is a method to check whether the date is true or false. Date will only be true when enter dd/mm/yy.
I am trying to put a check on whether the date is correct or not. If it is correct, it will be stored into the String date and the program will continue. If it is incorrect, the program will then prompt the user again for the correct date.
When I first enter a incorrect date, it will then prompt me for the correct date to be entered again. At this point, when I enter a correct date, the program could not verify if it is a correct date or not anymore. Why is this happening?
Please help!
public void bookingA(){
bkList = new ArrayList<bookingInfo>();
Scanner keys = new Scanner(System.in);
String date;
System.out.println("\nEnter the date: ");
while(!isValidDate(keys.nextLine())) {
do {
System.out.println("That is not a valid date! Please enter again (dd/mm/yy): ");
date = keys.nextLine();
} while (!isValidDate(date));
System.out.print(date);
break;
}
}