Reference no: EM132210414
Question :
Write a program named (Scheduler.java) that allows students to schedule appointments at either 1, 2, 3, 4, 5, or 6 o'clock pm.
The program should accept up to 6 appointments, making sure that there is no time conflict or an invalid time slot is requested.
You will need to do the following:
o Declare an array appointments that can hold six Strings to store the names for the time slots.
o Declare a counter appointmentsMade to count how many appointments were made.
o Write a loop that iterates as long as the array has a free space.
o Two of the classes that you need to include are declared below and you need to write the code for the third class according to the given instructions:
1. public class TimeInUseException extends Exception{
/** * Creates a new instance of TimeInUseException */ public TimeInUseException(String reason) { super(reason); }
2. public class InvalidTimeException extends Exception{
/** * Creates a new instance of InvalidTimeException */
public InvalidTimeException(String reason) {
super(reason); } }
3. public class Scheduler:
o Will include the main() method with instance variables declarations and try and catch blocks.
o Within the try block, allow the user to enter his/her name and the requested time slot.
o If the time slot is not already occupied (i.e. free), put the user's name in the appointments array.
o You will need to write three catch blocks that will catch the following exceptions:
InvalidTimeException - that will display the message "Sorry, that is not a legal time"
TimeInUseException - that will display the message "Sorry, that time is already in use"
Exception - that will display the message "Bad time format, should just be an integer"
o If the time is not free, throw a TimeInUseException.
o If the time is not valid, throw an InvalidTimeException.
o If the user enters a time that is not an integer, throw Exception.