Lab 08

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Computer Engineering Department

Lab Assignment 08
2020 – 2021 Spring, CMPE 211 Fundamentals of Programming II

ANOTHER TYPE OF EMPLOYEE

The files Firm.java, Staff.java, StaffMember.java, Volunteer.java, Employee.java,


Executive.java, and Hourly.java are already available on Moodle and illustrate inheritance and
polymorphism. In this lab, you will add one more employee type to the class hierarchy which is to be seen
from Figure 1.

Figure 1. A class hiearchy of employees


The employee will be one that is an hourly employee but also deducts a discount on sales. Hence the class,
which we’ll name Discounter, will be derived from the Hourly class. You are asked to do the following
tasks:

1
Computer Engineering Department

Task 1 (80 points)

Write a class named Discounter 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 discount rate for the employee (the discount rate will be
type double and will represent the percent (in decimal form) discount the employee applies on
sales (so .2 would mean the employee applies 20% discount 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 discount 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 discount 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 for hours
worked then subtracts to that the pay from discount on sales. (See the pay method in the
Executive class.) The total sales should be set back to 0 (note: you don’t need to set the hours
Worked back to 0—why not?).

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

Task 2 (20 points)

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


a. Increase the size of the array to 8.
b. Add two discounter employees to the staffList—make up your own names, addresses, phone
numbers and social security numbers. Have one of the employees earn $7.25 per hour and 10%
discount and the other one earn $10.75 per hour and 5% discount.
c. For the first additional employee you added, put the hours worked at 25 and the total sales $500; for
the second, put the hours at 50 and the sales at $1250.
Compile Firm.java and run the program. Make sure it is working properly. You can see expected program
run (demo) from the link below:
https://asciinema.org/a/z2U9pKjMGGo3EDWPiniquwFsH

Submission

You need to implement all the required tasks above and upload your Java source files (.java) as a single Zip
file into the available Moodle submission.

You might also like