Commit c0c4f587 authored by Henry Ewen's avatar Henry Ewen

Finished

parent 792fd555
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -30,7 +30,6 @@ public class AppTest { ...@@ -30,7 +30,6 @@ public class AppTest {
assertEquals(0.87520335, a.argument(), 1e-6); assertEquals(0.87520335, a.argument(), 1e-6);
} }
@Test @Test
public void testToString() { public void testToString() {
/* toString() should return a string like 1.2 + j3.4 where 1.2 is the real part /* toString() should return a string like 1.2 + j3.4 where 1.2 is the real part
...@@ -55,6 +54,4 @@ public class AppTest { ...@@ -55,6 +54,4 @@ public class AppTest {
assertEquals(19.7, c.real(), 1e-6); assertEquals(19.7, c.real(), 1e-6);
assertEquals(26.4, c.imag(), 1e-6); assertEquals(26.4, c.imag(), 1e-6);
} }
} }
...@@ -14,7 +14,6 @@ public class Complex { ...@@ -14,7 +14,6 @@ public class Complex {
{ {
real = r; real = r;
imag = i; imag = i;
double d = Math.atan2(i,r);
} }
public double imag() public double imag()
...@@ -29,24 +28,42 @@ public class Complex { ...@@ -29,24 +28,42 @@ 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 imagine_string = Double.toString(imag);
String real_string = Double.toString(real);
if (real!=0) {
if (imag!=0) {
if (imag<0) {
String imagine_string2 = imagine_string.replace("-","");
return real_string+" - "+"j"+imagine_string2;
}
return real_string+" + "+"j"+imagine_string;
}
else {
return real_string;
}
}
else {
return "j"+imagine_string;
}
} }
public Complex add(Complex complexNum) public Complex add(Complex complexNum)
{ {
Complex answer = new Complex(0.0,0.0); Complex ans = new Complex(0.0,0.0);
ans.real = complexNum.real + real;
return answer; ans.imag = complexNum.imag + imag;
return ans;
} }
......
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