Write a generic class called HighestLowest with a type parameter constrained to any type that implements Comparable. The constructor should accept an array of such objects. The class should have methods that return the highest and lowest object in the array. Demonstrate the class in an application by creating two instances of the HighestLowest class, one with an array of Employee objects and another one with an array of City objects.
The Employee and City classes are described below:
Create the classes Employee that implements comparable and City that implements comparable.
The Employee class should have to fields, name and age. since it is implementing comparable, it has to have method called compareTo that takes another Employee class object as parameter and returns -1. 1 or 0 depending on the objects being compared. Please use the age to compare two employee objects. Collect data for three employee objects as shown below, create an array of those three employee objects and pass them as an argument to the contructor to create an instance of HighestLowest class.
The City class should have to fields, name and population. since it is implementing comparable, it has to have method called compareTo that takes another City objects as parameter and returns -1. 1 or 0 depending on the objects being compared. Please use the population to compare two City objects. Collect data for three City objects as shown below, create an array of those three City objects and pass them as an argument to the contructor to create another isntance of HighestLowest class.
At the end you call the getLowest() and getHighest from the collection of Employee objects which return the youngest employee and oldest employee.
Also, you call the getLowest() and getHighest from the collection of City objects which return the city lowest population and city with highest population.
The java file must be named as: Generics2.java
Here is the sample input output:
Collecting Employee1 Information
Please enter Employee1 name:
Please enter Employee1 Age:
Collecting Employee2 Information
Please enter Employee2 name:
Please enter Employee2 Age:
Collecting Employee3 Information
Please enter Employee3 name:
Please enter Employee3 Age:
Collecting City1 Information
Please enter City1 name:
Please enter City1 population:
Collecting City2 Information
Please enter City2 name:
Please enter City2 population:
Collecting City3 Information
Please enter City3 population:
The oldest employee is: Susan
The youngest employee: Maria
The city with highest population is: Los Angeles
The city with lowest population is: Santa Monica