-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplex.java
36 lines (29 loc) · 861 Bytes
/
Complex.java
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
/**
* Author : Kisaru Liyanage
* Description : This is a sub class of Point class used to create complex numbers and do
* some complex arithmetic(addition, square, square of absolute) on them
* Date : 04/09/2016
*/
public class Complex extends Point{
Complex(double real, double imaginary) {
super(real, imaginary);
}
public Complex squared() {
return new Complex((x * x - y * y), (2 * x * y));
}
public Complex add(Complex number) {
return new Complex((x + number.getReal()), (y + number.getImaginary()));
}
public double absSquared() {
return x * x + y * y;
}
public double getReal() {
return x;
}
public double getImaginary() {
return y;
}
public String toString() {
return "[" + x + ", " + y + "]";
}
}