// Written in ENGR 131, 11/08/07 public class Complex { private double realPart, imagPart; public Complex(double a, double b) { realPart = a; imagPart = b; } public Complex() { realPart = 0.0; imagPart = 0.0; } public void print() { System.out.printf("( %f, %f)\n", realPart, imagPart); } // class method public static Complex add(Complex c1, Complex c2) { Complex c3 = new Complex(); c3.realPart = c1.realPart + c2.realPart; c3.imagPart = c1.imagPart + c2.imagPart; return c3; } // instance method public Complex add(Complex that) { Complex ans = new Complex(); // System.out.print("1st arg: "); // this.print(); // System.out.print("2nd arg: "); // that.print(); ans.realPart = this.realPart + that.realPart; ans.imagPart = this.imagPart + that.imagPart; // System.out.print("answer : "); // ans.print(); return ans; } // class method public static Complex subtract(Complex c1, Complex c2) { Complex c3 = new Complex(); c3.realPart = c1.realPart - c2.realPart; c3.imagPart = c1.imagPart - c2.imagPart; return c3; } // instance method public Complex subtract(Complex that) { Complex ans = new Complex(); // System.out.print("1st arg: "); // this.print(); // System.out.print("2nd arg: "); // that.print(); ans.realPart = this.realPart - that.realPart; ans.imagPart = this.imagPart - that.imagPart; // System.out.print("answer : "); // ans.print(); return ans; } }