Question: Modify this class so it implements the Comparable interface. We define Point p1 to be less than Point p2 if the distance from the origin

Modify this class so it implements the Comparable interface. We define Point p1 to be less than Point p2 if the distance from the origin to p1 is less than the distance from the origin to p2; p1 is greater than p2 if the distance from the origin to p1 is greater than the distance from the origin to p2; otherwise, if they distances are equal then p1 is equal to p2. The original source Point code: public class Point { // A point in the Cartesian plane is located at (x, y) where x and y form the // coordinates of the point. private double x; private double y; // Constructor. public Point(double initX, double initY) { setX(initX); setY(initY); } // Accessor method for x. public double getX() { return x; } // Accessor method for y. public double getY() { return y; } // Mutator method for x. public void setX(double newX) { x = newX; } // Mutator method for y. public void setY(double newY) { y = newY; } }

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 Databases Questions!