Question: 1. (a) Write a method max that finds a maximum element in an unsorted List of countries. The interface of max allows users to provide

1. (a) Write a methodmaxthat finds a maximum element in an unsorted List of countries. The interface of max allows users to provide their own comparison method. This affords them to define the maximum according to different properties, such as population, area, gross domestic product (GDP), etc.maxmust not modifytheList(Sorting the list is not an option). If multiple countries with the same maximum value exist in the list,maxis free to pick one of those countries. If the list of countries is empty,maxreturnsnull.

// public specification of Country public class Country { int populationCount() {} // head count float area() {} // in square miles float GDP() {} // in billion dollars }

static public Country max(List countries, Comparator comp) { /* YOUR CODE */ }

(b) Implement a functionCountry findLargest(List countries)that finds the country with the largest area. Your implementation is required to use the functionmaxfrom the previous question.

(c) Implement agenericmethodgenericMaxthat finds the maximum object in a list. The generic constraints should make the method as flexible as possible.

static public TYPEVARIABLE/TYPEBOUNDSgenericMax(List lst, Comparator comparator) { /* YOUR CODE */ }

Please give solution in code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!