Class Diagram Athlete The Athlete class implements the Seria

Class Diagram:

Athlete

The Athlete class implements the \"Serializable\" interface so that its object can be stored. (The Serializable interface is defined in the \"java.io\" package.)

AthleteNameComparator

The AthleteNameComparator class implements the \"Comparator\" interface (The Comparator interface is in \"java.util\" package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define:
public int compare(Athlete first, Athlete second)
instead by making the class implements Comparator<Athlete>.

If the first argument object has a last name lexicographically less than that of the second argument, an int less than zero is returned. If the first argument object has a last name lexicographically larger than that of the second argument, an int greater than zero is returned. If their last names are same, then their first names should be compared. If they have same first and last names, then 0 should be returned.

MedalCountComparator

The MedalCountComparator class implements the \"Comparator\" interface (The Comparator interface is in \"java.util\" package.). It needs to define the following method that was an inherited abstract method from Comparator interface:

public int compare(Object first, Object second)

(Note that you can also define:
public int compare(Athlete first, Athlete second)
instead by making the class implements Comparator<Athlete>.

If the first argument object has a larger gold medal count than that of the second argument, an int less than zero is returned. If the first argument object has a smaller gold medal count than that of the second argument, an int greater than zero is returned. If both gold medal counts are same, then their silver medal counts should be compared. If both gold medal counts are same and also silver medal counts are same, then their bronze counts should be compared. If all of gold, silver, and bronze medal counts are same, then 0 should be returned.

Sorts

The Sorts class is a utility class that will be used to sort a list of Athlete objects. Sorting algorithms are described in the algorithm note posted under Notes section of the course web site. These algorithms sort numbers stored in an array. It is your job to modify it to sort objects stored in an array list (or a vector).
The Sorts class object will never be instantiated. It must have the following methods:

public static void sort(ArrayList objects, Comparator<Athlete>)

Your sort method utilizes the compare method of the parameter Comparator object to sort. You can use one of Selection sort or Insertion Sort.

AthleteManagement

The AthleteManagement class has a list of Athlete objects that can be organized at the athlete management system. The athlete management system will be a fully encapsulated object. The AthleteManagement class implements the Serializable interface.
It has the following attributes:

The following public methods should be provided to interact with the athlete management system:

No input/output should occur in the athlete management system. User interaction should be handled only by the driver class.

You may add other methods to the class in order to make your life easier.

Assignment8

All input and output should be handled in Assignment8 class. The main method should start by displaying this updated menu in this exact format:

Choice\\t\\tAction\
------\\t\\t------\
A\\t\\tAdd Athlete\
D\\t\\tCount Athletes for Medal Type\
E\\t\\tSearch for Athlete Name\
L\\t\\tList Athletes\
O\\t\\tSort by Athlete Names\
P\\t\\tSort by Medal Counts\
Q\\t\\tQuit\
R\\t\\tRemove by Athlete Name\
T\\t\\tClose AthleteManagement\
U\\t\\tWrite Text to File\
V\\t\\tRead Text from File\
W\\t\\tSerialize AthleteManagement to File\
X\\t\\tDeserialize AthleteManagement from File\
?\\t\\tDisplay Help\ \

Next, the following prompt should be displayed:

What action would you like to perform?\

Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase. The following commands are modified or new.

Add Athlete

Your program should display the following prompt:

Please enter the following information of an athlete:\

First Name:\

Read in first name and prompt:

Last Name:\

Read in last name and prompt:

Sport:\

Read in sport and prompt:

The number of gold medals\

Read in a number of gold medals and prompt:

The number of silver medals\

Read in a number of silver medals and prompt:

The number of bronze medals\

Read in a number of bronze medals, and if the Athlete object with the first and last names is not in the athlete list, then add it into the athlete list and display:

athlete added\

Otherwise, display:

athlete exists\

Also, if any number of any medals entered is not an integer, display:

Please enter a numeric value for the number of medals. Athlete not added\

Count Athletes By Medal Type

Your program should display the following prompt:

Please enter a medal type, 0 for gold, 1 for silver, 2 for bronze, to count the athletes with such medal:\

Read in a medal type, and count the number of athletes that have at least one medal of the type, and print the number.

Also, if the entered medal type is not an integer, display:

Please enter an integer for a medal type, 0 for gold, 1 for silver, 2 for bronze.\

Search for Athlete Name

Your program should display the following prompt:

\"Please enter the first and last names of an athlete to search:\

\"First Name:\

Read in the fist name, then display the following prompt:

Last Name:\

Read in the last name, and search the athlete list based on these information. If there exists a Athlete object with the first and last name, then display the following:

athlete found\

Otherwise, display this:

athlete not found\

Sort By Athlete Names

Your program should sort the athlete list using last names and first names in alphabetical order by last names first, and if they are same, comparing first names and output the following:

sorted by athlete names\

Sort By Medal Counts

Your program should sort the athlete list using their medal counts in decreasing order, sort by gold medal counts first, then by silver, then by bronze and output the following:

sorted by medal counts\

Remove By Athlete Name

Your program should display the following prompt:

Please enter the first and last names of an athlete to remove:\

First Name:\

Read in the first name and display the following prompt:

Last Name:\

Read in the last name. If the Athlete object can be found in the athlete list, then remove it from the list, and display the following:

athlete removed\

If there is no such Athlete object in the athlete list, display:

athlete not found\

List Athletes

Each Athlete object information in the athlete list should be displayed using the toString method provided in the Athlete class. (and use listAthletes( ) method in the AthleteManagement class.)

If there is no Athlete object in the athlete list, display:

\ no athlete\ \

Close AthleteManagement

Delete all Athlete objects. Then, display the following:

athlete management system closed\

Write Text to File

Your program should display the following prompt:

Please enter a file name to write:\

Read in the filename and create an appropriate object to get ready to read from the file. Then it should display the following prompts:

Please enter a string to write in the file:\

Read in the string that a user types, say \"input\", then attach \"\ \" at the end of the string, and write it to the file. (i.e. input+\"\ \" string will be written in the file.)

If the operation is successful, display the following:

FILENAME was written\

Replace FILENAME with the actual name of the file.

Use try and catch statements to catch IOException. The file should be closed in a finally statement.

Read Text from File

Your program should display the following prompt:

Please enter a file name to read:\

Read in the file name create appropriate objects to get ready to read from the file. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was read\

Then read only the first line in the file, and display:

The first line of the file is:\

CONTENT\

where CONTENT should be replaced by the actual first line in the file.

Your program should catch the exceptions if there are. (Use try and catch statement to catch, FileNotFoundException, and the rest of IOException.)

If the file name cannot be found, display

FILENAME was not found\

where FILENAME is replaced by the actual file name.

Serialize AthleteManagement to File

Your program should display the following prompt:

Please enter a file name to write:\

Read in the filename and write the serialized AthleteManagement object out to it. Note that any objects to be stored mustimplement Serializable interface. The Serializable interface is defined in java.io.* package. If the operation is successful, display the following:

FILENAME was written\

Replace FILENAME with the actual name of the file.

Use try and catch statements to catch NotSerializableExeption and IOException.

Deserialize AthleteManagement from File

Your program should display the following prompt:

Please enter a file name to read:\

Read in the file name and attempt to load the AthleteManagement object from that file. Note that there is only one AthleteManagement object in the Assignment8 class, and the first object read from the file should be assigned to the AthleteManagement object. If the operation is successful, display the following (replace FILENAME with the actual name of the file):

FILENAME was read\

Your program should catch the exceptions if there are.

(Use try and catch statement to catch ClassNotFoundException, FileNotFoundException, and the rest of IOException.)

See the output files for exception handling.

These are the two given:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

You are required, but not limited, to turn in the following source files:

Assignment8.java(More code need to be added)
Athlete.java(given by the instructor, it needs to be modified for this assignment)
AthleteNameComparator.java
MedalCountComparator.java
Sorts.java
AthleteManagement.java

Attribute name Attribute type Description
athleteList ArrayList or Vector A list of Athlete objects in the athlete management system

Solution

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Class Diagram: Athlete The Athlete class implements the \
Class Diagram: Athlete The Athlete class implements the \
Class Diagram: Athlete The Athlete class implements the \
Class Diagram: Athlete The Athlete class implements the \
Class Diagram: Athlete The Athlete class implements the \
Class Diagram: Athlete The Athlete class implements the \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site