Assignment #121
Code
/// Name: Matthew Lorence
/// Period: 5
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class HighScore {
public static void main(String[] args) {
PrintWriter fileOut;
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);
}
Scanner keyboard = new Scanner(System.in);
fileOut.println( "You got a high score!!!!" );
System.out.print("Name: ");
String name = keyboard.next();
System.out.print("Score: ");
int score = keyboard.nextInt();
fileOut.println( name + " " + score );
fileOut.close();
}
}
Picture of the output