-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOOPSAssignment.java
39 lines (32 loc) · 1.01 KB
/
OOPSAssignment.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
37
38
39
public class OOPSAssignment {
public static void main(String[] args) {
Complex c1 = new Complex(10, 10);
Complex c2 = new Complex(5, 5);
Complex ans = Complex.product(c1, c2);
System.out.printf("%d + %di",ans.real, ans.imaginary);
}
}
class Complex {
int real;
int imaginary;
Complex(){
this.real = 0;
this.imaginary = 0;
}
Complex(int real, int imaginary){
this.real = real;
this.imaginary = imaginary;
}
static Complex sum(Complex c1, Complex c2){
Complex ans = new Complex(c1.real+c2.real, c1.imaginary+c2.imaginary);
return ans;
}
static Complex difference(Complex c1, Complex c2){
Complex ans = new Complex(c1.real-c2.real, c1.imaginary-c2.imaginary);
return ans;
}
static Complex product(Complex c1, Complex c2){
Complex ans = new Complex(c1.real*c2.real - c1.imaginary*c2.imaginary, c1.real*c2.imaginary + c1.imaginary*c2.real);
return ans;
}
}