Question
Worker class Instance variables: firstName(String), lastName(String), email(String), phoneNumber (long). Librarian class will be inheriting this class. So, think about the access specifiers for the instance
Worker class
Instance variables: firstName(String), lastName(String), email(String), phoneNumber (long). Librarian class will be inheriting this class. So, think about the access specifiers for the instance variables.
Constructor: parameterized constructor that gets values to set all properties of a person (Its upon you to think and decide if you need a no-arg constructor).
Methods: getter to return name. Name should be returned as one string. If your first name is Peter and your last name is Ken, getter should return Peter Ken.
Librarian class (inherits from class Worker)
Instance variables: librarianID (int)
Constructor: parameterized constructor that initializes a librarian with librarian ID and all worker properties. As you have a parameterized constructor for Worker class, use that to set worker properties.
Methods:
- readLibrarian(): accepts nothing, returns nothing. Reads all librarian information.
- printLibrarian(): accepts nothing, returns nothing. This method prints details of a librarian using formatted output (use printf).
Fulltime class (inherits from class Librarian)
Instance variables: salary (double)
Methods:
- readLibrarian(): accepts nothing, returns nothing. Make a call to the readLibrarian() method of the parent class. Then, reads annual salary from the user, converts it to monthly salary and save it in salary instance variable.
- printLibrarian(): accepts nothing, returns nothing. Make a call to the printLibrarian() of the parent class. Then, prints salary info (formatted output).
Parttime class (inherits from class Librarian)
Instance variables: hourlyRate (double), numHours (double)
Methods:
- readLibrarian(): accepts nothing, returns nothing. Make a call to the readLibrarian() method of the parent class. Then, reads hourly rate and number of hours worked.
- printLibrarian(): accepts nothing, returns nothing. Make a call to the printLibrarian() of the parent class. Then, prints salary, which is the product of hourly rate and the number of hours worked (formatted output).
Library class
Instance variables: an array of Librarian named librarians
Constructor: parameterized constructor that creates the array of librarians with the given size (this size will be read in main(), and will be sent here when creating the Library object)
Methods:
- readLibrarianDetails(): accepts nothing, returns nothing. In a for loop, read details of all librarians. First, read the type of the librarian. Based on the type of the librarian, corresponding array object needs to be created (Polymorphism). Then, call readLibrarian() method.
- printLibrarianDetails(): accepts nothing, returns nothing. In a for loop, call printLibrarian() to print details of all librarians.
- printLine(): static method that prints a line using =
- printTitle(): static method that prints the title of the output. This method gets the name of the library as a parameter, which will be used in the formatted print statement. printLine() method will be called from this method to print lines.
Lab3Test class
This is the driver class (test class), which means this class has the main method.
Main method
- This method read the name of the library (example: Quality) and the number of librarians (saved in num).
- A Library object will be created with the num.
- Call readLibrarianDetails() method to read details of all librarians
- Print the title and the header row
- Call printLibrarian() method to print details of all librarians.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started