public class ComplexCalc { public static void main(String[] args) { Complex c1 = new Complex(); Complex c2 = new Complex(1,3); Complex c3 = c1.add(c2); System.out.println(c2.add(c1)); System.out.println(Complex.add(c1,c3)); // Can you do this? // c1.real = 4; } } class Complex { private double real; // real component private double imag; // imaginary component public Complex() { } public Complex(double r, double i) { real = r; imag = i; } // Add two complex numbers together (one approach): public Complex add(Complex other) { return new Complex(real+other.real, imag+other.imag); } // Alternative approach: public static Complex add(Complex c1, Complex c2) { return new Complex(c1.real+c2.real,c2.real+c2.imag); } // Stringify complex number: public String toString() { return real+"+"+imag+"i"; // what if imag is neg? } }