Assignment #121: High Score

Code

import java.util.Scanner;
import java.io.PrintWriter;
import java.io.IOException;

public class HighScore {

    public static void main(String[] args) {
    
        PrintWriter output;
        
        try {
            
            output = 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?");
            output = null;
            System.exit(1);
            
        }
        
        Scanner kb = new Scanner(System.in);
        
        String name;
        
        int score;
        
        System.out.println("Congratulations! You got a high score! Please enter your score here: ");
        score = kb.nextInt();
        
        System.out.println("Please enter your name: ");
        name = kb.next();
        
        output.println("Name: " + name);
        output.println("Score: " + score);
        
        output.close();
        
    }
    
}
    

Picture of the output