• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating a Score List and High Score list?  RSS feed

 
Aarden Axford
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The title says it all. I am creating a program called "Mad Math Machine". This program is to generate random arithmetic questions, with integers ranging from -12 to 12, for the user to answer. The user has three lives. Once they get more than three questions wrong, they run out of lives, and their "score" (the number of questions they answered correctly) is taken.

I have the large chunk of the program (the arithmetic questions and answers) completed. The only part I am stuck on is the scoring system. I believe that arrays would be useful for this task, but I have little idea of where to start. Here is what the scoring list should be able to do:

- It should print out the top ten recent players and their scores.
- A separate list should show the top-two highest scores of all time.

I don't want a whole answer to this question, but rather if someone could point me in the right direction? I have no ideas where to start, or how this could be accomplished, besides the fact that I realise that arrays may be useful here. Any help and tips are appreciated! Thanks everyone!

*I didn't think it was relevant, but I can include the program code. Up until this point, I have created methods to keep track of the score, but I have simply left them commented out so I could build the rest of the program.*
 
Joren Uitzetter
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have Player objects?
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You need to get rid of silicon‑based technology and forget there are such things as arrays at all. Use carbon‑based technology, remembering the middle of a pencil is carbon! You will also need paper and an eraser (also mostly carbon). You will probably find the eraser is used more than the pencil. Write down very simply how you would do it without a computer, only some sheets of paper. Once you have got that worked out, you will probably find it easy to turn into code.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aarden Axford wrote:Up until this point, I have created methods to keep track of the score, but I have simply left them commented out so I could build the rest of the program.

My advice: Don't do that. If you don't have a "body" for a method, simply have it throw UnsupportedOperationException until you're ready to code it. That way, your API is complete, and other objects can happily call the method if they need to. If you keep "uncommenting" methods, it'll be changing all the time.

And as long as throwing the exception is the only thing you do, the method will compile just fine.

It's called "stubbing" - at least, that's what I call it...

Winston
 
Matt Matthews
Greenhorn
Posts: 18
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:
Aarden Axford wrote:Up until this point, I have created methods to keep track of the score, but I have simply left them commented out so I could build the rest of the program.

My advice: Don't do that. If you don't have a "body" for a method, simply have it throw UnsupportedOperationException until you're ready to code it. That way, your API is complete, and other objects can happily call the method if they need to. If you keep "uncommenting" methods, it'll be changing all the time.

And as long as throwing the exception is the only thing you do, the method will compile just fine.

It's called "stubbing" - at least, that's what I call it...

Winston


I get the concept of using methods within the class he is using to track scores. As a student myself, is it best to keep it this way or would it be viable to create a new class that will only handle scores?
Or does creating a scoreResults class just complicate things?
 
Campbell Ritchie
Marshal
Posts: 56584
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. It is quite hard to create too many classes and quite easy to create too few. Creating a Score class which encapsulates the score and player sounds a good idea. And a HighestScore class, too. You can enhance your highest score class to encapsulate n Scores. But that sort of thing depends on the design of the remainder of your app.
 
Aarden Axford
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies for not replying for an extended period of time. I am still working on this project, however. I got to the point where it will print out an array with space for ten scores. However, each time I run the program, it deletes the last user to play. For example, the user plays the game and receives a score of 7:

Name: Martin
Score: 7

^ The above prints out. Next time the program runs, it should look like this:
Name: Jackie
Score: 9
Name: Martin
Score:7

But in my program, Martin is deleted the second time the program runs. I am unsure of how to fix this...
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aarden Axford wrote:But in my program, Martin is deleted the second time the program runs. I am unsure of how to fix this...

Applications are simple processes that must be loaded into the computer's workspace (RAM) where they are brought to life to perform its job and then it dies(terminates)...
When the process dies, all information is lost unless you transfer that information to some persistent storage device...
Therefore you will need to save the state of your application either in a file on the file-system or in a database...
For this purpose you can use either Serialization for the file storage mechanism or Oracle Java DB for the database storage...
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to post your code at this point (use code tags and indent).
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rico Felix wrote:Therefore you will need to save the state of your application either in a file on the file-system or in a database...
For this purpose you can use either Serialization for the file storage mechanism or Oracle Java DB for the database storage...

Or a simple text flat file.
 
Aarden Axford
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


There it is. The problems are now arising in the nameChange and scoreChange methods. I genuinely have no idea what I am doing at this point. :P
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
scoreChange() and nameChange() should have the same logic if you want them to be in sync.
At this point it might be useful to do a little bit of refactoring. Create a Player class that has both a name field and a score field. Replace highScore[] and highScoreName[] with a highScorePlayers[].
If you want to save & restore high score games you'll need a saveScores() method and a loadScores() method. I suggest using a simple flat file for the persistent storage.
Seems like on line 45 you wouldn't want to bail on on menu choice '1'. you should be able to start another game.
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your use of 'static' (fields and methods) should be undone. Your main() method should create an instance of a MadMathMinute object and invoke a MadMathMinute.run() method (for example) which will replace what is now your main() method.

Rather than having a field called arithmeticAnswer, why not use the arithmeticAnswer as returned by displayNewQuestion()?
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aarden Axford wrote:I genuinely have no idea what I am doing at this point. :P

You are not the first and won't be the last to this phenomenon... This state of confusion is the result of lack of planning and design...
A system can only be implemented after it has been carefully thought about which consists of the fundamental elements of requirements analysis and design specification...
As the elder Campbell Ritchie has suggested... Your best bet to completing this project successfully with satisfying results, you should ditch the ad-hoc design and implementation and return back to the drawing board...
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll also add the definition of a system which is a set of interacting, interrelated, interdependent components that function as a whole to achieve specific objectives...
Therefore you must identify the components of your system that you are trying to model and determine how they will interact, in what way components are dependent on other components to accomplish its task and how all these components are related to each other...
So you should cast your mind on the four buzzwords of solid modern design: Abstraction, Encapsulation, Inheritance and Polymorphism...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!