Java Lab #12: Comparable Interface
Continue extending the Figs project by taking the following steps.
- Modify class Date so it implements the interface
Comparable<Date>. This entails adding a compareTo method. Read
about what the method is supposed to do in the documentation for
Comparable.
- Modify class Time and also class Event similarly. Notice that your
compareTo in class Event effectively defines the "natural order" of
events. Define it so that events are naturally in chronological order. In the case where
two events have the same date and time, use compareTo on the description to
decide the order.
- In Datebook's addEvent method use Collections.sort to sort
the datebook according to the natural order of events. This allows you to eliminate the
tricky and error prone code that inserts an event in the correct place. Instead just
insert the event at the end of the list and sort the entire list to force the new event to
find its correct location.
Send me the files you modified.