Payroll Program with Abstract
Description
This program incorporates OOP inheritance, polymorphism, and abstract method/class concepts to design classes to represent different types of employees.The abstract superclass Employee defines the common features that apply to any types of employees.
Method earnings() is an abstract method.
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 concrete subclasses override the superclass' earnings method.
Basically, the Employee's earnings method simply returns 0. It is up to the concrete subclasses how to implement it.
Associated Concepts:
OOP - Inheritance
OOP - Polymorphism
OOP - Abstract Method / Class
OOP - Polymorphism
OOP - Abstract Method / Class
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.