Question: 1. Write a Java program that implements and tests the following interface for complex numbers: Complex +Complex (real: double, imag: double + toString): String +plus(c:
1. Write a Java program that implements and tests the following interface for complex numbers: Complex +Complex (real: double, imag: double + toString): String +plus(c: Complex): Complex + times(c: Complex): Complex +isimag): boolean +pow(n: int): Complex Test your class with the ollowing main program: public static void main(String[] args)( Complex x new Complex (-3.0, 2.0) Complex y new Complex (2.0, -1.0); Complex sum = x.pt us (y) ; complex prod = y, times (x) ; Complex power x. pow(4); System.out.println (x); System.out.println(y); System.out.println (sum); System.out.println (prod); System.out.println (power); System.out.println(x.isImag)) System.out.println(y.norm()) // end of test program Turn in a listing of your program, and the results of the test run. (Note: the methods plus and times do not mutate the complex number, but rather produce a new complex number as the result.) Extra Credit: Add a method norm() that returns the Euclidean norm of the complex number. Test it by printing the norm of y. (Hint: the square route function is Math.sqrt(t).)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
