Commit d57866f0 authored by elliot.copeland's avatar elliot.copeland

Exercise Completed

parent de95c2bd
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -57,12 +57,12 @@ Looking at the tests in AppTest.java might help you see how these methods will b
`toString()` should return a string in the format `a + jb` where `a` is the real component and `b` is the imaginary component. Note the rules below should be followed.
|Real Part|Imaginary Part|String|
|---|---|---|
|`2.6`|`5.2`|`2.6 + j5.6`|
|`2.6`|`0`|`2.6`|
|`0`|`5.2`|`j5.2`|
|`2.6`|`-9.8`|`2.6 - j9.8`|
|Real Part|Imaginary Part|String |
|--- |--- | --- |
|`2.6` |`5.2` |`2.6 + j5.6`|
|`2.6` |`0` |`2.6` |
|`0` |`5.2` |`j5.2` |
|`2.6` |`-9.8` |`2.6 - j9.8`|
If the real or imaginary part is 0 it should not be shown. If the imaginary part is negative the negative symbol should be before the j not the number (i.e. `4.3 - j2.1` not `4.3 + j-2.1`).
......
public class App {
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
}
}
......@@ -29,23 +29,50 @@ public class Complex {
public double magnitude()
{
return 1.0;
return Math.sqrt(Math.pow(real, 2) + Math.pow(imag, 2));
}
public double argument()
{
return 1.0;
return Math.atan2(imag, real);
}
public String toString()
{
return "";
String temp = "";
if (real != 0) {
temp = Double.toString(real);
}
if (imag != 0) {
if (imag < 0) {
if (real != 0) {
temp = temp + " - j" + Double.toString(imag * -1);
}
else {
temp = "j" + Double.toString(imag);
}
}
else {
if (real != 0) {
temp = temp + " + j" + Double.toString(imag);
}
else {
temp = "j" + Double.toString(imag);
}
}
}
return temp;
}
public Complex add(Complex complexNum)
{
Complex answer = new Complex(0.0,0.0);
answer.real = real + complexNum.real;
answer.imag = imag + complexNum.imag;
return answer;
}
......
......@@ -57,12 +57,12 @@ Looking at the tests in AppTest.java might help you see how these methods will b
`toString()` should return a string in the format `a + jb` where `a` is the real component and `b` is the imaginary component. Note the rules below should be followed.
|Real Part|Imaginary Part|String|
|---|---|---|
|`2.6`|`5.2`|`2.6 + j5.6`|
|`2.6`|`0`|`2.6`|
|`0`|`5.2`|`j5.2`|
|`2.6`|`-9.8`|`2.6 - j9.8`|
|Real Part|Imaginary Part|String |
|--- |--- | --- |
|`2.6` |`5.2` |`2.6 + j5.6`|
|`2.6` |`0` |`2.6` |
|`0` |`5.2` |`j5.2` |
|`2.6` |`-9.8` |`2.6 - j9.8`|
If the real or imaginary part is 0 it should not be shown. If the imaginary part is negative the negative symbol should be before the j not the number (i.e. `4.3 - j2.1` not `4.3 + j-2.1`).
......
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