Methods Summary |
---|
public static ComplexNumber | add(ComplexNumber a, ComplexNumber b)This is a static class method. It takes two complex numbers, adds them,
and returns the result as a third number. Because it is static, there is
no "current instance" or "this" object. Use it like this:
ComplexNumber c = ComplexNumber.add(a, b);
return new ComplexNumber(a.x + b.x, a.y + b.y);
|
public ComplexNumber | add(ComplexNumber a)This is a non-static instance method by the same name. It adds the
specified complex number to the current complex number. Use it like this:
ComplexNumber c = a.add(b);
return new ComplexNumber(this.x + a.x, this.y+a.y);
|
public double | imaginary()An accessor method. Returns the imaginary part of the complex number return y;
|
public double | magnitude()Compute the magnitude of a complex number return Math.sqrt(x*x + y*y);
|
public static ComplexNumber | multiply(ComplexNumber a, ComplexNumber b)A static class method to multiply complex numbers
return new ComplexNumber(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x);
|
public ComplexNumber | multiply(ComplexNumber a)An instance method to multiply complex numbers
return new ComplexNumber(x*a.x - y*a.y, x*a.y + y*a.x);
|
public double | real()An accessor method. Returns the real part of the complex number.
Note that there is no setReal() method to set the real part. This means
that the ComplexNumber class is "immutable". return x;
|
public java.lang.String | toString()This method converts a ComplexNumber to a string. This is a method of
Object that we override so that complex numbers can be meaningfully
converted to strings, and so they can conveniently be printed out with
System.out.println() and related methods return "{" + x + "," + y + "}";
|