Question: Homework # 5 1 . Write a Java program that implements and tests the following interface for complex numbers: Test your class with the

Homework \#5
1. Write a Java program that implements and tests the following interface for complex numbers:
Test your class with the following main program:
```
public static void main(String[] args){
Complex x = new Complex(-5.0,4.0);
Complex y = new Complex(3.0,-2.0);
Complex sum = x.plus(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.isReal());
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 squareroot function is Math.sqrt(t).)
Homework \ # 5 1 . Write a Java program that

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!