/** * Author: Josiah Yoder et al. * Class: SE1011-011 * Date: 10/21/13 1:20 AM * Lesson: Week 7, Day 1 */ public class Complex { private double real; private double imaginary; public Complex() { real = 0; imaginary = 0; } public Complex(double real, double imaginary) { this.real = real; this.imaginary = imaginary; } public Complex add(Complex other) { Complex result = new Complex(); result.real = this.real + other.real; result.imaginary = this.imaginary + other.imaginary; return result; } /* * Arithmetic inverse (aka -c) */ public Complex inverse() { Complex result = new Complex(); result.real = -this.real; result.imaginary = -this.imaginary; return result; } /* * Subtract the other from this * this - other */ public Complex subtract(Complex other) { Complex result = new Complex(); return this.add(other.inverse()); // return add(other.inverse()); // alternative. Not as clear in this case. } /* * Add an imaginary number to the complex number * * imagineN -- "b" in the expression b*i that represents the imaginary number */ public void addImaginary(double imagineN) { // need a & b // What do we have? // this.real; // this.imaginary; imaginary = imagineN + imaginary; } }