Commit 0c3f9b1b authored by thomas.fuller's avatar thomas.fuller

finished

parent de95c2bd
File added
public class App { public class App {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
System.out.println("Hello, World!"); Complex a = new Complex(6.6, 12.9);
Complex b = new Complex(13.1, 13.5);
System.out.println(a.magnitude());
System.out.println(b.argument());
Complex c = a.add(b);
System.out.println(c.toString());
} }
} }
...@@ -29,23 +29,28 @@ public class Complex { ...@@ -29,23 +29,28 @@ public class Complex {
public double magnitude() public double magnitude()
{ {
return 1.0; double x = this.real;
double y = this.imag;
return Math.hypot(x, y);
} }
public double argument() public double argument()
{ {
return 1.0; return Math.atan2(imag,real);
} }
public String toString() public String toString() {
{ if (imag == 0) return real + "";
return ""; if (real == 0) return "j"+imag ;
if (imag < 0) return real + " - " + "j"+(-imag);
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(0.0,0.0);
answer.real=this.real+complexNum.real;
answer.imag=this.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