Implementing Complex Numbers with Class

Java has a number of built-in types such as int, char, boolean, float, and double, among others. Scientists and engineers often like to work with complex numbers, but complex numbers are not a built-in type in Java. Therefore, your task is to implement a complex number class. The class should be implemented in a file named Complex.java.

 

Recall that a complex number is of the form a + bi where a and b are real numbers and i is an imaginary number. Addition of two complex numbers is defined by (a + bi) + (c + di) = (a+c) + (b+d)i. Similarly, to multiply two complex numbers, we simply compute (a + bi) * (c + di) = ac + adi + bci + bdi2 = (ac - bd) + (ad + bc) i since i2 is -1 by definition.

 

In your implementation, the numbers a and b in the complex number a + bi should be represented by doubles. Below are the public methods (functions) that your Complex class should contain. Be sure to use exactly these names and the specified kinds of arguments and return values. You may use any additional private methods that you like in order to build your public methods.

 

Use the program ComplexTest.java, found in the class folder on the network, to test your Complex class.