Assignment #121 High Score

Code

    /// Name: Koosha Kimelman
    /// Period: 7
    /// Program Name: High Score
    /// File Name: HighScore.java
    /// Date Completed: 5/23/16
    
    import java.util.Scanner;
    import java.io.IOException;
    import java.io.PrintWriter;
    
    public class HighScore {
    
        public static void main(String[] args) {
        
            PrintWriter fileOut;
            Scanner k = new Scanner(System.in);
            
            System.out.println("You got a high score.\n");
            
            System.out.print("Please enter your score: ");
            int s = k.nextInt();
            System.out.print("\nPlease enter your name: ");
            String n = k.next();
            
            try {
                fileOut = new PrintWriter("score.txt");
            } 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.print("High score: " + s + " by " + n);
            fileOut.close();
            
            System.out.println("\n\nData stored into score.txt. Thank you play again.");
        }
    }
    

Picture of the output

Assignment 121 Assignment 121