Commit 3b928e73 authored by rhys.may's avatar rhys.may

Upload New File

parent f23e1349
public class Complex {
double realno, imagno;
public Complex(double d, double e) {
// TODO Auto-generated constructor stub
realno = d;
imagno = e;
}
public Complex() {
// TODO Auto-generated constructor stub
realno = 0;
imagno = 0;
}
public void setReal(double q) {
realno = q;
}
public void setImag(double q) {
imagno = q;
}
public double real() {
// TODO Auto-generated method stub
return realno;
}
public double imag() {
// TODO Auto-generated method stub
return imagno;
}
public double magnitude() {
// TODO Auto-generated method stub
return Math.sqrt((Math.pow(realno, 2) + Math.pow(imagno, 2)));
}
public Object argument() {
return Math.atan2(realno, imagno);
}
public Complex add(Complex b) {
// TODO Auto-generated method stub
this.realno = this.realno + b.realno;
this.imagno = this.imagno + b.imagno;
return this;
}
public String toString() {
String realno = "";
String imagno = "";
String Sign = "";
if(this.realno ==0) {
realno = "";
} else if(this.realno > 0) {
realno = "" + this.realno;
} else if(this.realno > 0) {
realno = "" + (Math.sqrt(Math.pow(this.realno, 2)));
}
if(this.imagno < 0) {
Sign = " - ";
}else if(this.imagno > 0) {
Sign = " + ";
}else {
Sign = "";
}
if(this.realno == 0) {
Sign = "";
}
if(this.imagno == 0) {
imagno = "";
}else if(this.imagno != 0) {
double l = Math.sqrt(Math.pow(this.imagno, 2));
imagno = "j" + l;
}
return (realno + Sign + imagno);
}
}
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