CMPS 144 Spring 2022
Prog. Assg. #2: Complex Numbers with Generators
Due: 11:59pm, February 18

For this assignment, you are to complete the ComplexNumberWithGen class, several methods (and two constructors) of which are "stubbed" (i.e., left for you to provide the bodies). This class is to be a child of ComplexNumber (from the previous programming assignment), and its purpose is to augment the functionality of its parent class.
Note: A working link to a correct version of ComplexNumber will be provided after the deadline has passed for submitting it.

Specifically, ComplexNumWithGen is to include generator methods that carry out the arithmetic operations addition, subtraction, multiplication, and division. What distinguishes these new methods from the inherited methods that perform the same operations is that, rather than modifying the state of an already-existing object, they create and return a brand new object.

For example, suppose that a client program had ComplexNumberWithGen objects x and y representing, respectively, the complex numbers a + bi and c + di. Then the method call x.addTo(y) (to the inherited method addTo()) would have the effect of modifying the state of x so that it represented (a+c) + (b+d)i. In contrast, the call x.plus(y) (to the new generator method plus()) will change neither the state of x nor that of y, but it will return a brand new ComplexNumberWithGen object that represents the complex number (a+c) + (b+d)i.

Provided is the Java application ComplexNumWithGenTester for testing your work. Essentially, it's a calculator by which you can add, subtract, multiply, or divide complex numbers. A sample user/program dialog is shown below, with user input shown in boldface.

Welcome to the Complex Number (with generators) Tester Program.

> 2.1 3.7 + 4 -9
6.1 + -5.3i

> 0 1 * 0 1
-1 + 0i

> 3 5 / -2 6
0.6 + -0.7i

> 1 2 - 3 4
-2 + -2i

> H
Examples of commands:
Q           (quit)
H           (print this help info)
2 6 + 3 5   (computes (2+6i) + (3+5i))
2 6 - 3 5   (computes (2+6i) - (3+5i))
2 6 * 3 5   (computes (2+6i) * (3+5i))
2 6 / 3 5   (computes (2+6i) / (3+5i))

> Q
Goodbye.

Program Submission

Using the file submission system (see link on course web page), you are to submit the ComplexNumberWithGen.java file to the prog2_dir folder.