Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions/Requirements In this lab, we are writing an object-oriented program incorporating abstraction, encapsulation, polymorphism and inheritance that uses an array of Librarian as an attribute

Instructions/Requirements

In this lab, we are writing an object-oriented program incorporating abstraction, encapsulation, polymorphism and inheritance that uses an array of Librarian as an attribute of a Payroll object with two of each of the following kinds of librarians:

Parttime

-First name

-Last name

-email

-hourly rate: $45 (same for all contractors)

-hours per week

-tax rate: 15% (that is, 0.15) (only contractors have this property)

-method of payment: mail a check

-weekly payroll calculation: hours * rate * (1 + tax rate) + (a bonus: $10 * a quarter of hours worked each week).

Fulltime

-First name

-Last name

-email

-hourly rate: $30 (same for all regular librarians)

-hours per week

-deduction rate: 17% (that is,0.17) (only regular librarians have this property)

-method of payment: direct deposit

-weekly payroll calculation: hours * rate x (1 deduction rate) + (a bonus: $5 * a fifth of hours worked each week).

You may start with your lab 3 program. To do this it is important that move the details of worker class to Librarian class and delete Worker class. Payroll class will replace library class as you will see below.

Write down Java classes including an abstract Librarian class with two abstract methods - one that does the payroll calculation and the other that prints the method of payment. Consider first & last name, email, hourly rate, hours per week, tax rate and deduction rate as attributes, and consider the method of payment and payroll calculation to be behaviors.

Implement the method of payment behavior by printing out a suitable string when the payment is made. For example, your payment method could take an amount parameter, and consist of a single line: System.out.println("Direct depositing " + amount + " to " + name + "'s bank account");

Your method for calculating the payment should return a double.

The constructor for your Parttime and Fulltime classes will accept first name, last name, email and number of hours worked as parameters, and initialize all those properties. Properties like hourly rate, tax rate and deduction rate will be initialized with the values given above. Super call must be made to call super class constructor from the child class constructor.

Here is the driver class:

package payrollabstractclass;

import java.util.Scanner;

public class Lab4Test { public static void main(String[] args) {

//creating an instance for Scanner class

Scanner input = new Scanner(System.in);

System.out.println(" Enter number of librarians: ");

int num = input.nextInt();

//creating payroll object for Payroll class with num parameter

Payroll payroll = new Payroll(num);

//invoking readLibrarians method

payroll.readLibrarians();

System.out.println(" Summary of Payroll Processing");

System.out.println("================================");

//invoking processPayroll method

payroll.processPayroll();

input.close(); } }

In Payroll class, you need to read personal information including the type of the librarian. For the payroll calculation, for each librarian, calculate the amount owed to that librarian and pass that as a parameter to the librarians payment method. You need to write the code that performs the calculation (do not hard-code the payroll figures).

Here is the worker class:

public class Worker {

protected String firstName; protected String lastName; protected String email; protected long phoneNumber;

public Worker(String firstName, String lastName, String email, long phoneNumber){ this.firstName = firstName; this.lastName = lastName; this.email = email; this.phoneNumber = phoneNumber; }

public String getName() { return firstName + " " + lastName; }

public Worker(){ }

}

Here is the librarian class:

import java.util.Scanner; public class Librarian extends Worker{ protected int librarianID;

public Librarian() { }

public Librarian(String firstName, String lastName, String email, long phoneNumber, int librarianID){ super(firstName, lastName, email, phoneNumber); this.librarianID = librarianID; }

public void readLibrarian() { Scanner scanner = new Scanner(System.in); System.out.print("Enter Librarian ID: "); this.librarianID = scanner.nextInt(); scanner.nextLine(); System.out.print("Enter first name: "); this.firstName = scanner.nextLine(); System.out.print("Enter last name: "); this.lastName = scanner.nextLine(); System.out.print("Enter email: "); this.email = scanner.nextLine(); System.out.print("Enter phone number: "); this.phoneNumber = scanner.nextLong(); }

public void printLibrarian() { } }

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_2

Step: 3

blur-text-image_3

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

Object Oriented Databases Prentice Hall International Series In Computer Science

Authors: John G. Hughes

1st Edition

0136298745, 978-0136298748

More Books

Students also viewed these Databases questions

Question

COMPARE the three types of organization-wide incentive plans.

Answered: 1 week ago

Question

Explain the contribution of Peter F. Drucker to Management .

Answered: 1 week ago

Question

What is meant by organisational theory ?

Answered: 1 week ago

Question

What is meant by decentralisation of authority ?

Answered: 1 week ago

Question

Briefly explain the qualities of an able supervisor

Answered: 1 week ago

Question

Question Can a self-employed person adopt a profit sharing plan?

Answered: 1 week ago