Assignment #121 High Score
Code
/// Name: John Huh
/// Period: 6
/// Program Name: HighScore
/// File Name: HighScore.java
/// Date Finished: 5/11/2016
import java.util.Scanner;
import java.io.IOException;
import java.io.PrintWriter;
public class HighScore {
public static void main(String[] args) {
PrintWriter fileOut;
Scanner keyboard = new Scanner(System.in);
int score;
String name;
System.out.println();
System.out.println( "You got a high score!!!!" );
System.out.println();
System.out.print( "Please enter your score: " );
score = keyboard.nextInt();
System.out.print( "Please enter your name: " );
name = keyboard.next();
System.out.println();
System.out.println( "Data stored into score.txt. Thank you play again." );
System.out.println();
try{
fileOut = new PrintWriter("score.txt");
} catch(IOException e) {
System.out.println("Sorry, I can't open the file 'receipt.txt' for editing.");
System.out.println("Maybe the file exists and is read-only?");
fileOut = null;
System.exit(1);
}
fileOut.println( "High Score" );
fileOut.println();
fileOut.println( "User: " + name );
fileOut.println();
fileOut.println( "Score: " + score );
fileOut.close();
}
}
Picture of the output