Question: page 19 is the second page 2. (25 pts) You are given two classes Complex and ComplexTuple on page 19. They implement complex numbers and

2. (25 pts) You are given two classes Complex and ComplexTuple on page 19. They implement complex numbers and tuples of complex numbers, respectively. Hint: In both a and b, below, you are given significantly more space than you should need. a) (10 pts) Add a clone () method to the Complex class; the method must override java.lang. Object's clone () method. The signature is shown below; you just need to fill in the try and catch blocks. @Override public Object clone () { try { Complex c = (Complex) super. clone(); } catch (CloneNot SupportedException e) { Sample code for Problem 2 public class complex implements Cloneable { private int re; // real part private int im; // imaginary part public Complex (int re, int im) { this.re = re; this. im = im; } @Override public boolean equals (Object o) { // Assume this is already implemented; the // implementation details irrelevant. } } public class ComplexTuple { private Complex ci; private complex c2; public Complex Tuple (Complex ci, Complex c2) { this.cl = c1; this.c2 = c2; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
