Assignemnt #121: High Score
Code
/// Name: Cassie Rapp
/// Period: 6
/// Program Name: High Score
/// File Name: score.java
/// Date Finished: 6/9/2016
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class score {
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 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." );
fileOut.println( "High Score: " + score );
fileOut.println( "Name: " + name );
fileOut.close();
}
}
Picture of the output