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.
We'll cover the following
Showing the top ten highest scores
The Word Builder program would be more helpful if it also showed the top ten scores.
- At the end of
endGame()
, remove the line of code that displayed the message. Add to message “TOP 10 HIGH SCORES\n:”. - 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’sget()
method. The new line symbol is “\n”. - Display
message
in a message dialog using JOptionPane’sshowMessageDialog()
.
...
private void endGame() {
...
saveRecords(records);
(Code was removed from here.)
}
message += ________________;
for(_________________) {
message += __________________;
}
JOptionPane.___________________________;
}
...
Get hands-on with 1200+ tech skills courses.