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




Delivery OOP Program


Description

This is an OOP program that uses PackageClass object to calculate the delivery cost for a shipping company.

Each package object has three instance data members: package id, weight (in ounces) and cost per ounce to ship the package.

The PackageClass also has a static data member that represents a flat fee that the shipping company charges for each package.

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

The client program is DeliveryCompany.java.

Associated Concepts:

Object Oriented Programming (OOP)

Data member: instance variable

Data member: static variable

Instance method and static method

Reserved keyword: this

Constructor

Getter and getter

toString method

Algorithm:

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



Client program:

Call static method to set the static data member

Create the PackageClass object with hard-coded values

Use the object reference p1 to call the method to calculate the delivery cost

Print the object's information

Source Code

PackageClass.java Source Code



DeliveryCompany.java Source Code



Sample Run




Refer to the video in IDE page on how to use NetBeans

Video