a) Write the implementation of the class Complex as per the specifications that follow. An object of type Complex stores information about a single complex number. A complex number is of the form a + bi, where a and b are numbers of type double, and i = √−1 .

The class Complex contains:

Private instance variables of type double to store the real and imaginary parts of the complex number.

Three constructors:

o One that takes two arguments and sets all of the corresponding instance variables.

o A default constructor, that sets all instance variables to 0.0.

o A copy constructor which sets the instance variables to be the same as the passed Complex object.

Public methods to get (accessor) and set (mutator) each instance variable individually.

A public method called addition() that returns a new Complex object which is the sum of the calling object and the passed object.

A public static method called multiplication() that returns a new Complex object which is the product of two passed complex numbers.

A toString() method which takes no arguments and returns a string containing the Complex object showing its real and imaginary parts in the standard format. Be sure that the real and imaginary numbers are formatted with 2 places after the decimal. Here is a link explaining how to use the format() method from the String class. https://www.cs.colostate.edu/~cs160/.Summer16/resources/Java_printf_method_quick_re ference.pdf

An equals() method which tests for the equality of two Complex objects. Clarification: Addition, multiplication, and equality of two complex numbers a + bi and c + di are defined as below:

o Addition: (a + bi) + (c + di) = (a + c) + (b + d)i

o Multiplication: (a + bi)*(c + di) = (ac – bd) + (ad + bc)i

o Equality: a + bi is equal to c + di if and only if a = c and b = d

b) Write a driver which

1. Creates two Complex objects:

o First one is created with the default constructor.

o The second one is created with values entered by the user.

2. Outputs the descriptions of the two Complex objects created in step 1 above.

3. Compares the two Complex objects for equality and displays the result.

4. Swaps the real and imaginary parts of the 2nd Complex object and display the resulting Complex object.

5. Changes the first Complex object’s content to be the same as that of the second one. (Hint: good place to use your copy constructor).

6. Compares the two Complex objects for equality again and displays the result.

7. Prompts the user for a number and adds this value to the real and imaginary part of either of the two Complex objects – you decide which one.

8. Compares the two Complex objects for equality again and displays the result.

9. Adds the two Complex objects storing the result in the 1st Complex object and displays the result.

10. Multiplies the two Complex objects storing the result in the 2nd Complex object and displays the result.

11. Finishes of with a closing message giving the final values of the two Complex objects.

Note: i. Notice the difference in invoking the method addition() and the method multiply(). ii. You can create static methods in the driver if you wish.

Figure 2 is a sample output to help illustrate the expected behaviour of your program.

Let's play with complex numbers! Complex number created with default constructor is: 0.00 + 0.00*i Enter the real part of the 2nd complex number: -4.76 Enter the imaginary part of the 2nd complex number: 4.76 Entered Complex Number is: -4.76 + 4.76*i The complex numbers 0.00 + 0.00*i and -4.76 + 4.76*i are not equal Swapping real and imaginary part of -4.76 + 4.76*i results in 4.76 + -4.76*i 4.76 4.76*i is equal to 4.76 + -4.76*i is now true Enter a number please: 11.1 4.76 4.76*i has been changed to 15.86 +6.34*i The complex numbers 15.86 + 6.34*i and 4.76 + -4.76*i are not equal. Adding 15.86 + 6.34*i to 4.76 + -4.76*i results in the complex number 20.62 + 1.58*i Multiplying 20.62 + 1.58*i by 4.76 + -4.76*i results in the complex number 105.67 + -90.63*i So after all this manipulation the original complex number have morphed into 20.62 1.58*i and 105.67 + -90.63*i You should now be comfortable with defining a class and manipulating objects, right? On to bigger and better things… Figure 2- Sample output for Question 2