// Assume that the following classes where written by two different programers // with different purposes in mind // Some dork wrote the following class. // Objects representing rational numbers (fractions) class rational { public int n; // numerator // private sucks! public int d; // denominator public rational(int a, int b) {n=a; d=b;} // constructor public rational mult(rational B) // non-destructive times { return new rational(n*B.n,d*B.d); } public rational add(rational B) // non-destructive addition { return new rational(n*B.d+B.n*d, d*B.d); } public boolean equals(rational B) { return n*B.d == d*B.n; } public String toString() // override Object.toString for printing { return n + "/" + d; } }// rational class // Some bozo wrote the following class: // Objects representing complex numbers. A complex number a + bi has // a real part (a) and an imaginary part (b). So it consists of two // floating point numbers class complex { private double rp; // real part. All instance vars must be PRIVATE! private double ip; // imaginary part public complex(double a, double b) {rp=a; ip=b;} public boolean equals(complex B) { return rp==B.rp && ip==B.ip; } public complex add(complex B) { return new complex(rp+B.rp, ip+B.ip); } public complex times(complex B) // darn it, he didn't call it 'mult' { return new complex(rp*B.rp - ip*B.ip, ip*B.rp+rp*B.ip); } public String makestring() // ha ha! this guy don't know about toString { return rp + "+" + ip + "i"; } }// complex numbers class public class numbersaop { public static void main(String[] argv) { rational half = new rational(1,2); rational quarter = new rational(1,4); complex a = new complex(2,1); // 2+i complex b = new complex(4,3); // 4+3i System.out.println(half.add(quarter)); System.out.println(a.times(b).makestring()); } }//numbersaop