This laboratory exercise provides practice defining an interface in Java, implementing that interface through a Java class, and then extending that class.
In class, we discussed unordered and ordered lists as an example of interfaces and inheritance. The following files (found in directory ~walker/java/lists/) provide some details:
These files review various details of interfaces, implementation, and inheritance, and you may wish to use these as models for the latter parts of this lab.
During the semester, we have considered a hierarchy of appointments as part of our class project:
Using the above list programs as examples, one way to translate the appointment hierarchy into Java code would be to utilize interfaces and inheritance. In this hierarchy, Appointment could be an interface, AvailableAppt and UnchangeableAppt implementations, and the remaining three classes could extend AvailableAppt.
While folks working on appointment classes will need to work out the actual labs, this lab provides practice with some three operations: constructor, make an appointment, and print the appointment on the system's output. A sample interface is given in Appointment.java. (This and other class files for the appointment hierarchy in this lab may be found in directory ~walker/java/schedule/.)
A simple implementation of Appointment.java is given by UnchangeableAppt.java. In this implementation, only the owner can adjust appointment data. Also, printing content depends upon the nature of the user.
Class | Owner | Logged-in User | Unknown User |
---|---|---|---|
WalkInAppt | Can make changes | Told to drop in | Told to drop in |
SignUpAppt | Can make changes | Can sign up if comment field is null or says "office hours"; otherwise told time taken | Told e-mail request will be sent if comment field is null or says "office hours"; otherwise told time taken |
RestrictedAppt | Can make changes | Told e-mail request will be sent | Told e-mail request will be sent |
In your implementation (for now), you need not try to actually send e-mail. Instead, just make the appointment (assuming the owner will approve the request), but return a message indicating e-mail was sent.
This document is available on the World Wide Web as
http://www.walker.cs.grinnell.edu/courses/223.sp02/lab-java-inheritance.html
created March 14, 2002 last revised March 15, 2002 |
|
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |