Assignemnt #121 High Score

Code

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

public class HighScore
{
    public static void main(String[] args)
    {
        PrintWriter fileOut;
        
        try
        {
            fileOut = new PrintWriter("score.txt");
        }
        catch (IOException e)
        {
            System.out.println("Error.");
            fileOut = null;
            System.exit(1);
        }
        
        Scanner keyboard = new Scanner(System.in);
        
        double score;
        String name;
        
        System.out.print("You got a high score!!!\n\nPlease Enter Your Score:  ");
        score = keyboard.nextDouble();
        System.out.print("Please Enter Your Name: ");
        name = keyboard.next();
        
        System.out.println("Data stored into score.txt. Thank you play again.");
        
        fileOut.println( "High Score!\n The score was: " + score + " set by " + name + "!" );
        
        fileOut.close();
    }
}
    

Picture of the output

Assignment 1