Question: Complex Language/Type: Java classes Comparable compare To interfaces implementing instance methods Related Links: Author: Complex.java Marty Stepp Suppose that a class Complex has been

Complex Language/Type: Java classes Comparable compare To interfaces implementing instance methods Related

Complex Language/Type: Java classes Comparable compare To interfaces implementing instance methods Related Links: Author: Complex.java Marty Stepp Suppose that a class Complex has been defined for storing complex numbers. In mathematics, complex numbers are those that can be written as (x + y) where x and y are real numbers and i is the square root of -1. In other words, complex numbers have a real part (x) and an imaginary part (y). The class includes the following members: Name private double x private double y public Complex(double x, double y) public double getReal() public double getImaginary() public double abs() public string tostring() public complex add(Complex other) real part imaginary part Description constructs a complex number x + y*i returns the real part of the number returns the imaginary part of the number returns the absolute value of the number returns a String representation of the number returns the result of adding another complex number to this one public complex subtract (Complex other) | returns the result of subtracting another complex number from this one Your task is to modify the class to be Comparable by adding an appropriate compareTo method. Complex objects should be compared using absolute value with smaller absolute values considered "less" than numbers of higher absolute value. The absolute value of a complex number is defined to be the square root of the sum of the squares of x and y.

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!