Commit 9a4077c0 authored by lui.bingham's avatar lui.bingham

Exercise 1

parent de95c2bd
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -29,22 +29,37 @@ public class Complex { ...@@ -29,22 +29,37 @@ public class Complex {
public double magnitude() public double magnitude()
{ {
return 1.0; return Math.sqrt(real * real + imag * imag);
} }
public double argument() public double argument()
{ {
return 1.0; return Math.atan2(imag, real);
} }
public String toString() public String toString()
{ {
return ""; if (real == 0.0)
{
return "j" + imag;
}
if (imag == 0.0)
{
return real + "";
}
if (imag < 0.0)
{
return real + " - j" + imag *-1;
}
else
{
return real + " + j" + imag;
}
} }
public Complex add(Complex complexNum) public Complex add(Complex complexNum)
{ {
Complex answer = new Complex(0.0,0.0); Complex answer = new Complex((real + complexNum.real),(imag + complexNum.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