Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following Country class. Write a comparator that defines an ordering on Country objects. Use lexicographic ordering on (name, area). That is it first

image text in transcribed

Consider the following Country class. Write a comparator that defines an ordering on Country objects. Use lexicographic ordering on (name, area). That is it first compares names. If they are the same (ignoring case), then compare the area. API is on the last page. class Country {private String name; private int area; public Country (String n, int a) {name = n; area = a;} public string getName {} {return name;} public int getArea {} {return area;} public String costring {} {return name + " " + area;}} public class CountryTester {public static void main (String args) {Comparator comp =//your work goes here. ArrayList countries = new ArrayList(); countries.add(new Country ("a", 30)); countries.add(new Country ("b", 10)); countries.add(new Country ("a", 20)); Collections.sort(countries, comp); System.out.printin(countries);//prints [a 20, a 30, b 10]}}

Step by Step Solution

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

More Books

Students also viewed these Databases questions

Question

3. The group answers the questions.

Answered: 1 week ago