Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Starter code is available here: https://github.com/ucsd-cse11-su222/cse11-pa8-starter Comparators and Lists The Comparator interface in Java describes operations that compare two values of the same type. A
Starter code is available here:
https://github.com/ucsd-cse11-su222/cse11-pa8-starter
Comparators and Lists The Comparator interface in Java describes operations that compare two values of the same type. A Comparator's compare method should return a negative number if the first argument is less than the second, o if they are equal, and a positive number if the first argument is greater than the second. For example, a Comparator that compares two Doubles we could write as: class CompareDoubles implements Comparator { public int compare (Double n, Double m) { } if(nm) { return 1; } else if(m> n) { return -1; } else { return 0; } All of your code will go into a single file CompareLists.java. Comparators First, write the following implementations of the Comparator interface. You can write them all in the file CompareLists.java. 1. Write a class PointCompare that implements Comparator that compares points by the following process If the first point's y coordinate is smaller than the other point's y coordinate, it is smaller; if y is greater, it's greater. If the y coordinates are the same, if the first point's x coordinate is smaller, it is smaller, if greater, the first point is greater. If the points have the same coordinates, return 2. Write a class PointDistanceCompare that implements Comparator for Points that compares the points' distance from (0, 0). If the first point's distance is closer to o, it's smaller, if the distances are equal, the points are equal, and if the distance is further from o, the point is larger. 3. Write a class StringCompare that implements Comparator that uses the compareTo method on strings for comparison and returns the result of compareTo directly. Hint: not all classes need constructors. Remember the method compareTo.
Step by Step Solution
★★★★★
3.51 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started