I created a game a random guessing game ( for school project ) . I just want to ask on how to put a hall of fame? Like when you played the game then its end it will be putted his/her name then it will be saved. Then it will be based on which is greater than. Just tell me what should i need to took. Then i will make an algorithm on it! But if your soo kind you can make it LOL :)) . THANKS ALOT.

## All 10 Replies

I created a game a random guessing game ( for school project ) . I just want to ask on how to put a hall of fame? Like when you played the game then its end it will be putted his/her name then it will be saved. Then it will be based on which is greater than. Just tell me what should i need to took. Then i will make an algorithm on it! But if your soo kind you can make it LOL :)) . THANKS ALOT.

Hmm why not save the score at the end of the game including the players name to a text file, then on start up or when the user presses to ask to see the hall of fame you can read in the entries from the text file into two arrays one for the name, another for the score, (or maybe a 2d array) and list them according to their high scores, that will be done by a simple if else statement checking the condition if the one is greater or less then the other and saving the value that is greater to a new array which will hold the sorted values of the scores-highest to lowest. That's how i would do it, though there are many alternatives, but one thing will remain constant, the storing of the scores in a file and reading from the file etc

Hmm why not save the score at the end of the game including the players name to a text file, then on start up or when the user presses to ask to see the hall of fame you can read in the entries from the text file into two arrays one for the name, another for the score, (or maybe a 2d array) and list them according to their high scores, that will be done by a simple if else statement checking the condition if the one is greater or less then the other and so on

How ?? I'm still new on java language :((((((((((

How ?? I'm still new on java language :((((((((((

well Google will always help hey but to start you off: heres a link to read text files:http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml then here is another link that will take the reading of the file one step further(putting it into an array):http://www.java-forums.org/new-java/7001-reading-text-file-into-array.html, and finally here is a link on writing to text files:http://www.abbeyworkshop.com/howto/java/writeText/index.html and then here just for the cherry on top is a small example of comparing variables for Highest and lowest values:http://www.roseindia.net/java/beginners/largernumber.shtml
Hope its enough to get you started...

well google will always help hey but to start you off: Heres a link to read text files:http://www.roseindia.net/java/beginners/java-read-file-line-by-line.shtml then here is another link that will take the reading of the file one step further(putting it into an array):http://www.java-forums.org/new-java/7001-reading-text-file-into-array.html, and finally here is a link on writing to text files:http://www.abbeyworkshop.com/howto/java/writetext/index.html and then here just for the cherry on top is a small example of comparing variables for highest and lowest values:http://www.roseindia.net/java/beginners/largernumber.shtml
hope its enough to get you started...

thanks alot dude!!

How do i add a new line at this code? Like i want to put a new string/variable in the same text file?
Here's my code. I still don't have an idea how would i put it.

``````import java.io.*;

public class WriteTextFileExample{
public static void main(String[] args)throws IOException{
int anArray[]  = new int[100];
Writer output = null;
System.out.print("Write your name: ");
String text = a;
File file = new File("Name.txt");
output = new BufferedWriter(new FileWriter(file));
output.write(text);
output.close();
System.out.println("Your file has been written");

System.out.print("Write your name: ");
String number = guess.readLine();
String numberdefine = number;
File scores = new File("Scores.txt");
output = new BufferedWriter(new FileWriter(scores));
output.write(numberdefine);
output.close();
System.out.println("Your file has been written");

}
}``````

How do i add a new line at this code? Like i want to put a new string/variable in the same text file?
Here's my code. I still don't have an idea how would i put it.

``````import java.io.*;

public class WriteTextFileExample{
public static void main(String[] args)throws IOException{
int anArray[]  = new int[100];
Writer output = null;
System.out.print("Write your name: ");
String text = a;
File file = new File("Name.txt");
output = new BufferedWriter(new FileWriter(file));
output.write(text);
output.close();
System.out.println("Your file has been written");

System.out.print("Write your name: ");
String number = guess.readLine();
String numberdefine = number;
File scores = new File("Scores.txt");
output = new BufferedWriter(new FileWriter(scores));
output.write(numberdefine);
output.close();
System.out.println("Your file has been written");

}
}``````

to add new line:

``output.write("\r\n\r\n");``

Which part?

Which part?

the above code is to add a new line

``````String variable="yup im it :)";
...
output = new BufferedWriter(new FileWriter(scores));
output.write(numberdefine);
output.write("\r\n\r\n");//new line
output.write(variable);//here is the new string you want to write
output.close();
...``````

How do i make that everytime someone wins they will save the name and the score without using another Write Text File? HEELP.

How do i make that everytime someone wins they will save the name and the score without using another Write Text File? HEELP.

Can you elaborate further?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.