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
(b) Implement a functionCountry findLargest(List
(c) Implement agenericmethodgenericMaxthat finds the maximum object in a list. The generic constraints should make the method as flexible as possible.
static public
Please give solution in code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started