Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions