Reference no: EM132402872
CST8284 - Object Oriented Programming (Java) - Algonquin College Assignment
Program Description
In this assignment you'll add more features to your Appointment Scheduler. For those students who failed to submit Assignment 2 you may use my copy, available on Brightspace, as the starting point for your Assignment 3 code, without citation.
I. Create an Assignment3 project and copy your existing classes to the new Project
a) Create a new CST8284_19F_Assignment3 project folder, copy the scheduler and employee packages from Assignment2 (including all its classes) to the new project, and refactor the name of the old package to cst8284.asgmt3.scheduler.
b) There is no UML diagram for this assignment; you are free to implement the requirements any way you wish, so long as it's within the existing UML framework established in Assignment 2. Note however that the principles of good code design still apply. So, at the marker's discretion, you will lose marks for not implementing best practices such as, e.g. not using getters and setters, not practicing code reuse, not employing chaining, not employing the principle of least privilege in your code design, sloppy design, etc.
(The same goes for the output. There are a limited number of changes to the program output, and all of them are related to the message and description implemented in section II(a). Aside from the actual wording-given below-you only need to decide what to put into your toString() method for output.)
II. Add the following new features to your Appointment Scheduler
a) Throw a BadAppointmentDataException to catch data input errors
Add a new BadAppointmentDataException class to your project, which extends from RuntimeException. Add two constructors to your new class: a no-arg constructor and a two- String constructor. The former constructor passes the Strings "Please try again" and "Bad data entered" to the latter via chaining. The two- String constructor uses super() to pass the first String up to the superclass (just as you did in Lab 7) so that it will be returned when you call ex.getMessage(). The second String is stored to a private String field called Description, which you'll need to add to your new exception, along with appropriate getters and setters.
In your existing code, throw a BadAppointmentDataException for each of the kinds of errors indicated in the table on the next page. The message to be displayed-the first String passed to your exception-is indicated in the right column, while the description of the error-the second String-is indicated on the left; you can use your new getDescription() method whenever you need to output this String.
Your lab professor will be running a series of tests on your code to check that each type of BadAppointmentDataException is thrown correctly with the appropriate information displayed for each error conditions indicated. So test your code thoroughly.
b) Refactor your code to sort and search Appointments using the Comparator interface
Recall that in Assignment 2 we searched through our ArrayList of Appointments using the same mechanism as in Assignment 1: by laboriously searching through each element until we found the Calendar object we were looking for.
Clearly, there's a better way to do this.
The ‘better way' is to sort the ArrayList first by its Calendar date. Then, when we wish to locate an Appointment, the search is much faster and more efficient. To organize the Appointments by date, we first need to implement a Comparator, so begin by creating a new class SortAppointmentByCalendar that implements the Comparator interface. Inside that class, you'll need to override the compare() method so that it returns an integer value representing the difference between the Calendar's of the two Appointment's input as parameters to the compare() method. Then, use an instance of your SortAppointmentByCalendar object to sort the ArrayList using the Collections sort() method (but be sure to use the overloaded version that takes a comparator as its second parameter). For details on this, see the course notes, or consult the web for guidance (as always, be sure to cite your sources). The following will help get you started:
Once your comparator is built and tested, searching for a particular Appointment by Calendar date is straightforward, this time using the Collections.binarySearch() method. Again, you'll probably want to do some research on this.
You'll want to use the overloaded binarySearch() method, the one with the signature:
public static <T> int binarySearch (List<? extends T> list, T key, Comparator<? super T> c)
That is, use the binarySearch() method that takes as its third parameter the same Comparator object you used in the sort() method.
Use the Collections sort() and binarySearch() methods in your existing code to refactor the findAppointment() method. (You may also find that other methods need refactoring as well once you make the change, depending on how you implemented your code.)
Finally, note that if each time you save an Appointment (in saveAppointment()), you sort the ArrayList as well, you can save yourself some time whenever you need to search the ArrayList.
c) Document your code using JavaDoc
JavaDoc adds hypertext-linked documentation to your code-you saw it briefly in Lab 1-allowing you to output rich text comments similar to those seen on the Oracle web site for each Java class. Provided, that is, you take the time to write and lay out your comments correctly. (See the sample documentation, available at the Oracle web site, below.) A good place to begin with JavaDoc is which explains what each tag does. For this assignment, the following tags are essential:
For the class: For methods/constructors
@author @param
@version @returns
@throws
You can safely ignore @see and @since for this assignment. Feel free to implement any other JavaDoc and HTML tags you feel are appropriate. You'll need to refer the Algonquin College Documentation Standard (ACDS), a set of (somewhat dated) slides indicating which components of your code need to be documented (short answer: pretty much everything). The document is available on Brightspace. The ACDS specifies that you must document both the file and the class (because a file may contain more than one class.) In this assignment, you're fee to ignore the first requirement: document each class only.
Your efforts to document your code correctly will all be for nothing if you don't follow the instructions in the Appendix below exactly.
This is because the JavaDoc utility does not operate on all the folders in your project, but only on the folders and subfolders that you have selected at the time you run the utility. So if you click on a class and then execute the JavaDoc utility, you will only generate JavaDoc for the methods and constructors in that class-and nothing else. And you will get ‘0' for your documentation, regardless of how detailed the description of your code was inside each class since you are marked for the JavaDoc output only.
Attachment:- Object Oriented Programming.rar