Commit 7da1e6b1 authored by cosmina.dunca's avatar cosmina.dunca

tasksDone

parent bf380f35
...@@ -12,40 +12,61 @@ public class Complex { ...@@ -12,40 +12,61 @@ public class Complex {
public Complex(double r, double i) public Complex(double r, double i)
{ {
real = r; this.real = r;
imag = i; this.imag = i;
double d = Math.atan2(i,r); double d = Math.atan2(i,r);
} }
public double imag() public double imag1()
{ {
return imag; return this.imag;
} }
public double real() public double real1()
{ {
return real; return this.real;
} }
public double magnitude() public double magnitude()
{ {
return 1.0; return Math.sqrt(Math.pow(this.real, 2) + Math.pow(imag, 2));
} }
public double argument() public double argument()
{ {
return 1.0; return Math.atan2(this.imag, this.real);
} }
public String toString() public String toString()
{ {
return ""; if(this.imag < 0)
{
if(this.real != 0) {
return this.real + " - j" + this.imag * (-1);
}
else {
return "- j" + this.imag * (-1);
}
} else if (this.imag > 0)
{
if (this.real != 0) {
return this.real + " + j" + this.imag;
}
else {
return "j" + this.imag;
}
} else {
return this.real + "";
}
} }
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 = complexNum.real + this.real;
answer.imag = complexNum.imag + this.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