Assignemnt #121 Score

Code

    /// Name: Caelan Dorstad
    /// Period: 6
    /// Program Name: score
    /// File Name: score.java
    /// Date Finished: 5/13/2016
    
    import java.util.Scanner;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.InputMismatchException;
    
    public class score{
        public static void main(String[] args){
            
            PrintWriter fileOut;
            int score = 0;
            String name;
            Scanner keyboard = new Scanner(System.in);
            
            System.out.print("Please enter your name: ");
            name = keyboard.next();
            
            do
            {
                try
                {
                    System.out.println();
                    System.out.print("Please enter your score: ");
                    score = keyboard.nextInt();
                }
                catch (InputMismatchException e){
                    System.out.println("ERROR");
                }
            } while (score<=0);
            
            
            
            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.println(name+": "+score);
            fileOut.close();
            
            System.out.println("SAVED!!");
        }
    }
            
                               

    

Picture of the output

Assignment 10