Commit fb5043b0 authored by jinny.wilkin's avatar jinny.wilkin

assessment upload

parent de95c2bd
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
......@@ -14,7 +14,7 @@ public class Complex {
{
real = r;
imag = i;
double d = Math.atan2(i,r);
//double d = Math.atan2(i,r);
}
public double imag()
......@@ -29,23 +29,44 @@ 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 result;
String realStr = "";
String imagStr = "";
if(real != 0){
realStr = Double.toString(real);
}
if(imag != 0){
imagStr = imag>0?" + j"+imag:" - j"+(-imag);
}
if((real != 0) && (imag == 0)){
result = realStr;
}else if ((real == 0)&& (imag != 0)){
result = imagStr.substring(3);
}else{
result = realStr + imagStr;
}
return result;
}
public Complex add(Complex complexNum)
{
double realAdd = real + complexNum.real;
double imagAdd = imag + complexNum.imag;
Complex answer = new Complex(0.0,0.0);
answer.real = realAdd;
answer.imag = imagAdd;
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