-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexNumber.java
More file actions
43 lines (31 loc) · 1.11 KB
/
Copy pathComplexNumber.java
File metadata and controls
43 lines (31 loc) · 1.11 KB
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
42
43
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 real;
}
public void setReal(double real) {
this.real = real;
}
public double getImaginary() {
return imaginary;
}
public void setImaginary(double imaginary) {
this.imaginary = imaginary;
}
public ComplexNumber plusComplexNumbers(ComplexNumber other) {
return new ComplexNumber(real + other.real, imaginary + other.imaginary);
}
public ComplexNumber minusComplexNumbers(ComplexNumber other) {
return new ComplexNumber(real - other.real, imaginary - other.imaginary);
}
public ComplexNumber multiply(ComplexNumber other) {
double newReal = real * other.real - imaginary * other.imaginary;
double newImaginary = real * other.imaginary + imaginary * other.real;
return new ComplexNumber(newReal, newImaginary);
}
}