Question: Lab 2: Another Employee Type 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

Lab 2: Another Employee Type

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 two more employee type to the class hierarchy (see Figure 9.1 in the text). One of the new employee types will be an intern, but earns a commission on sales. Hence the class, which we'll name CommissionIntern, will be derived from the Volunteer class. The second employee type will also be an intern but is not paid.

--Write a class named Commission with the following features:

It extends the Volunteer class.

It has one instance variable (in addition to those inherited - 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 4 parameters: the first 3 are the same as for Volunteer (name, address, phone number) and the 4th is the commission rate for the employee. The constructor should call the constructor of the parent class with the first 3 parameters then use the 4th to set the commission rate.

One additional method is needed: public void addSales (double totalSales) that adds the parameter to the instance variable representing total sales.

The pay method must call the pay method of the parent class to compute the pay from commission on sales. (See the pay method in the Executive class.) The total sales should be set back to 0.

The toString method needs to call the toString method of the parent class then add the total sales to that.

--Write a second class named FreeIntern using the same ideas as above, but be sure that it fits the scenario.

To test your classes, update Staff.java as follows:

Increase the size of the array to 10.

Add two interns to the staffListmake up your own names, addresses, and phone numbers. Have one of the employees earn a 10% commission and the other one earn a15% commission.

For the first additional employee you added, put the total sales $150; for the second, put the sales at $95.

Add two non-paid interns to the staffList

Be sure that you test your program, and that you have adequate output that shows that your code is working.

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!