Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. readLibrarian(): accepts nothing, returns nothing. Reads all librarian information.
  2. 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:

  1. 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.
  2. 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:

  1. 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.
  2. 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:

  1. 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.
  2. printLibrarianDetails(): accepts nothing, returns nothing. In a for loop, call printLibrarian() to print details of all librarians.
  3. printLine(): static method that prints a line using =
  4. 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.

image text in transcribed

Expected Output (green - user input) Enter name of the library: OOP How many librarians do you have? 3 Enter details of librarian 1 1. Fulltime 2. Parttime Enter type of librarian: 1 Enter Librarian ID: 110210 Enter first name: Peter Enter last name: Ken Enter email: ken@oop.com Enter phone number: 123456789 Enter annual salary: 98000 Enter details of librarian 2 1. Fulltime 2. Parttime Enter type of librarian: 2 Enter Librarian ID: 110220 Enter first name: Eric Enter last name: James Enter email: eric@oop.com Enter phone number: 213546879 Enter hourly rate: 75 Enter number of hours worked: 5 Enter details of librarian 3 1. Fulltime 2. Parttime Enter type of librarian: 1 Enter Librarian ID: 110230 Enter first name: Tim Enter last name: Hortons Enter email: tim@oop.com Enter phone number: 321654987 Enter annual salary: 85450 11 II 11 II OOP Library Management System LibrarianID Name ! Email Phone | Salary 110210 110220 110230 Peter Ken | ken@oop.com Eric James ! eric@oop.com Tim Hortons | tim@oop.com 123456789 213546879 321654987 8166.67 1 375.00 7120.83

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

5. If yes, then why?

Answered: 1 week ago

Question

3. What changes should I be making?

Answered: 1 week ago