Show High Scores

Learn how to show the top ten highest scores at the end of the game and also explore how to ask the user to play again.

Showing the top ten highest scores

The Word Builder program would be more helpful if it also showed the top ten scores.

  1. At the end of endGame(), remove the line of code that displayed the message. Add to message “TOP 10 HIGH SCORES\n:”.
  2. Loop through all the lines in records using ArrayList’s size() method. Add each element in records and a new line symbol to the message using ArrayList’s get() method. The new line symbol is “\n”.
  3. Display message in a message dialog using JOptionPane’s showMessageDialog().
    ...
 
  private void endGame() {
 
        ...
 
      saveRecords(records);
 
        (Code was removed from here.)
    }
    
    message += ________________;
    for(_________________) {
      message += __________________;
    }
    
    JOptionPane.___________________________;
  }
    ...

Get hands-on with 1200+ tech skills courses.