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
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:
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
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 CodeFractionClient.java Source Code