-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenComplexNum.java
More file actions
41 lines (34 loc) · 843 Bytes
/
Copy pathGenComplexNum.java
File metadata and controls
41 lines (34 loc) · 843 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class GenComplexNum {
private double real, imaginary;
public GenComplexNum() {
this.real=0;
this.imaginary=0;
}
public GenComplexNum(double real, double imaginary) {
this.real=real;
this.imaginary=imaginary;
}
public GenComplexNum(ExpComplexNum exp) {
double r=exp.getR();
double th=exp.getTheta();
this.real=r*Math.cos(th);
this.imaginary=r*Math.sin(th);
}
public GenComplexNum(PolComplexNum pol) {
double r=pol.getR();
double th=pol.getTheta();
this.real=r*Math.cos(th);
this.imaginary=r*Math.sin(th);
}
double getReal() {
return real;
}
double getImaginary() {
return imaginary;
}
public String toString() {
real=Double.parseDouble(String.format("%.2f", real));
imaginary=Double.parseDouble(String.format("%.2f", imaginary));
return "("+real+")+("+imaginary+")i";
}
}