Assignment #121 and High Score
Code
///Name: Ali Kurland
/// Period: 6
/// Program Name: High Score
/// File Name: Score.java
/// Date Finished: 4/18/2016
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Score {
public static void main(String[] args) {
PrintWriter fileOut;
Scanner keyboard = new Scanner(System.in);
try{
fileOut = new PrintWriter("score.txt");
} catch(IOException e) {
System.out.println("Sorry, I can't open the file 'score.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: ");
int score = keyboard.nextInt();
System.out.print("Please enter your name: ");
String name = keyboard.next();
fileOut.println( "High Score:" );
fileOut.println( "" );
fileOut.println( "Name: " + name );
fileOut.println( "Score: " + score );
fileOut.close();
System.out.println("");
System.out.println("Data stored into score.txt. Thank you and play again.");
System.out.println("");
}
}
Picture of the output