Lab 2: Interfaces

Objectives

Resources

Introduction

In this lab, you will explore using interfaces to represent items on a calendar.

The Schedulable interface represents an item that can appear on one's calendar. It can represent a meeting, a class (or section), or even an entire calendar. The Meeting, Section, and Calendar classes all implement the Schedulable interface. The primary abilities of something that is Schedulable are that you can see if it is busy at a particular time, add to or remove from the schedule, and get the schedule's name.

Assignment Details

Due at the beginning of lab: You must create the interface and all of the classes shown in the UML diagram. You must have stub implementations of all of the methods implemented. The program does not need to be functional, but the project must compile without any errors prior to lab.

A class diagram for the program is shown in the figure below:

You will implement all of the classes shown in the diagram.

The class constants in the interface are used to represent different days of the week. You should use these constants instead of integer values when specifying a day. Each method should behave as follows.

Specifics for Different Implementations

The Meeting class represents the simplest implementation of Schedulable. A meeting represents one schedulable item that could appear on a calendar. It is one contiguous time slot that is represented by a starting time (hour), duration, and day. Both add() and remove() do nothing other than returning false, and the getName() method returns X.

The Section class represents a collection of meetings representing a course section. The Driver class demonstrates creating a section that consists all of the meeting times for a class. Each of the items added to the object are stored in the items instance variable. The constructor uses Java's varargs feature to allow one to pass zero or more schedulable items to the constructor.

The varargs feature allows one to define a method that accepts zero or more arguments. The following are all legal ways to create a Section.
Section section = new Section("Empty");
section = new Section("OneCredit", new Meeting(8, 1, MONDAY));
section = new Section("LectureOnly", new Meeting(8, 1, MONDAY),
                                     new Meeting(8, 1, WEDNESDAY),
                                     new Meeting(8, 1, FRIDAY));

All of the Schedulable items passed are stored in an array called items. In the first case, the array is empty; In the second case, the array has one element; and in the third case, the array has three elements.

The Calendar class represents a person's entire calendar. Sections and meetings can all be added to the calendar. It operates very similarly to the Section class, but has two additional methods:

Driver Class

The starting repository contains a Driver class that creates two calendars. You must implement the getStudentCalendar() that creates a calendar with your schedule for this term. When implemented, your solution should produce output for the two calendars that matches the following (including aligning the columns):

| **Dr. Bukowy** | Mon | Tue | Wed | Thu | Fri |
| -------------- | --- | --- | --- | --- | --- |
|           7:00 |     |     |     |     |     |
|           8:00 |  X  |  X  |  X  |  X  |  X  |
|           9:00 |  X  |  X  |  X  |  X  |  X  |
|          10:00 |     |     |     |     |     |
|          11:00 |     |     |     |     |     |
|          12:00 |     |     |     |  X  |     |
|          13:00 |     |  X  |  X  |  X  |  X  |

| **Prof. Jones** | Mon | Tue | Wed | Thu | Fri |
| --------------- | --- | --- | --- | --- | --- |
|            8:00 |  X  |  X  |  X  |     |  X  |
|            9:00 |  X  |  X  |  X  |  X  |  X  |
|           10:00 |     |     |     |  X  |     |
|           11:00 |     |     |     |     |     |
|           12:00 |     |     |     |     |     |
|           13:00 |     |  X  |  X  |  X  |  X  |
|           14:00 |  X  |  X  |     |  X  |  X  |
|           15:00 |     |     |     |     |     |
|           16:00 |     |     |     |     |     |

Acknowledgment

This laboratory assignment was developed by Dr. Chris Taylor.

See your professor's instructions for details on submission guidelines and due dates.