Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help writing this program in java. directions: Your task is to develop an Athlete class that has the persons name, sport, and ranking, where

need help writing this program in java.

directions: Your task is to develop an Athlete class that has the persons name, sport, and ranking, where the name and sport are Strings and the ranking is anything that is comparable (do NOT hardcode this to an int use generics). You should be able to sort athletes two different ways: alphabetically by sport and if two athletes have the same sport, they should be sorted alphabetically by name or alphabetically by sport and if two athletes have the same sport, they should be sorted in decreasing order of rank. In your main method, create five Athlete objects, add them to an ArrayList, and display them. Then sort the ArrayList by sport and name and display the sorted list. Finally, sort the array list by sport and ranking and display the sorted list again. Hints: Because you need to sort the Athletes in two different ways, you will probably need to both implement Comparable and make a new Comparator class. You may need to add getter methods for the fields in your Athlete class, and it might be helpful to override the toString method to make it easier to display the objects.

output example:

Unsorted

John Doe (baseball - 3)

Sam Johnson (football - 2)

Kevin Smith (baseball - 1)

Sally Johnson (swimming - 3)

James Smith (swimming - 4)

Meagan Kelly (swimming - 1)

Sorted by sport and then name John Doe (baseball - 3)

Kevin Smith (baseball - 1)

Sam Johnson (football - 2)

James Smith (swimming - 4)

Meagan Kelly (swimming - 1)

Sally Johnson (swimming - 3)

Sorted by sport and then ranking

Kevin Smith (baseball - 1)

John Doe (baseball - 3)

Sam Johnson (football - 2)

Meagan Kelly (swimming - 1)

Sally Johnson (swimming - 3)

James Smith (swimming - 4)

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

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

4. Who would lead the group?

Answered: 1 week ago

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago