Commit 83b250af authored by sam.pople's avatar sam.pople

Final finish

parent d0b44f50
...@@ -8,57 +8,49 @@ public class Complex { ...@@ -8,57 +8,49 @@ public class Complex {
real = 0; real = 0;
imag = 0; imag = 0;
} }
public Complex(double r, double i) public Complex(double r, double i)
{ {
real = r; real = r;
imag = i; imag = i;
} }
public double imag() public double imag()
{ {
return imag; return imag;
} }
public double real() public double real()
{ {
return real; return real;
} }
public double magnitude() public double magnitude()
{ {
return Math.sqrt(this.real() * this.real() + this.imag() * this.imag()); return Math.sqrt(Math.pow(real, 2) + Math.pow(imag, 2));
} }
public double argument() public double argument()
{ {
return Math.atan2(this.imag(),this.real()); return Math.atan2(imag, real);
} }
public String toString() public String toString()
{ {
String str = ""; String str = "";
if (this.real() != 0) { if (this.real() != 0) {
str = str + this.real(); str = str + this.real();
if (this.imag > 0) {
str = str + " + ";
}
if (this.imag < 0) { if (this.imag < 0) {
str = str + " - "; str = str + " - ";
} }
if (this.imag > 0) {
str = str + " + ";
}
} }
if (this.imag != 0) { if (this.imag != 0) {
str = str + "j" + Math.abs(this.imag()); str = str + "j" + Math.abs(this.imag());
} }
return str; return str;
} }
public Complex add(Complex complex) public Complex add(Complex complexNum)
{ {
Complex answervalue = new Complex(this.real() + complex.real(),this.imag() + complex.imag()); Complex value = new Complex(this.real() + complexNum.real(),this.imag() + complexNum.imag());
return answervalue; return value;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment