Question
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,
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 <
+getAnnualSalary(): double <
+pay(): double <
+toString(): String <
--------------------------------------------------------------------------------- PayWithWage <
+getHourlyRate(): double <
+setHourlyRate(hourlyRate: double): void <
+regularPay(): double +overtimePay(): double +pay(): double <
--------------------------------------------------------------------------------- PayWithNoPay <
--------------------------------------------------------------------------------- +pay(): double <
--------------------------------------------------------------------------------- Employee <
+getFirst(): String <
+setFirst(first: String): void <
+payCheck(): double
+compareTo(Employee o): int <
+toString(): String <
==========================================================================================
--------------------------------------------------------------------------------- FullTime <
--------------------------------------------------------------------------------- +FullTime(first: String, last: String, annualSalary: double)
+toString(): String <
--------------------------------------------------------------------------------- PartTime <
--------------------------------------------------------------------------------- +PartTime(first: String, last: String, hourlyRate: double, hoursPerWeek: double)
+toString(): String <
--------------------------------------------------------------------------------- Intern <
--------------------------------------------------------------------------------- +PartTime(first: String, last: String)
+toString(): String <
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