Commit fd790f99 authored by jose.alencastro's avatar jose.alencastro

ok

parent c094b452
No preview for this file type
public class Complex public class Complex
{ {
public double real; public double real;
public double imag; public double imag;
public Complex() public Complex()
{ {
real = 0; real = 0;
imag = 0; imag = 0;
} }
public Complex(double r, double i) public Complex(double r, double i)
{ {
real = r; real = r;
imag = i; imag = i;
double d = Math.atan2(i,r); double d = Math.atan2(i,r);
} }
public double imag() public double imag()
{ {
return imag; return imag;
} }
public double real() public double real()
{ {
return real; return real;
} }
public double magnitude() public double magnitude()
{ {
return 1.0; double magnitude = Math.sqrt(Math.pow(this.real, 2) + Math.pow(this.imag, 2));
return magnitude;
} }
public double argument() public double argument()
{ {
return 1.0; return Math.atan2(imag,real);
} }
public String toString() public String toString()
{ {
return ""; String imagString = Double.toString(imag);
String realString = Double.toString(real);
if (real !=0 )
{
if (imag !=0 )
{
if (imag < 0)
{
String imagString2 = imagString.replace("-","");
return realString+" - "+"j"+imagString2;
}
return realString+" + "+"j"+imagString;
}
else
{
return realString;
}
}
return realString;
} }
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 + real;
answer.imag = complexNum.imag + imag;
return answer; return answer;
} }
}
} \ No newline at end of file
\ No newline at end of file
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