-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path34_ComplexNumber.java
More file actions
38 lines (30 loc) · 966 Bytes
/
34_ComplexNumber.java
File metadata and controls
38 lines (30 loc) · 966 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
public class ComplexNumber {
private double real;
private double imaginary;
public ComplexNumber(double real, double imaginary) {
this.real = real;
this.imaginary = imaginary;
}
public double getReal() {
return this.real;
}
public double getImaginary() {
return this.imaginary;
}
public void add(double real, double imaginary) {
this.real += real;
this.imaginary += imaginary;
}
public void add(ComplexNumber complexNumber) {
this.real += complexNumber.getReal();
this.imaginary += complexNumber.getImaginary();
}
public void subtract(double real, double imaginary) {
this.real -= real;
this.imaginary -= imaginary;
}
public void subtract(ComplexNumber complexNumber) {
this.real -= complexNumber.getReal();
this.imaginary -= complexNumber.getImaginary();
}
}