Basically as you can see from the code, I want the user to enter a date, (start date & end date) but I want to make sure that the system doesn't let he user type in something else. and the user should be able to type it again. Where am I going wrong?
System.out.println("Enter your date here: ");
Scanner scan = new Scanner (System.in);
UserInput = scan.nextLine();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date date = new SimpleDateFormat("dd-MM-yyyy").parse(UserInput);
while (true) {
if (!isValidDate(date)){
System.out.println(dateFormat.format(date));
break;
}
else {
System.out.println("That is not a valid date! Please enter again (dd-mm-yy): ");
UserInput = scan.nextLine();
break;
}
}
private static boolean isValidDate(Date date) {
// TODO Auto-generated method stub
return false;
}
and also if I will finally manage to do this? how can I add it an array saved in another class? my array are like this
arrayUsers[0] = new User("User", "One", 1234, 1234, 0);
arrayUsers[1] = new User("User2", "Two" , 4321, 4321, 0);
I would like to add these "start date & date" here, but after 0 at the end of array. Thanks