Given the following class Complex, complete the following questions:
class Complex {
private int real;
private int imaginary;
public Complex(int r, int i) {
real = r;
imaginary = i;
} // end constructor
public String toString() {
return real + “ + ” + imaginary + “i”;
} // end toString
} //end class Complex
a. Write a statement that creates a complex number 3 + 2i called cl.
b. Write a statement that creates a complex number 4 - 5 i called c2.
c. Write a statement that prints a complex number called cl.
d. For the class Complex, modify the toStringmethod so that if the real or imaginary part is zero, it is not placed in the string. If both are zero, then just print zero. Finally, if the imaginary part is 1 or -1, simply print + i instead of + li and - i instead of - li.
e. For the class complex, add the following methods: public Complex add(Complex val)
// returns a Complex number whose value is (this + val) public Complex subtract(Complex val)
// returns a Complex number whose value is (this - val) public Complex multiply(Complex val)
// returns a Complex number whose value is (this * val)
f. Add a mainprogram with test code that demonstrates that the above methods are working properly.
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.