COMP2396
Loading...
Searching...
No Matches
Complex.java
Go to the documentation of this file.
1
@SuppressWarnings(
"unused"
)
2
public class
Complex
{
3
private
int
real
;
4
private
int
imaginary
;
5
public
Complex
(
int
real,
int
imaginary) {
6
this.real = real;
7
this.imaginary = imaginary;
8
}
9
public
void
add
(
Complex
c) {
10
this.real += c.
real
;
11
this.imaginary += c.
imaginary
;
12
}
13
public
void
subtract
(
Complex
c) {
14
this.real -= c.
real
;
15
this.imaginary -= c.
imaginary
;
16
}
17
public
String
toString
() {
18
// `imaginary >= 0`, not `imaginary > 0`
19
return
real + (imaginary >= 0 ?
" + "
:
" - "
) + Math.abs(imaginary) +
"i"
;
20
}
21
}
Complex
Definition
Complex.java:2
Complex.real
int real
Definition
Complex.java:3
Complex.add
void add(Complex c)
Definition
Complex.java:9
Complex.toString
String toString()
Definition
Complex.java:17
Complex.subtract
void subtract(Complex c)
Definition
Complex.java:13
Complex.imaginary
int imaginary
Definition
Complex.java:4
Complex.Complex
Complex(int real, int imaginary)
Definition
Complex.java:5
tutorial3
q2
Complex.java
Generated on Sat Dec 7 2024 17:10:09 for COMP2396 by
1.12.0