Commit ea6107b0 authored by Suleman Hussain's avatar Suleman Hussain

finished

parent 53835ebe
No preview for this file type
...@@ -29,23 +29,41 @@ public class Complex { ...@@ -29,23 +29,41 @@ public class Complex {
public double magnitude() public double magnitude()
{ {
return 1.0; return Math.sqrt(Math.pow(real,2)+(Math.pow(imag,2)));
} }
public double argument() public double argument()
{ {
return 1.0; return Math.atan(imag/real);
} }
public String toString() public String toString()
{ {
return ""; String imag_string = Double.toString(imag);
String real_string = Double.toString(real);
if (real!=0) {
if (imag!=0) {
if (imag<0) {
String imag_string_ = imag_string.replace("-","");
return real_string+" - "+"j"+imag_string_;
}
return real_string+" + "+"j"+imag_string;
}
else {
return real_string;
}
}
else {
return "j"+imag_string;
}
} }
public Complex add(Complex complexNum) public Complex add(Complex complexNum)
{ {
Complex answer = new Complex(0.0,0.0); Complex answer = new Complex(0.0,0.0);
answer.real = complexNum.real + real;
answer.imag = complexNum.imag + imag;
return answer; return answer;
} }
......
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