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 5 of 5

Thread: top 10 high score table

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default top 10 high score table

    I am 6 weeks into a java programming class and we have just been given our first major program to write.

    I need to be able to create a java program that keeps track of the top 10 scores. Basically, the program will ask you for a name and then a score and then store it in an array. You will be able to enter 10 names and 10 scores and the program will insert the name and score in the appropriate place in the table. If two people have the same score, it will keep the first person to score that amount above the second person to score the same.

    The only guidance I've got from the tutor is to create it all in a loop (you exit the program by typing in "quit" instead of a name. I was told that I will need an array to store the names and the scores and the program needs to start at position 10 and move up the table to find out the insertion point of where the new score should be placed. Once the insertion point in the table has been found, the program will shuffle all the other scores down one place, insert the new score and then go back to asking for a new name and score.

    I was told that this program can all be made within one class,using a keyboard input utility (import java.util.Scanner), and using only for, while, do-while loops, IF statements, compareto and .length for string handling.

    Does anybody have any idea how to go about it? All I can really do at the moment is have the program ask for a name and a number and store it.

    What do I need to be even looking at? Our guidance is very vague with no code examples at all on how to do anything other than create loops and setup an array. We have covered nothing about how to move values down the array. Obviously if you just moved a value out of a part of the array and placed it somewhere else in the array it would overwrite the value that is already there, not move it down and just delete the last one.

    The books I have read through tell you how to sort an array into ascending or descending order but not shuffle it all down one place.
    They also make use of importing a java utility to do it, the array.sort. The tutor specifically said the only utility we will need to import is the Scanner one.

    Any pointers, code snippets or any other help would be appreciated.
    Thanks.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: top 10 high score table

    Start with your idea:
    program ask for a name and a number and store it.
    When that works, work on the logic to order the names/numbers for the next step.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: top 10 high score table

    Do you have a tip for the type of logic I should be thinking about? I will need to check if the score is greater than the score in position 10 and work my way up until it comes across a score that it is less than. That will be my point to insert the new score into.
    I am inclined to think that I would need an IF statement inside of a For loop to find the insertion point?

    Having found that position, what type of logic would I be looking at to move the names and scores below the insertion point all down by one place and erasing the score at position 10?

    Thankfully it's not just me that's stumped by this program, the whole class is.
    Not a single one of us can even come up with a flowchart on how we'd go about it.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: top 10 high score table

    a tip for the type of logic I should be thinking about
    First understand the steps the code needs to do to solve the problem. Use a piece of paper and pencil and work through the steps the code needs to do.

    For a first step, write code to get the data from the user and put it in the array. Don't worry about sorting yet.
    Also for testing work with a shorter array to make the testing simpler. Later the array can be expanded. The logic will be the same.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Mar 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: top 10 high score table

    Ok thanks for the ideas. I will have a go at coding some of the beginning of the code.

Similar Threads

  1. How to display each score in a competition?
    By seaofFire in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 26th, 2012, 06:10 PM
  2. Noob, Collision Detection and Score
    By gkovr in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 24th, 2012, 07:53 PM
  3. Dice score program
    By ksahakian21 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 23rd, 2012, 05:25 PM
  4. How to get the list of highest score
    By pogi in forum Java Theory & Questions
    Replies: 4
    Last Post: July 1st, 2010, 09:50 PM
  5. Help with score board!
    By vlan in forum Java Applets
    Replies: 0
    Last Post: June 2nd, 2010, 04:34 AM