Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When comes to the pay() method in the employee class, is the best solution to use the instanceof command in an if else statement and

When comes to the pay() method in the employee class, is the best solution to use the instanceof command in an if else statement and instantiate a FullTime, PartTime, and Intern objects and then call the pay() from each individual class?

Objectives: - To understand the effectiveness of interfaces and how to use them. - To get more practice with file IO. - To get more exposure to Unit testing. ========================================================================================== Project setup: Existing project: Rename the project to mp.

========================================================================================== Language features used: - inheritance - polymorphism - exceptions - file IO - Abstract classes and Interfaces ========================================================================================== Problem Description: In this assignment you are going to make use of files to read in Employee records into an array. This array will then be sorted using selection sort, and then the results displayed to the screen. See output below.

The assignment will make use of abstract classes and interfaces to tie everything together. See the requirements below for details. ========================================================================================== Sample output:

Original employee list: ----------------------- Intern: [iLast1, iFirst1] [Paycheck: $0.00] FullTime: [ftLast1, ftFirst1] [Annual salary: $65000.00] [Paycheck: $2500.00] PartTime: [ptLast1, ptFirst1] [hours: 50.0 (r: 40.0, o: 10.0)] [rate: $13.50] [Paycheck: $742.50 (r: $540.00, o: $202.50)] FullTime: [ftLast2, ftFirst2] [Annual salary: $55000.00] [Paycheck: $2115.38] PartTime: [ptLast2, ptFirst2] [hours: 40.0 (r: 40.0, o: 0.0)] [rate: $20.00] [Paycheck: $800.00 (r: $800.00, o: $0.00)]

Sorted employee list: --------------------- FullTime: [ftLast1, ftFirst1] [Annual salary: $65000.00] [Paycheck: $2500.00] FullTime: [ftLast2, ftFirst2] [Annual salary: $55000.00] [Paycheck: $2115.38] Intern: [iLast1, iFirst1] [Paycheck: $0.00] PartTime: [ptLast1, ptFirst1] [hours: 50.0 (r: 40.0, o: 10.0)] [rate: $13.50] [Paycheck: $742.50 (r: $540.00, o: $202.50)] PartTime: [ptLast2, ptFirst2] [hours: 40.0 (r: 40.0, o: 0.0)] [rate: $20.00] [Paycheck: $800.00 (r: $800.00, o: $0.00)] ========================================================================================== Program requirements: The file "employees.txt" is provided for you. Make sure it is newline terminated in your environment (Windows users).

The file consists of three types of employee record, I-Intern, F-Full time, and P-Part time. Each record type has a variable amount of fields as shown below:

I,, F,,, P,,,,

There are three types of employees, FullTime, PartTime and Intern, each represented by a corresponding concrete class. The abstract Employee class serves as their superclass. The Employee class implements the Comparable interface, so that employees can be compared to each other by last name first name order.

The interface PayPolicy is implemented by the three concret pay classes, PayWithSalary, PayWithWage and PayWithNoPay. Each one defines the pay behavior that employees may exhibit. This interface is used by the Employee class as a property defining each Employee's pay behavior.

Several classes have been provided that need implementing. These are: (1) Employee - the absract superclass (2) FullTime - the full time employee (3) PartTime - the part time employee (4) Intern - the intern (5) PayPolicy - the interface defining pay behavior (6) PayWithSalary - pay class for salaried employees (FullTime) (7) PayWithWage - pay class for hourly employees (PartTime) (8) PayWithNoPay - pay class for free labor (Intern) (9) Main - the driver Refer to each class for TODO comments. These will instruct you to what you need to add/change. Below are the UML class diagrams of all the classes, interfaces you are to add. ==========================================================================================

--------------------------------------------------------------------------------- PayPolicy <> ---------------------------------------------------------------------------------

--------------------------------------------------------------------------------- +pay(): double --------------------------------------------------------------------------------- Method notes: - pay(): the abstract method that all classes implementing this interface must provide ==========================================================================================

--------------------------------------------------------------------------------- PayWithSalary <> --------------------------------------------------------------------------------- -annualSalary: double --------------------------------------------------------------------------------- +PayWithSalary(annualSalary: double)

+getAnnualSalary(): double <> +setAnnualSalary(annualSalary: double): void <>

+pay(): double <>

+toString(): String <> --------------------------------------------------------------------------------- Method notes: - ctor: Initializes object. - pay(): returns the bi-weekly paycheck amount. ==========================================================================================

--------------------------------------------------------------------------------- PayWithWage <> --------------------------------------------------------------------------------- -hourlyRate: double -hoursPerWeek: double -regularHours: double -overtimeHours: double --------------------------------------------------------------------------------- +PayWithWage(hourlyRate: double, hoursPerWeek: double)

+getHourlyRate(): double <> +getHoursPerWeek(): double <> +getRegularHours(): double <> +getOvertimeHours(): double <>

+setHourlyRate(hourlyRate: double): void <> +setHoursPerWeek(hoursPerWeek: double): void <>

+regularPay(): double +overtimePay(): double +pay(): double <> --------------------------------------------------------------------------------- Method notes: - ctor: Initializes object. - setHoursPerWeek(): sets all hour properties. If more than 40 hours are worked then those extra hours are the overtime hours. - regularPay(): returns a 40 hour pay load. - overtimePay(): returns the overtime pay at 1.5 the rate. - pay(): returns the weekly total paycheck amount. ==========================================================================================

--------------------------------------------------------------------------------- PayWithNoPay <> ---------------------------------------------------------------------------------

--------------------------------------------------------------------------------- +pay(): double <> --------------------------------------------------------------------------------- Method notes: - pay(): returns 0.0, since interns do not get paid. This choice makes things simpler. ==========================================================================================

--------------------------------------------------------------------------------- Employee <><< implements Comparable >> --------------------------------------------------------------------------------- -first: String -last: String #payPolicy: PayPolicy --------------------------------------------------------------------------------- #Employee(first: String, last: String, payPolicy: PayPolicy)

+getFirst(): String <> +getlast(): String <> +getName(): String <> +getPayPolicy(): PayPolicy <>

+setFirst(first: String): void <> +setLast(last: String): void <> +setName(first: String, last: String): void <> +setPayPolicy(payPolicy: PayPolicy): void <>

+payCheck(): double

+compareTo(Employee o): int <>

+toString(): String < --------------------------------------------------------------------------------- Method notes: - payCheck(): This method produces the employee's paycheck, whether weekly or bi-weekly, based on the employee type. This determination is made by the .pay() method of the corresponding PayWithxxx class, which know how to create such a paycheck. Simply call this .pay() method and return its result. - compareTo(): This should compare the two employee instances using the formatted string: - descriptor: Returns the formatted string: [, ]

==========================================================================================

--------------------------------------------------------------------------------- FullTime <> ---------------------------------------------------------------------------------

--------------------------------------------------------------------------------- +FullTime(first: String, last: String, annualSalary: double)

+toString(): String <> --------------------------------------------------------------------------------- Method notes: - ctor: Initializes its superclass. Note that the annualSalary is a property of the PayWithSalary class, which FullTime objects conform to. - descriptor: Returns the formatted object: FullTime: [, first>] [Annual salary: $] [Paycheck: $] ==========================================================================================

--------------------------------------------------------------------------------- PartTime <> ---------------------------------------------------------------------------------

--------------------------------------------------------------------------------- +PartTime(first: String, last: String, hourlyRate: double, hoursPerWeek: double)

+toString(): String <> --------------------------------------------------------------------------------- Method notes: - ctor: Initializes its superclass. Note that the hourlyRate and hoursPerWeek are properties of the PayWithWage class, which PartTime objects conform to. - descriptor: Returns the formatted object: PartTime: [, first>] [hours: (r: , o: )] [rate: $] [Paycheck: $ (r: $, o: $)] Note: indicates continuation on the same line, i.e. the string is one single line. ==========================================================================================

--------------------------------------------------------------------------------- Intern <> ---------------------------------------------------------------------------------

--------------------------------------------------------------------------------- +PartTime(first: String, last: String)

+toString(): String <> --------------------------------------------------------------------------------- Method notes: - ctor: Initializes its superclass, conforming to the PayWithNoPay() pay class. - descriptor: Returns the formatted object: Intern: [, first>] [Paycheck: $]

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

Rules In Database Systems Third International Workshop Rids 97 Sk Vde Sweden June 26 28 1997 Proceedings Lncs 1312

Authors: Andreas Geppert ,Mikael Berndtsson

1997th Edition

3540635165, 978-3540635161

More Books

Students also viewed these Databases questions

Question

2. Identify the purpose of your speech

Answered: 1 week ago