Score

Code

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

public class Score {

    public static void main(String[] args) {
        
        Scanner keyboard = new Scanner(System.in);
        
        PrintWriter fileOut;
        
        int Score;
        Score=0;
        String Name="";
        
        try{
            fileOut = new PrintWriter("Score.txt");
            
        System.out.print(" Please enter your score: ");
        Score=keyboard.nextInt();
        
        System.out.println(" ");
        
        System.out.print(" Please enter your name " );
        Name=keyboard.next();

        } 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);
        }

        
        
        fileOut.println( "---------------------------------" );
        fileOut.println( "   Score: " + Score );
        fileOut.println( " " );
        fileOut.println( "   Name: " + Name );
        fileOut.println( "---------------------------------" );
        
        fileOut.close();
        
    }
}
        

Score

Assignment 121