-
Notifications
You must be signed in to change notification settings - Fork 217
Expand file tree
/
Copy pathComplexNumber.java
More file actions
39 lines (30 loc) · 973 Bytes
/
ComplexNumber.java
File metadata and controls
39 lines (30 loc) · 973 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
39
package com.example.task03;
public class ComplexNumber {
private int real;
private int imaginary;
ComplexNumber(int real, int imaginary) {
this.real = real;
this.imaginary = imaginary;
}
public void setReal(int real) {
this.real = real;
}
public void setImaginary(int imaginary) {
this.imaginary = imaginary;
}
public int getReal() {
return real;
}
public int getImaginary() {
return imaginary;
}
public ComplexNumber add(ComplexNumber number) {
return new ComplexNumber(real + number.real, imaginary + number.imaginary);
}
public ComplexNumber mul(ComplexNumber number) {
return new ComplexNumber(real * number.real - imaginary * number.imaginary, imaginary * number.real + number.imaginary * real);
}
public String toString() {
return "(" + Integer.toString(real) + ", " + Integer.toString(imaginary) + "i" + ")";
}
}