August 2000
JP219 : JAVA PROGRAMMING

QUESTION 4

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 4

You are required to implement a reservation system for meeting rooms. A room has a name, for example “Meeting Room”, and it has a number of slots. A slot is a time period in which the room may be booked. A slot has a time, and a day. The time can be any one of 9 am, 10 am, etc all the way to 4 pm, and a day can be any one of Monday to Friday. When a slot is booked,
it has filled in the name of the person booking the slot, and the reason for the meeting.
Consider the following enumerated class Day, which enumerates the days of the week:

public final class Day {
  public final static int Monday = 0;
  // ... etc ...
  public final static int Friday = 4;
}

public final class Time {
  public final static int am9 = 0;
  public final static int am10= 1;
  // ... etc ...
  public final static int pm4= 7;
};

(a) Define the class Slot, which has the attributes Day, as above, and Time. In addition to this, it should contain two strings, one for the name of the person booking the room and one for the reason they have for booking it. [3 marks]

(b) Define the class Room, such that it has a name, which is a string that cannot be overloaded by derived classes, and an array of 40 slots, one for each available slot in the week. This array should not be visible to other classes, but may need to be to any derived classes. [3 marks]

(c) Add to your class a constructor function, which initialises the name of the room, and the time and day in each slot, as well as setting the name and reason to empty strings to indicate that the room has not been booked. [5 marks]

(d) Add to your class a method Book, such that it takes an integer parameter which identifies a particular Slot, and two strings giving a name and a meeting, and books the corresponding slot in the room should it be free. The method should return true if the meeting has been successfully booked, and false otherwise. [4 marks]