• Post Reply Bookmark Topic Watch Topic
  • New Topic

code to track high scores  RSS feed

 
Adam Sainz
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a program that will track high scores. You will need to get the name and score of the player. All data will be stored in an external file. When your program starts, you will need to load all data from the file and before the program ends, you need to save the data back to the file. Other requirements are below.
• I have attached the code for the class “Score” You must use this file and cannot modify the class.
o You do not need to use all methods in the Class Score. Use only what you need.
• You need to create a menu were the user can select a number to run different parts of your code. Menu options should include:
1-Add a new score
2-Display a list of all scores
3-Display the TOP 10 scores
4-Exit
o Option 3 -Top 10 is Extra Credit +20.
o To support [tab]s in the Class Score, use the following line to print a message that contains '\t'.
JOptionPane.showMessageDialog(null, new JTextArea(msg));
you should allow the user to continue using the program until they select "Exit" from the menu.
• If a user enters a option not on the menu, your program should return an error to the user.
• All scores need to be integers.
• Since array have very strict uses and can't grow as you add new scores, you must use an ArrayList<Score> to store the player's name and score using the class Score.
o Array Lists have many helpful methods and can grow as needed. They can also store primitive data types up to complex objects like Classes. Page 467 in your book talks about ArrayList. Please review this diagram on the use of ArrayLists.





 
Carey Brown
Saloon Keeper
Posts: 3328
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a specific question?

This looks like a homework assignment, we will provide hints and guidance but we won't write it for you.
 
Indigo Montes
Greenhorn
Posts: 22
1
C++ IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adam Sainz wrote:

• I have attached the code for the class “Score” You must use this file and cannot modify the class.
o You do not need to use all methods in the Class Score. Use only what you need.



Whatever your question may be, be careful with your given class Score.
Its global variables are defined as public. This is a bad example of object oriented programming, because it defeats encapsulation. So, if you need to change/set values for myName and myScore, use the setter methods that are present in the Score class.
Do not use the variables directly like this:
 
Campbell Ritchie
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure that global variables is quite the right name for those fields; I think I would say that making the fields public makes them behave as global variables, but I agree that is a bad idea.
I also think it is a bad idea to use a String for the score.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!