   import java.util.*;
   import java.io.*;
/**************************************************************
* This class contains a try catch block for 5 different exception
* types
* Author- Brian DeMarkis
* Date- 01/17/07
* Lab3
* Section 2  
* 
* 
**************************************************************/
    public class Exceptions_Lab_demarkbc_ExceptionHandling
   {
   /*************************************************************
   *this method is the main method and runs 5 different try/catch 
   *blocks to handle exceptions. 
   *
   * These exceptions include the 
   * FileNotFoundException, ArrayIndexOutOfBoundsException,
   * NumberFormatException, StringOutOfBoundsException, and the 
   * IllegalArgumentException.
   **************************************************************/
       public static void main (String [] args)
      {
         String filename;//name of a file to be looked up 
         Scanner fileScanner;
         int NumberFormatBad;
         int [] IndexNum = new int[4];// new array holding 4 integers
         Scanner keyboard;
         char character;
         double random;
         keyboard = new Scanner(System.in);// declares a new Scanner object to be system.in
         
         filename = "FileNotFoundException.txt";//assigns the filname string the name of a non exsistent file
         System.out.println("The filename is " + filename + "\n");// echos the filename
         try
         {
            fileScanner = new Scanner(new File(filename));//attempts to use filescanner to find the file under the filename variable
         
         }
             catch(FileNotFoundException fnfe)
            {
               System.out.println(filename + " was not found. FileNotFoundException. Try again\n");// handles the exception when the filename cannot be found
            }
      
         try
         {
            NumberFormatBad = Integer.parseInt(filename);// trys to convert the filename variable to an integer
         }
           
          
             catch(NumberFormatException nfe)
            {
               System.out.println("Cannot convert this string " + filename+
                  " to an integer. NumberFormatException.\n");// handles the NumberFormatException because a non numerical string cannot be converted to an integer
            }
         try
         {
            for(int index = 0; index < 5; index++)// creates a for loop so that the array of integers can be created
            {
               System.out.println(" Enter the integer to store in the array ");
               IndexNum[index] = keyboard.nextInt();// assigns the entered number to the current element in the array 
            }
         }
             catch(ArrayIndexOutOfBoundsException aioob)
            {
               System.out.println(" There are too many Elements trying to be stored in the array. ArrayIndexOutOfBoundsException\n");// Handles the exception, because the user is prompted to enter 5 elements in a 4 element array 
            } 
         try
         {
            character = filename.charAt(56);//trys to get the 56 characters of the filname string
         }
             catch(StringIndexOutOfBoundsException sioob)
            {
               System.out.println(" You are trying to access a character from a position that is longer" + 
                  " than the string specified, " + filename + ". StringOutOfBoundsException\n");//handles the StringIndexOutOfBoundException because the string is not 56 characters long and the user attempted to access a character out of bounds 
            }
         try 
         {
            NumberFormatBad = Integer.parseInt(filename);//trys to parse a String to an int
         }
           
             catch(IllegalArgumentException ia)
            {
               System.out.println(" Bad Number Format. Illegal Argument being passed is " + filename + ". IllegalArgumentException");// handles the exception and shows that the NumberFormatException showed above is inherited from the IllegalArgumentException
            }
         try
         {
            for(int index = 0; index < 5; index++)// creates a for loop so that the array of integers can be created
            {
               System.out.println(" Enter a letter to store in the array ");// tells user to enter a letter
               IndexNum[index] = keyboard.nextInt();// assigns the entered number to the current element in the array 
            }
         }
             catch(InputMismatchException im)
            {
               System.out.println("The input does not match the correct type required for the array. InputMismatchException.");// since a letter cannot be sotred in an integer array the exception has to be handled
            }
         System.out.println("The program has ended normally");//ending statement
         {
         
         
         
         
         }
      }
   }