Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Write a generic class called HighestLowest with a type parameter constrained to any type that implements Comparable. The constructor should accept an array of

JAVA

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.

Please refer to the test cases below for the exact input and output that your program should produce.

TestCase1:

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: 24

Collecting Employee3 Information Please enter Employee3 name: Adam Please enter Employee3 Age: 40

Collecting City1 Information Please enter City1 name: LA Please enter City1 population: 35000000

Collecting City2 Information Please enter City2 name: Culver City Please enter City2 population: 250000

Collecting City3 Information Please enter City3 name: Santa Monica Please enter City3 population: 300000

The oldest employee is: Adam The youngest employee: Susan The city with highest population is: LA The city with lowest population is: Culver City

Test Case2:

Collecting Employee1 Information Please enter Employee1 name: John Please enter Employee1 Age: 30

Collecting Employee2 Information Please enter Employee2 name: Susan Please enter Employee2 Age: 25

Collecting Employee3 Information Please enter Employee3 name: Adam Please enter Employee3 Age: 20

Collecting City1 Information Please enter City1 name: LA Please enter City1 population: 100

Collecting City2 Information Please enter City2 name: New York Please enter City2 population: 200

Collecting City3 Information Please enter City3 name: Chicago Please enter City3 population: 150

The oldest employee is: John The youngest employee: Adam The city with highest population is: New York The city with lowest population is: LA

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_2

Step: 3

blur-text-image_3

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

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions

Question

3. Provide advice on how to help a plateaued employee.

Answered: 1 week ago