   import java.util.Scanner;
   import java.io.*;

/*******************************************************
*	Ryan Patterson
*	Jan 17, 2007
*	Section 2
*	Lab 3
*	This lab is designed to allow experimentation
*		with exceptions and how to handle them correctly.
*	ArrayIndexOutOfBoundsException, NumberFormatException,
********************************************************/

    public class Exceptions_Lab_patterrd_Handlers
   {
       public static void main(String args[])
      {
         int[] myArray;
         int user;
         int newNumber;
         FileReader freader;
         BufferedReader inputFile;
         String name;
         Scanner keyboard;
      
         myArray = new int[] {1, 2, 3, 4, 5, 6};
         keyboard = new Scanner(System.in);
      
      
         System.out.println("\nHere is a six(6) integer array.");
      
         try		//An example of an ArrayIndexOutOfBoundsException where the loop tries to
         {			//print an element that doesn't exist.
            for (int count = 0; count <= 6; count++)
            {
               System.out.println(myArray[count]);
            }
         }
             catch (ArrayIndexOutOfBoundsException aiobe)
            {
               System.out.println("Exception: Array Index Out Of Bounds At: " + aiobe.getMessage());
            }
      
      
      
         try		//This is an example of a NumberFormatException as the program trues to
         {			// turn a string of letters into a integer.
         
            System.out.print("What is your name? ");
            user = Integer.parseInt(keyboard.nextLine());
         
            System.out.println("\nYour name is " + user + ".");
         }
             catch (NumberFormatException nfe)
            {
               System.out.println("\nThere has been an exception in trying to initalize your name.");
               System.out.println("The exception was: " + nfe.getMessage());
            }
      	
      	
      	    
         System.out.print("What game would you like to play? ");
         name = keyboard.nextLine();
      	
         try		//This is a FileNotFoundException as the program cannot retrieve the correct file.
         {
            freader = new FileReader(name);
            inputFile = new BufferedReader(freader);
            System.out.println("\nThe file was found.");
         }
             catch (FileNotFoundException fnfe)
            {
               System.out.println("\nGame file not found.");
            }
      	
   	 System.out.println("The program ended correctly.");
      
      }	//end of main method
   }	//end of class