Assignment #121

Code

    
    ///Name: Cody Swain
    ///Period: 6
    ///Project Name: HighScore
    ///File Name: HighScore.java
    ///Date: 5/12/16
    
    
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Scanner;
    
    public class HighScore {
    
        public static void main( String[] args ) {
        
            Scanner keyboard = new Scanner(System.in);
            PrintWriter fileOut;
            int score;
            String name;
            
            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);
            }
            
            System.out.println("You got a high score!!!! " );
            System.out.print("Please enter your score: " );
            score = keyboard.nextInt();
            System.out.print("Please enter your name: ");
            name = keyboard.next();
            
            fileOut.println( name + " - " + score );
            fileOut.close();
            
            System.out.println("Data is stored into score.txt. Thank you play again. " );
            
        }
    }
            


    

Picture of the output

Assignment 121