Payroll Program with Polymorphism
Description
This program incorporates the OOP inheritance concept to design classes to represent different types of employees.The client program incorporates the OOP Polymorphism concept to process a variety of subclass objects.
The superclass Employee defines the common features that apply to any types of employees.
Data members: employee id, first and last names
constructors
getters and setters
earnings method
(It is up to the subclasses how to implement it.)
toString method
constructors
getters and setters
earnings method
(It is up to the subclasses how to implement it.)
toString method
The subclasses SalariedEmployee, HourlyEmployee, and CommissionEmployee inherit the superclass Employee's features and add additional features.
The subclass BasePlusCommissionEmployee inherits the superclass CommissionEmployee's features and adds additional features.
SalariedEmployee: fixed salary
HourlyEmployee: hours worked, and base wage
CommissionEmployee: sales and commission rate
BasePlusCommissionEmployee: base salary
HourlyEmployee: hours worked, and base wage
CommissionEmployee: sales and commission rate
BasePlusCommissionEmployee: base salary
All subclasses override the superclass' earnings method.
Basically, the Employee's earnings method simply returns 0. It is up to the subclasses how to implement it.
Associated Concepts:
OOP - Inheritance
Algorithm:
Class diagrams:
Client program:
Client program:
The client program creates an ArrayList of superclass Employee
and adds subclass objects to the ArrayList in random order.
It then invokes the earnings() method in the loop using the superclass references.
As we know, the actual subclass object's earnings() method is executed.
It then invokes the earnings() method in the loop using the superclass references.
As we know, the actual subclass object's earnings() method is executed.
Source Code
Superclass Employee classSubclass CommissionEmployee class
subclass BasePlusCommissionEmployee class
Client program
***Note: SalariedEmployee and HourlyEmployee source code were not implemented.
So the default constructors were used to create the objects of these two types.