COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

OOP - Inheritance Pet Program
Pet.java
Cat.java
Dog.java
PetClient.java
Payroll Program
Employee.java
SalariedEmployee.java
HourlyEmployee.java
CommissionEmployee.java
BasePlusCommissionEmployee.java
PayrollClient.java
Class Roster Program
Student.java
UndergraduateStudent.java
GraduateStudent.java
ClassRosterClient.java




Payroll Program


Description

This program uses the OOP inheritance concept to design classes to represent different types of employees.



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

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

In addition, all subclasses override the superclass' earnings() method.

The Employee's earnings() method simply returns 0. It is up to the subclasses how to implement it.


This problem was originally presented as an example in C++ HOW TO PROGRAM (2nd Edition) book.
Authors: Deitel & Deitel
The requirements are revised to meet our purpose.


Associated Concepts:

OOP - Inheritance

Algorithm:

Class diagrams:



Client program:

The client program creates objects of different types of employee.

It then prints these objects and uses the object references to call earnings() method.

Source Code

Superclass Employee class



Subclass CommissionEmployee class



subclass BasePlusCommissionEmployee class



***Note: SalariedEmployee and HourlyEmployee source code were not provided.

Client program



Sample Run



Video