Commit 1e82dadf authored by sam.drinkwater's avatar sam.drinkwater

main

parent de95c2bd
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -29,25 +29,48 @@ public class Complex { ...@@ -29,25 +29,48 @@ public class Complex {
public double magnitude() public double magnitude()
{ {
return 1.0; double answer = Math.sqrt((real*real)+(imag*imag));
return answer;
} }
public double argument() public double argument()
{ {
return 1.0; double d = Math.atan2(imag,real);
return d;
} }
public String toString() public String toString()
{ {
if (imag > 0 && real > 0){
String positive = real+ " + j"+imag;
return positive;
}
else if (imag == 0.0){
String no_imag = real+"";
return no_imag;
}
else if (imag > 0 && real == 0.0){
String no_real = "j"+imag;
return no_real;
}
else if (imag < 0 && real > 0){
String str = imag+"";
String strNew = str.replace("-", "");
String negative = real+ " - j"+strNew;
return negative;
}
return ""; return "";
} }
public Complex add(Complex complexNum) public Complex add(Complex complexNum){
{ Complex res = new Complex(0, 0);
Complex answer = new Complex(0.0,0.0); Complex a = new Complex(real,imag);
res.real = complexNum.real + a.real;
return answer; res.imag = complexNum.imag + a.imag;
return res;
} }
} }
\ No newline at end of file
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