Question: Write you code in a class named HighScores, in file named HighScores.java. Write a program that records high-score data for a fictitious game. The program

Write you code in a class named HighScores, in file named HighScores.java.

Write a program that records high-score data for a fictitious game. The program will ask the user to enter five names, and five scores. It will store the data in memory, and print it back out sorted by score.

The output from your program should look approximately like this:

Enter the name for score #1: Suzy

Enter the score for score #1: 600

Enter the name for score #2: Kim

Enter the score for score #2: 9900

Enter the name for score #3: Bob

Enter the score for score #3: 1012

Enter the name for score #4: Armando

Enter the score for score #4: 8000

Enter the name for score #5: Tim

Enter the score for score #5: 514

Top Scorers:

Kim: 9900

Armando: 8000

Bob: 1012

Suzy: 600

Tim: 514

Requirements

The data must be stored in two ArrayLists: one ArrayList of strings named names, and one ArrayList of Integers named scores. These ArrayLists must be declared in the main method.

All of the user input should be done in a method named initialize. It should have the following signature:

public static void initialize(ArrayList names, ArrayList scores)

You should write a function that sorts both array lists, based on the values in the scores array list. This is one of the more conceptually challenging parts of the assignment. You want to sort the scores array list, and simultaneously alter the names array list so that the names continue to line up with their respective scores by index. In the example data above, when the score 9900 moves to the first element of the scores array list, the name Kim should also be moved to the top of the names array list. The function should have the following signature:

public static void sort(ArrayList names, ArrayList scores)

Finally you should write a method that displays the contents of the two arraylists. It should have the following signature:

public static void display(ArrayList names, ArrayList scores)

The main method should be very short. It should just declare and initialize the two arraylists and then invoke these three methods.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!