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




Fraction OOP Program


Description

Rational fractions are in the form of numerator / denominator, where numerator and denominator are both integers, and denominator is not 0.

Write an OOP program that can add, subtract, multiply, or divide two Fraction objects.

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

The client program is FractionClient.java.

Associated Concepts:

Object Oriented Programming (OOP)

Data member: instance variable

Instance method

Constructor

Getter and getter

toString method

Shallow copy vs. deep copy

equals method

Algorithm:

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



Client program:

Create two Fraction objects

Use the instance methods defined in Fraction class to add two Fraction objects

Make shallow copy of Fraction object

Make deep copy of Fraction object using copy method

Make deep copy of Fraction object using copy constructor

Use equals method to compare two Fraction object

Source Code

Fraction.java Source Code



FractionClient.java Source Code



Sample Run



Video