Question: Java inheritance and polymorphism program - all properties of the classes should be private Base class - Employee class that contains attributes common to every

Java inheritance and polymorphism program - all properties of the classes should be private

Base class - Employee class that contains attributes common to every employee. Employee contains a name and hourly pay rate. Explicit value constructor should be used to set both values when an Employee object is created. Use mutator method for both properties. Should be weekly pay method that takes int parameter for number of hours worked. Returns amount of pay for week. If hours worked < 40, the pay is the number of hours times the rate. If >= 40, pay is 40 times the rate. Use toString method which returned both properties each property on separate line.

Derived classes

1) Union Employee inherits from Employee class. Contains a dues variable which holds amount of dues a union employee has withheld from their paycheck each week. Should be explicit value constructor provided to set both values from the base class along with the dues value. Use mutator method to set the dues property. The base class weekly pay method must be overridden since Union Employee gets 1.5 times the pay rate for any hours greater than 40 per week. This method should use the base class weekly pay method to calculate pay for first 40 hours and THEN add overtime amount. This method reduces weekly pay amount by the amount of dues withheld. Use toString method which overrides base class method. (uses base class method to get string with employee info and then adds line with dues info)

2) Commission Employee inherits from Employee class. This class contains a commission rate and sales amount variable which is used as part of the pay calculation. Explicit value constructor should set both values of base class along with commission rate variable. Use mutator method for commission rate + sales amount. Base class weekly pay must be overridden(because commission employee gets base employee pay + commission rate times sales amount.) Add toString method (overrides base class method) uses base class method to get employee info string, and adds two lines with commission rate and sales amount info.

Test program - Create Union Employee and Commission object. Must contain separate display function which takes base class Employee object reference parameter and number of hours worked. Display functions prints object with toString. Display function gets weekly pay info for object and displays that info. Test program should pass the Union Employee Object and Commission Employee object to display methods along with number hours each employee worked. It should test payroll calculation for number of hours worked less than and greater than 40 hours for each employee time. Output seen should demonstrate polymorphic behavior. (meaning the base class Employee reference to a Union Employee object elicits Union Employee pay calculations, and the base class Employee reference to a Commission Employee elicits Commission Employee payroll calculations)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!