public class Fraction { // instance variables private int numerator; private int denominator; // Constructor(s) public Fraction(int num, int denom) { numerator = num; denominator = denom; normalize(); } // Fraction() public Fraction(int num) { numerator = num; denominator = 1; } // Fraction() // Instance Methods public Fraction multiply(Fraction f) { int n = numerator * f.numerator; int d = denominator * f.denominator; return new Fraction(n, d); } // multiply() private void normalize() { int g = gcd(numerator, denominator); numerator = numerator / g; denominator = denominator / g; } // normalize() private int gcd(int a, int b) { while (a != b) { if (a > b) a = a - b; else b = b - a; } return a; } // gcd() // Print Methods public String toString() { return numerator + "/" + denominator; } // toString() // Test suite public static void main(String[] args) { Fraction f1 = new Fraction(22, 7); Fraction f2 = new Fraction(56, 24); Fraction f3 = new Fraction(6, 8); Fraction f4 = new Fraction(5); System.out.println("f2 = 56/24: " + f2); System.out.println("f3 = 6/8: " + f3); f1 = f2.multiply(f3); System.out.println("f1 = f2*f3: " + f1); } // main() } // Fraction