I'm not sure why the console scanner is not accepting month in two-digit form, like 10,11,12. Only accepts single digit.
I have same prompts, and boolean validation methods for year and day, and they work as expected.
private int promptForMonth() {
String monthResponse = "";
int month = -1;
do {
System.out.println("\t" + "Please enter the month number - "
+ "for example '6':");
monthResponse = scan.next();
if (validateMonthString(monthResponse)) {
month = Integer.parseInt(monthResponse);
}
} while (month == -1);
return month;
}
boolean validation below.
private boolean validateMonthString(String month) {
boolean isValid = true;
if (month.charAt(0) == '0') {
isValid = false;
return isValid;
} else if (!(month.length() == 2)) {
isValid = false;
return isValid;
}
for (int x = 1; x < month.length(); x++) {
if (!(month.charAt(x) >= 49 && month.charAt(x) <= 57)) {
isValid = false;
return isValid;
}
}
if (Integer.parseInt(month) > 12) {
isValid = false;
return isValid;
}
return isValid;
}