Week 3 Assignment
Create a new Java Project in Eclipse named HW3 and complete the following two parts.
Part 2 – Inheritance
Create a package named hw3.part2. Using this package, create the following classes and implement the specified functionality.
Create a class named Employee as follows.
The instance (or member) private variables – name (String) and wageRate (integer). The wageRate denotes the weekly wages (@40 hours/week) for this employee.
A single constructor with two arguments, the name and the wage rate. Set the instance variables with the specified argument values.
The public set and get methods for the two instance variables.
A public computePayStub method which takes a double argument, named hours, and returns a double showing the weekly wages for this employee. The employee is only paid for a maximum of 40 hours for the week based on the weekly wageRate. If this employee worked less than 40 hours, the wages are prorated accordingly.
Override the toString method to return the string representation of this object in the format “Employee:<name of this employee>@$<wageRate>/week”.
No instance variables are allowed in the Consultant class.
A single constructor with two arguments, the name and the wage rate. The wage rate represents the hourly rate of this consultant.
Override the computePayStub method which takes a double argument, named hours, and returns a double showing the weekly wages for this consultant. The consultant is paid for the week based on the hourly wageRate for the first 40 hours. If this consultant worked more than 40 hours, the excess hours are paid at 1.5 times the hourly rate. However, a maximum of 10 overtime hours is allowed for the pay period.
Override the toString method to return the string representation of this object in the format “Consultant:<name of this consultant>@$<wageRate>/hour”.
Create a derived class from the Employee class named Consultant.
Create a Test class to test the following functionality in its main method.
Declare a variable named currentEmployee of type Employee.
Create an Employee object with name Alice and the weekly wage rate 1000 and assign it to the above variable.
Print to the console the string representation of this object.
Using any of the loop constructs, iterate over the computePayStub of this object with the hours 10, 20, 30, 40, 50, and 60. Display the wages as shown in the sample below.
Create a Consultant object with name Bob and the hourly wage rate 100. Reassign the currentEmployee to this object.
Repeat the steps shown in c) and d) for this object.
The sample output is shown below.
My tutorial contains Java Programs - Eclipse Project and Document.
If you have more questions, please contact me via email email@example.com
I will help you any time
Thank you !