Assignment #121 and High Score
Code
///Name: Tim Gibson
///Period: 6
///Project Name: High Score
///File Name: Receipt.java
///Date Finished: 1/14/16
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Score
{
public static void main ( String[] args )
{
PrintWriter fileOut;
Scanner kb = 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);
}
int s;
String n;
System.out.print("You got a high score!!!!! \n\nPlease enter your score: " );
s = kb.nextInt();
System.out.print( "Please enter your name: " );
n = kb.next();
fileOut.println( "Score: " + s + " Name: " + n );
fileOut.close();
System.out.println("\nData stored into score.txt. Thank you play again." );
}
}
Picture of the output