Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java language Write a class that keeps track of the top five high scores that could be used for a video game. Internally, the class

image text in transcribed

java language

Write a class that keeps track of the top five high scores that could be used for a video game. Internally, the class should store the top scores in a data structure of your choice (the most straightforward way is to use arrays). Each entry consists of a name and a score. The data stored in memory should be synchronized with a text file for persistent storage. For example, here are the contents of a sample file where Ronaldo has the highest score and Pele has the third highest score: Ronaldo 1848 Didier 9889 Pele 9750 Kaka 8480 Cristiano 8300 The constructor should test if the file exists. If it does not exist, then the file should be created with blank names for each of the players and a score of 0. If the file does exist, then the data from the file should be read into the class's instance variables. Along with appropriate constructors, accessors, and mutators, add the following methods: void playerScore(String name, int score: Whenever a game is over, this method is called with the player's name and final score. If the name is one of the top five, then it should be added to the list and the lowest score should be dropped out. If the score is not in the top five, then nothing happens. Stringll getTopNames0: Returns an array of the names of the top players, with the top player first, the second best player second, etc. intu get opScores : Returns an array of the scores of the top players, with the highest score rt, the secon ighest score second, etc Test your program with several calls to playerScore and print out the list of top names and scores to ensure that the correct values are stored. When the program is restarted, it should remember the top scores from the last session

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions