COMP2396
Loading...
Searching...
No Matches
Complex Class Reference
Collaboration diagram for Complex:

Public Member Functions

 Complex (int real, int imaginary)
 
void add (Complex c)
 
void subtract (Complex c)
 
String toString ()
 

Private Attributes

int imaginary
 
int real
 

Detailed Description

Definition at line 2 of file Complex.java.

Constructor & Destructor Documentation

◆ Complex()

Complex.Complex ( int real,
int imaginary )
inline

Definition at line 5 of file Complex.java.

5 {
6 this.real = real;
7 this.imaginary = imaginary;
8 }
int real
Definition Complex.java:3
int imaginary
Definition Complex.java:4

Member Function Documentation

◆ add()

void Complex.add ( Complex c)
inline

Definition at line 9 of file Complex.java.

9 {
10 this.real += c.real;
11 this.imaginary += c.imaginary;
12 }

References imaginary, and real.

Referenced by Tester.main().

Here is the caller graph for this function:

◆ subtract()

void Complex.subtract ( Complex c)
inline

Definition at line 13 of file Complex.java.

13 {
14 this.real -= c.real;
15 this.imaginary -= c.imaginary;
16 }

References imaginary, and real.

Referenced by Tester.main().

Here is the caller graph for this function:

◆ toString()

String Complex.toString ( )
inline

Definition at line 17 of file Complex.java.

17 {
18 // `imaginary >= 0`, not `imaginary > 0`
19 return real + (imaginary >= 0 ? " + " : " - ") + Math.abs(imaginary) + "i";
20 }

Referenced by Tester.main().

Here is the caller graph for this function:

Member Data Documentation

◆ imaginary

int Complex.imaginary
private

Definition at line 4 of file Complex.java.

Referenced by add(), and subtract().

◆ real

int Complex.real
private

Definition at line 3 of file Complex.java.

Referenced by add(), and subtract().


The documentation for this class was generated from the following file: