/* There's something funny about this program (not that there are any errors), which concerns the nature of OOP in C++/Java/C#. In particular, pay attention to the usage of "public" and "private". Don't take everything about these languages for granted! Think about possible alternatives. */ class fraction { private int numerator; private int denominator; private int gcd(int a, int b) { if (a==0) return b; else return gcd(b%a,a); } // euclid's alg public fraction(int n, int d) // constructor { if (d==0) d = 1; int cd = gcd(n,d); // common divisor numerator = n/cd; denominator = d/cd; } // check if one fraction is equal to another fraction: boolean equals(fraction f) { return numerator*f.denominator == denominator*f.numerator; } // multiply fractions fraction mult(fraction f) { return new fraction(numerator*f.numerator,denominator*f.denominator); } }; // end of class fraction public class rrr { public static void main(String[] args) { fraction f1, f2, f3; f1 = new fraction(1,3); f2 = new fraction(2,5); f3 = f1.mult(f2); if (f3.equals(new fraction(2,15))) System.out.print("nice program!\n"); } }