title: Sorting an ArrayList of top scores
body: <pre><code>import java.util.ArrayList;
  import java.util.Scanner;
  
  public class Assignment5
  {
      public static void initialize(ArrayList&lt;String&gt; names, ArrayList&lt;Integer&gt; scores)
      {
         // Create a Scanner object for keyboard input.
         Scanner keyboard = new Scanner (System.in);
  
         // Ask the user for the names and scores for 5 people.
         System.out.println("Enter the name for score #1: ");
         names.add(keyboard.next());
         System.out.println("Enter the score for score #1: ");
         scores.add(keyboard.nextInt());
         System.out.println("Enter the name for score #2: ");
         names.add(keyboard.next());
         System.out.println("Enter the score for score #2: ");
         scores.add(keyboard.nextInt());
         System.out.println("Enter the name for score #3: ");
         names.add(keyboard.next());
         System.out.println("Enter the score for score #3: ");
         scores.add(keyboard.nextInt());
         System.out.println("Enter the name for score #4: ");
         names.add(keyboard.next());
         System.out.println("Enter the score for score #4: ");
         scores.add(keyboard.nextInt());
         System.out.println("Enter the name for score #5: ");
         names.add(keyboard.next());
         System.out.println("Enter the score for score #5: ");
         scores.add(keyboard.nextInt());
      } 
  
      public static void sort(ArrayList&lt;String&gt; names, ArrayList&lt;Integer&gt; scores)
      {
      }
  
      public static void display(ArrayList&lt;String&gt; names, ArrayList&lt;Integer&gt; scores)
      {
         for (int index = 0; index &lt; names.size(); index++)
         {
            String userNames = names.get(index);
            System.out.println(names.get(index));
         }
  
         for (int index = 0; index &lt; scores.size(); index++)
         {
            Integer userScores = scores.get(index);
            System.out.println(scores.get(index));
         }
      }
  
      public static void main(String[] args)
      {
         // Create an ArrayList for names and scores.
         ArrayList&lt;String&gt; names = new ArrayList&lt;String&gt;();
         ArrayList&lt;Integer&gt; scores = new ArrayList&lt;Integer&gt;();
  
         // Call the three methods.
         initialize(names, scores);
         sort(names, scores);
         display(names, scores);
      }
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>The output from your program should look approximately like this:</p>
  
  <p>Enter the name for score #1: Suzy</p>
  
  <p>Enter the score for score #1: 600</p>
  
  <p>Enter the name for score #2: Kim</p>
  
  <p>Enter the score for score #2: 9900</p>
  
  <p>Enter the name for score #3: Bob</p>
  
  <p>Enter the score for score #3: 1012</p>
  
  <p>Enter the name for score #4: Armando</p>
  
  <p>Enter the score for score #4: 8000</p>
  
  <p>Enter the name for score #5: Tim</p>
  
  <p>Enter the score for score #5: 514</p>
  
  <p>Top Scorers:</p>
  
  <p>Kim: 9900</p>
  
  <p>Armando: 8000</p>
  
  <p>Bob: 1012</p>
  
  <p>Suzy: 600</p>
  
  <p>Tim: 514</p>
  
  <p>Requirements</p>
  
  <p>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.</p>
  
  <p>All of the user input should be done in a method named InitializeArrays. It should have the following signature:</p>
  
  <p>public static void InitializeArrays(ArrayList names, ArrayList scores)</p>
  
  <p>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:</p>
  
  <p>public static void sort(ArrayList names, ArrayList scores)</p>
  
  <p>Finally you should write a method that displays the contents of the two array lists. It should have the following signature:</p>
  
  <p>public static void display(ArrayList names, ArrayList scores)</p>
  
  <p>The main method should be very short. It should just declare and initialize the two array lists and then invoke these three methods.</p>
  
  <p>.......As of now I have only created two arraylists and can store the names and scores. I am not certain on how I can sort and display them correctly. I've noticed people have created comparators for similar situations, but we haven't covered that yet in the class.</p>