So i've got an assignment for class and i'm completly stuck. I've lurked around here all semester and have found what i've needed but this time i'm lost. I need help with a try catch statement inside of a loop. The assignment wants us to have people input their names and choose a schedule time 1, 2, 3, 4, 5, 6. with exceptions if it is outside of that range or if the time is already taken. heres what i've got so far. when ran, it'll let me put the first name in and a time, but gives me an error for line 40, which is the "if(timeSlot[i] <1 || >6){ "
line.
Any help would be appreciated,Thanks
import java.util.Scanner;
public class Scheduler {
Scanner input = new Scanner(System.in);
public static void main(String[] args) throws TimeInUseException,
InvalidTimeException {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
String name[] = new String[6];
int timeSlot[] = new int[6];
//as long as there is less than 6 it will keep running
int d = 0;
while (d < 6) {
//try block to see if the time slot has been taken
try {
for (int i = 0; i < name.length; i++) {
//ask for the name
System.out.println("Please type your name: ");
name[i] = input.nextLine();
//ask for the time
System.out.println("Please select a time: 1, 2, "
+ "3, 4, 5, 6");
timeSlot[i] = input.nextInt();
// if the time is less than 1 or greater than 6
// it will throw an invalid time exception
if (timeSlot[i] < 1 || timeSlot[i] > 6) {
throw (new InvalidTimeException());
}
// if the time slot is not equal to null(not empty)
// it will throw a time in use exception
if (timeSlot[i] != null) {
throw (new TimeInUseException());
}
}
} // catch for invalid time
catch (InvalidTimeException ite) {
ite.getMessage();
} //catch for time in use
catch (TimeInUseException tiue) {
tiue.getMessage();
}
d++;
}
for (int i = 0; i < 6; i++) {
System.out.println(name[i] + " has an appointment at: "
+ timeSlot[i]);
}
}
}
the exceptions per request
public class InvalidTimeException extends Exception{
//sets the String to say time is in use
public InvalidTimeException(String message) {
super(message);
message = "That time is invalid, please enter either 1, 2, 3, 4, 5, or 6";
}
InvalidTimeException() {
throw new UnsupportedOperationException("That time is invalid, please enter either 1, 2, 3, 4, 5, or 6"); //To change body of generated methods, choose Tools | Templates.
}
}
And the second one
public class TimeInUseException extends Exception {
//sets the String to say time is in use
public TimeInUseException(String message) {
super(message);
// message = "That time is already in use, please select another";
}
TimeInUseException() {
throw new UnsupportedOperationException("That time is already in use, "
+ "please select another");
}
}