Hi I am currently working on a game in Java, that tests the users ability to work better with our without music for analyzing. I am using write file and created a .txt file to save the results. I was unsure how do i create headings for the saved results such as First name: Second Name. I am also a little lost as to calculate a percentage from the results. The results are stored in variables, Score and Score 2 i simply would like to display the percentage of the results. Thank you.
if(Globals.score2 > Globals.score) {
//Better with music
MessageBox.infoBox("You scored " + Globals.score + " without music & " + Globals.score2 + " with music!\n" + "You seemed to concentrate better while music was playing!" , "Score");
} else if (Globals.score2 < Globals.score) {
//Better Without Music
MessageBox.infoBox("You scored " + Globals.score + " without music & " + Globals.score2 + " with music!\n" + "You seemed to concentrate better without any music playing!" , "Score");
} else {
//Equal Reults
MessageBox.infoBox("You scored " + Globals.score + " without music & " + Globals.score2 + " with music!\n" + "Your concentration stayed the same through each play through!" , "Score");
}
// JOptionPane.showMessageDialog(frame, "Your score for game one was" + "" + Globals.score2 );
new FinalScore().setVisible(true);
this.dispose();
AudioPlayer.player.stop(as);
toolkit.beep();
timer.cancel(); //Not necessary because we call System.exit
//System.exit(0); //Stops the AWT thread (and everything else)
//CODE FOR WRITING TO FILE
public class WriteFile {
public static void SaveGame() throws IOException {
String content = (Globals.IDUser + ", " + Globals.firstName + ", " + Globals.lastName + ", " + Globals.userAge + ", " + Globals.eThnic + ", " + Globals.maleOrFem + ", " + " In the first game you scored, " + Globals.score + ", " + " In the second game you scored." + Globals.score2);
File file = new File("ResultsSaves.txt");
// if file exists, then overwrite current saved file with new
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.newLine();
bw.close();
JOptionPane.showMessageDialog(null, "Your details have been saved!");
}
}
}