/* * Complex.java * a complex number class * * Name: * * Comments to the graders: */ class Complex { private double real; private double imag; // place your constructors here: // *** Please use this toString method for consistency! *** // method: toString // in: no inputs // out: the String version of this Complex object public String toString() { String sign = "+"; // default sign is plus if (this.imag < 0.0) sign = "-"; // if imag is negative, make it a minus return "" + this.real + " " + sign + " " + Math.abs( this.imag ) + "i"; } // place your other methods here: // main: the starting point for our testing code // in: command-line arguments // out: nothing (it's void) public static void main(String[] args) { // a welcoming statement... System.out.println("Welcome to the Complex..."); // feel free to uncomment these lines of code // to test as you go! /* Complex c0 = new Complex( 0.0, 0.0 ); System.out.println("c0 should be 0.0 + 0.0i"); System.out.println("c0 is " + c0); Complex c1 = new Complex( 42.0, -60.0 ); System.out.println("c1 should be 42.0 - 60.0i"); System.out.println("c1 is " + c1); */ // you'll want to write more tests so that you // know your other functions are working... // Do not worry about the small floating-point // differences that necessarily arise when using // arithmetic on real hardware. // For instance, 2.4999999999999 is OK for 2.5 // a departing statement... System.out.println("where the Complex isn't!"); } }