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
Fantastic news! We've Found the answer you've been seeking!
Question:
Starter code is available here:
https://github.com/ucsd-cse11-su222/cse11-pa8-starter
Transcribed Image Text:
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<Double> { 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<Point> 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<Point> 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<String> 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. 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<Double> { 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<Point> 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<Point> 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<String> 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.
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Which type of Organizational Model put the MOST emphasis on establishing MORALE and AUTONOMY O a. Hierarchical style Model b. O c. O d. Flat Management (Holocracy) Model Multi-divisional style Model...
-
What are the "three Cs" and how do they explain why companies choose to perform an activity internally versus outsource (buy) the activity to a supplier.
-
Information for Craig Ltd. follows: 1. On July 6, Craig acquired the plant assets of Des bury Company, which had discontinued operations. The property was appraised by a reliable, independent...
-
You throw a ball straight up into the air. If air resistance affects the motion of the ball, which takes longer: the upward trip or the downward trip? Analyze using three different systems.
-
Winston Black was an audit partner in the firm of Henson, Davis & Company. He was in the process of reviewing the audit files for the audit of a new client, McMullan Resources. McMullan was in the...
-
Scenario Labor Expense Salvage Value of Buildings Salvage Value of Land Best Case $200,000 $150,000 $300,000 Expected Case 250,000 100,000 200,000 Worst Case 350,000 20,000 40,000 Make a scenario...
-
For this assignment, we are going to change our point of view. You are now working for Woolly, and you are preparing Woolly's response to Mammoth's RFP to support the transition of the 12 staff from...
-
An operational project is one that a. is completed to meet regulatory compliance. b. supports an organizations' long-run mission. c. can improve organizational performance. d. must be completed.
-
The next hurdle Joseph wants to tackle is the extension of the ideas to account to multiple periods. What are the main challenges in this extension? Is there a reasonable way to extend the analysis...
-
AFTER AN EXHAUSTING TRIAL THE JURY REWARDS JANE $500,000 BECAUSE JOHN ACCIDENTLY RAN OVER HER TOE WITH HIS BICYCLE. THE JUDGE THINKS THAT THE VERDICT IS EXCESSIVE THOUGH SHE AGREES THAT JANE SHOULD...
-
What are the three foremost opportunities identified for Costco, indicative of strategic pathways that could bolster the company's growth, market position, and competitive advantage?
-
Consider individuals A and B. They have preferences over two-dimensional consumption bundles x = (x,x2) where goods consumption must be non-negative, 0 and 2 0. Individuals A and B have perfect...
-
Hux Investments leased equipment from a leasing company on July 1, 2018 in a finance lease.. The present value of the lease payments discounted at 10% was $75,600. Ten annual lease payments of $8,630...
-
Fill in the blanks: The number of pups in wolf dens of the southwestern United States is recorded below for wolf dens: 587534395856564794361089127 12 10 969 Compute a 90% confidence interval for the...
-
In the simple quantity theory of money, what will lead to an increase in aggregate demand? In monetarism, what will lead to an increase in aggregate demand?
-
Steve Drake sells a rental house on January 1, 2012, and receives $130,000 cash and a note for $55,000 at 10 percent interest. The purchaser also assumes the mortgage on the property of $45,000....
-
Lisa Sizemore, a taxpayer in the 10-15 percent tax bracket, purchased stock as an investment on July 11, 2011. She sold the stock on July 9, 2012, 2 days before qualifying for the long-term holding...
-
Please answer the following questions regarding the taxability of Social Security: a. A 68-year-old taxpayer has $20,000 in Social Security income and $100,000 in tax-free municipal bond income. Does...
-
Suppose a job enrichment effort in one plant of a manufacturing firm is judged to be very successful. You are the corporate change agent responsible for the project, and you wish to diffuse it to...
-
Discuss: The best organizational structure to generate innovative ideas might not be the best structure to implement those ideas.
-
What qualities would the ideal gatekeeper possess to facilitate the communication of technical information in the firm?
Study smarter with the SolutionInn App