Commit 31daeb36 authored by sam.pople's avatar sam.pople

worked again

parent 22a525a6
public class Complex { public class Complex {
public double real; public double real;
public double image; public double imag;
public Complex() public Complex()
{ {
real = 0; real = 0;
image = 0; imag = 0;
} }
public Complex(double r, double i) public Complex(double r, double i)
{ {
real = r; real = r;
image = i; imag = i;
} }
public double imag() public double imag()
{ {
return image; return imag;
} }
public double real() public double real()
...@@ -35,30 +36,25 @@ public class Complex { ...@@ -35,30 +36,25 @@ public class Complex {
{ {
return Math.atan2(this.imag(),this.real()); return Math.atan2(this.imag(),this.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.image > 0) { if (this.imag > 0) {
str = str + " + "; str = str + " + ";
} }
if (this.image < 0) { if (this.imag < 0) {
str = str + " - "; str = str + " - ";
} }
} }
if (this.imag != 0) {
if (this.image != 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 complex)
{ {
Complex answervalue = new Complex(this.real() + complex.real(),this.imag() + complex.imag()); Complex answervalue = new Complex(this.real() + complex.real(),this.imag() + complex.imag());
......
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