Assignment #121 and High Score!
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: Highscore
/// File Name: Highscore.java
/// Date Finished: 05/28/2016/
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Highscore
{
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 'receipt.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 = kb.nextInt();
System.out.print("Please enter your name: ");
String name = kb.next();
System.out.println("");
fileOut.print("Name: " + name);
fileOut.print("Score: " + score);
fileOut.close();
}
}
Picture of the output