The objective of this question is

  • to use the Java exception handling facility in a program
  • to define and use an exception class
  • to write program code that will throw user-defined exceptions

Write a program to manage data for instructors in the training institution given the Instructor class and a partially completed Q2 class in appendix B.

(a) Implement the Java class InvalidInstructorException class. This class should be written as a subclass of Exception. An object of this class is created whenever the InstructorList class that you will implement in (b) raises an error. The constructor of the InvalidInstructorException class sets the exception message to the message pass in.

(b) Implement the Java class InstructorList class. This class models a collection of instructors and has the following:

  • attribute instructors (ArrayList < Instructor>) to store the collection of Instructor objects.
  • searchInstructor( String id) method that returns the Instructor object with the given id, if such an instructor exists. Otherwise, the method returns null.
  • addInstructor (String id, String name, int contact) method that first checks if an Instructor object with the given id, already exists. If so, the method should raise and error by throwing an InvalidInstructorException object with the message that the id already exists. Otherwise, the method adds a new Instructor object with the given id, name, and contact and returns the Instructor object.
  • removeInstructor (String id) method that first checks if an Instructor object with the given id, already exists. If so, the method removes the Instructor object with the given id and returns the Instructor object. Otherwise, the method should raise an error by throwing an InvalidInstructorException object with the message that the id does not exist.
  • listInstructors ()method that returns a string consisting of the details of all the Instructor objects in the collection instructors.

(c) Complete the Java class Q2 class given in Appendix B.

This class is an application class that repeatedly displays a menu to let the user invoke the methods of the InstructorList object. Modify it to perform the following:

  • Create an InstructorList object.
  • Repeatedly display a menu, prompt the user for a choice, and then invoke the appropriate methods on the InstructorList object.
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.