Assignment #121
Code
/// Name: Jonathan Stine
/// Period: 5
/// Program Name: High Score
/// File Name: HighScore.java
/// Date Finished: 4/28/2016
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class HighScore {
public static void main( String[] args ) {
Scanner keyboard = new Scanner( System.in );
PrintWriter fileOut;
int score;
String name;
try{
fileOut = new PrintWriter("highScore.txt");
} catch(IOException e) {
System.out.println("Sorry, I can't open the file 'highScore.txt' for editing.");
System.out.println("Maybe the file exists and is read-only?");
fileOut = null;
System.exit(1);
}
System.out.println( "You got a high score!!!!" );
System.out.println();
System.out.print( "Please enter yout 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." );
fileOut.println( "High Score: " + score );
fileOut.println( "Name: " + name );
fileOut.close();
}
}
Code Output