I have an "Appointment" class as follows
private String month;
private int day;
private int hour, minute;
private String message;
Appointment() {
month = "Jan";
day = 1;
hour = 12;
minute = 0;
message = "message";
}
private void setMonth(String monthIn) {
if (monthIn.length() > 3) {
System.out.println("Re-enter and keep month to 3 letters");
} else {
month = monthIn;
}
}
private void setDay(int dayIn) {
day = dayIn;
}
private void setHour(int hourIn) {
hour = hourIn;
}
private void setMinute(int minuteIn) {
minute = minuteIn;
}
private void setMessage(String messageIn) {
message = messageIn;
}
public void inputAppointment() {
System.out.println("Input appointment (month, day, hour, minute, message)");
setMonth(UserInput.getString());
setDay(UserInput.getInt(1, 31));
setHour(UserInput.getInt(1, 12));
setMinute(UserInput.getInt(0, 59));
setMessage(UserInput.getString());
}
In my main method i have
Appointment app = new Appointment();
app.inputAppointment();
But I'm only able to input the first string and the following 3 integers. setMessage(UserInput.getString()); never executes. The arguments sent to the set methods in inputAppointment() call methods from a "UserInput" class that handles input as follows
public static String getString() {
return scan.nextLine();
}
public static int getInt() {
return scan.nextInt();
}
public static int getInt(int min, int max) {
int input = getInt();
if (input >= min && input <= max) {
return input;
} else {
System.out.println("Invalid input. Re-enter...");
return getInt(min, max);
}
}