COMP2396
Loading...
Searching...
No Matches
Complex.java
Go to the documentation of this file.
1@SuppressWarnings("unused")
2public 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}
int real
Definition Complex.java:3
void add(Complex c)
Definition Complex.java:9
String toString()
Definition Complex.java:17
void subtract(Complex c)
Definition Complex.java:13
int imaginary
Definition Complex.java:4
Complex(int real, int imaginary)
Definition Complex.java:5