solution

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:
John
Please enter Employee1 Age:
34

Collecting Employee2 Information

Please enter Employee2 name:
Susan
Please enter Employee2 Age:
53

Collecting Employee3 Information

Please enter Employee3 name:
Maria
Please enter Employee3 Age:
23

Collecting City1 Information

Please enter City1 name:
Santa Monica
Please enter City1 population:
45000

Collecting City2 Information

Please enter City2 name:
Culver City
Please enter City2 population:
56000
Collecting City3 Information

Los Angeles
Please enter City3 population:
80000
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

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!