Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I need help with java

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need help with java

    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 score in a data structure of your choice (the most straightforwar 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
    10400
    Didier
    9800
    Pele
    9750
    Kaka
    8400
    Cristiano
    8000

    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, in 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.
    • String[] getTopNames(): Returns an array of the names of the top players, with the top player first, the second best player second, etc.
    • Int[] getTopScores(): Returns an array of the scores of the top players, with the highest score first, the second highest 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.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: I need help with java

    I need help with java
    So what is it you need help with?

Tags for this Thread