I'm creating a program and for part of it, the user must enter the date in the format "MM/DD/2008". I already have the pieces in place to take the month and date separately but how do I make sure that they entered it correctly and not "M/D/2008" or a letter?
Here's the case that asks for the input...
System.out.print("Please enter a date to view (MM/DD/2008, 0 to Quit):\n");
String dateChoice = scan.next();
while (!dateChoice.equals("0")) {
String[] tokens = dateChoice.split("/");
int month = Integer.parseInt(tokens[0]) - 1;
int date = Integer.parseInt(tokens[1]) - 1;
choice.weatherRecord(month, date);
System.out.print("Please enter a date to view (MM/DD/2008, 0 to Quit):\n");
dateChoice = scan.next();
}