-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex.java
More file actions
54 lines (54 loc) · 1.43 KB
/
Copy pathComplex.java
File metadata and controls
54 lines (54 loc) · 1.43 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
44
45
46
47
48
49
50
51
52
53
54
import java.util.*;
public class Complex {
private int real, image;
Complex() {
real = 0;
image = 0;
}
Complex(int a, int b) {
real = a;
image = b;
}
public int get_real()
{
return real;
}
public int get_image()
{
return image;
}
public void set_real(int a)
{
real = a;
}
public void set_image(int b)
{
image = b;
}
public void print() {
if (real == 0 && image == 0) System.out.print(0);
else if (real == 0) {
if (image < 0) System.out.print(image + "i");
else System.out.print(image + "i");
}
else {
if (image < 0) System.out.print(real+ " - " + (-image) + "i");
else if (image == 0) System.out.print(real);
else System.out.print(real + " + " + image + "i");
}
}
public Complex sum(Complex z2) {
Complex z = new Complex((this.real + z2.real), (this.image + z2.image));
return z;
}
public Complex diff(Complex z2) {
Complex z = new Complex((this.real - z2.real), (this.image - z2.image));
return z;
}
public Complex multi(Complex z2) {
int a = this.real * z2.real - this.image * z2.image;
int b = this.real * z2.image + this.image * z2.real;
Complex z = new Complex(a, b);
return z;
}
}