/** * Author: Josiah Yoder et al. * Class: SE1011-011 * Date: 10/21/13 1:20 AM * Lesson: Week 7, Day 1 */ public class Complex011_10_1 { private double real; private double imaginary; public static final double MY_CONSTANT = 5.0; public static int numberOfInstances = 0; public Complex011_10_1() { real = 0; imaginary = 0; numberOfInstances = numberOfInstances + 1; } public Complex011_10_1(double real, double imaginary) { this.real = real; this.imaginary = imaginary; } public Complex011_10_1(double real) { // System.out.println("the double one"); this(real, 0); } public Complex011_10_1(long real) { this(real, 0); // System.out.println("the long one"); } public Complex011_10_1(Complex011_10_1 other) { this(other.real, other.imaginary); } public Complex011_10_1 add(Complex011_10_1 other) { Complex011_10_1 result = new Complex011_10_1(); result.real = this.real + other.real; result.imaginary = this.imaginary + other.imaginary; return result; } public Complex011_10_1 add(double real) { return add(new Complex011_10_1(real,0)); // Complex011_10_1 result = new Complex011_10_1(); // result.real = this.real + real; // result.imaginary = this.imaginary; // return result; } /* * Arithmetic inverse (aka -c) */ public Complex011_10_1 inverse() { Complex011_10_1 result = new Complex011_10_1(); result.real = -this.real; result.imaginary = -this.imaginary; return result; } /* * Subtract the other from this * this - other */ public Complex011_10_1 subtract(Complex011_10_1 other) { // Complex011_10_1 result = new Complex011_10_1(); // 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 incrementReal(double realN) { real = realN + real; } /* * Add an imaginary number to the complex number * imagineN -- "b" in the expression b*i that represents the imaginary number */ public void incrementImaginary(double imagineN) { // need a & b // What do we have? // this.real; // this.imaginary; imaginary = imagineN + imaginary; } // Return to Chapter 7 public void swap(Complex011_10_1 other) { // other.real; // this.real; double temp; temp = other.real; other.real = this.real; this.real = temp; temp = other.imaginary; other.imaginary = this.imaginary; this.imaginary = temp; // Assign a to b // b = a; // Assign a to be b // a = b; } public String toString() { return "("+real+", "+imaginary+")"; } public Complex011_10_1 incrementALot(Complex011_10_1[] others) { // TODO: return null; } public double getReal(){ return real; } }