174 Chapter 10: Polymorphism
Another Type of Employee
The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java, Executive.java, and
Hourly.java are from Listings 9.1 – 9.7 in the text. The program illustrates inheritance and polymorphism.
In this exercise you will add one more employee type to the class hierarchy (see Figure 9.1 in the text).
The employee will be one that is an hourly employee but also earns a commission on sales. Hence the class,
which we’ll name Commission, will be derived from the Hourly class.
Write a class named Commission with the following features:
It extends the Hourly class.
It has two instance variables (in addition to those inherited): one is the total sales the employee has made
(type double) and the second is the commission rate for the employee (the commission rate will be type
double and will represent the percent (in decimal form) commission the employee earns on sales (so .2
would mean the employee earns 20% commission on sales)).
The constructor takes 6 parameters: the first 5 are the same as for Hourly (name, address, phone number,
social security number, hourly pay rate) and the 6th is the commission rate for the employee. The
constructor should call the constructor of the parent class with the first 5 parameters then use the 6th to set
the commission rate.
To test your class, update Staff.java as follows:
Increase the size of the array to 8.
Add two commissioned employees to the staffList—make up your own names, addresses, phone numbers
Compile and run the program. Make sure it is working properly.
//*****************************************************************
// Firm.java Author: Lewis/Loftus
public class Firm
{
//————————————————————–
personnel.payday();
}
}