COMP2243 - Programming and Problem Solving

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

OOP - Encapsulation Right Triangle OOP Program
RightTriangleClass.java
RightTriangleClient.java

Loan OOP Program
Loan.java
LoanCompany.java

Payroll OOP Program
PayrollClass.java
PayrollDepartment.java

Delivery OOP Program
PackageClass.java
DeliveryCompany.java

Fraction OOP Program
Fraction.java
FractionClient.java




Payroll OOP Program


Description

We studied Payroll program in previous sections.

In this section, we write an OOP program that uses the PayrollClass object to calculate the weekly pay.

The ADT (abstract data type) is PayrollClass.java.

The client program is PayrollDepartment.java.

Associated Concepts:

Object Oriented Programming (OOP)

Data member: instance variable

Instance method

Constructor

Getter and getter

toString method

Algorithm:

For PayrollClass, the class diagram is represented in UML (Unified Modeling Language) notation.



Client program:

Create the PayrollClass object p1 using the overloaded constructor with the user input data

Use the object reference p1 to call the method to calculate the weekly pay

Print the object p1's information

Create the PayrollClass object p2 using the default constructor

Set p2's data members with hard-coded values

Use the object reference p2 to call the method to calculate the weekly pay

Print the object p2's information

Double p1's hourly wage

Compare the weekly pays of two objects

Source Code

PayrollClass.java Source Code



PayrollDepartment.java Source Code



Sample Run



Video