/** * Author: Josiah Yoder et al. * Class: SE1011-011 * Date: 10/21/13 1:20 AM * Lesson: Week 7, Day 1 */ public class Complex011_8_2 { private double real; private double imaginary; public static final double MY_CONSTANT = 5.0; public Complex011_8_2() { real = 0; imaginary = 0; } public Complex011_8_2(double real, double imaginary) { this.real = real; this.imaginary = imaginary; } public Complex011_8_2 add(Complex011_8_2 other) { Complex011_8_2 result = new Complex011_8_2(); result.real = this.real + other.real; result.imaginary = this.imaginary + other.imaginary; return result; } /* * Arithmetic inverse (aka -c) */ public Complex011_8_2 inverse() { Complex011_8_2 result = new Complex011_8_2(); result.real = -this.real; result.imaginary = -this.imaginary; return result; } /* * Subtract the other from this * this - other */ public Complex011_8_2 subtract(Complex011_8_2 other) { // Complex011_8_2 result = new Complex011_8_2(); // unused object 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; } }