Answered step by step
Verified Expert Solution
Link Copied!

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

imageimageimage

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Calculate the pH of 4.0 10-5 M phenol (Ka = 1.6 10-10).

Answered: 1 week ago