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