Modify the LabeledPoint class of Exercise E15.15 so that it implements the Comparable interface. Sort points first by their x-coordinates.

Question:

Modify the LabeledPoint class of Exercise E15.15 so that it implements the Comparable interface. Sort points first by their x-coordinates. If two points have the same x-coordinate, sort them by their y-coordinates. If two points have the same x- and y-coordinates, sort them by their label. Write a tester program that checks all cases by inserting points into a TreeSet.


Data from Exercise E15.15

A labeled point has x- and y-coordinates and a string label. Provide a class LabeledPoint with a constructor LabeledPoint(int x, int y, String label) and hashCode and equals methods. Two labeled points are considered the same when they have the same location and label.

This problem has been solved!


Do you need an answer to a question different from the above? Ask your question!

Step by Step Answer:

Related Book For  answer-question
Question Details
Chapter # 15
Section: Practice Exercises
Problem: 17
View Solution
Create a free account to access the answer
Cannot find your solution?
Post a FREE question now and get an answer within minutes. * Average response time.
Question Posted: June 10, 2021 05:24:10