   import java.util.*;
   import java.io.*;
/***********************************************
 * This class will cause 5 different exceptions and handle each one.
 *
 * @author - Vicente Rosa
 * @version - V1
 ************************************************/
 /* Date: January 17, 2007
 /  Section 3
 /  Lab3
 /  
 /  References and Ackknowledgements: I have recieved
 /  no help on this programming assignment
 /
 /  Lab by Elizabeth Adams and Nancy Harris
 /***********************************************/
    public class Exceptions
   {
   /********************************************
    * This is the main method in which the exceptions will be caused and handled
    *
    * @param No Parameters
    * @return Prints to I/O screen with completed exceptions handled.
    *********************************************/
       public static void main(String args[])
      {
         String letters = "ifndois";
         double num;
         String fileName;
         String fileNameWork;
         Scanner fileNF;
      
      //This block of code is going to attempt to read past the index of the array.
         try
         {
            int size = 4; //array size
            int[] numbers = new int[size];
            System.out.println("The program will now attempt to add 5 ints into an array with a size of 4");
            for (int i = 0; i <= size; i++)//starting with 0 but going to 4 (out of bounds)
            {
               System.out.println("We are now storing an int into the array at the index " + i);
               numbers[i] = 22;
            }
         
         }
         //The catch block is going to catch the exception and handle it preventing the program from crashing.
             catch (ArrayIndexOutOfBoundsException aioobe)
            {
               System.out.println("You have attempted to store more information into an array than there is space."); 
            }
      
      //Here we are going to try and create and array with a negative size to cause an exception.
         System.out.println("\nWe are going to try and create a negative sized array.");
         try
         {	
            int size = -2; //Creating a negative size
            System.out.println("The size of the array is " + size);
            int[] numbers = new int[size];
         }
             catch (NegativeArraySizeException nase)
            {
               System.out.println("It appears that you have requested the siZe for an array to be negative.  That is not possible.");
            }
      //Here we are going to try and read at an index way out of bounds.
         System.out.println("\nWe are going to search at an index out of bounds of the String");
         try
         {
            char stringChar;
            int indexNum = 123;
            System.out.println("You attempted to find a character at the index " + indexNum);
            stringChar = letters.charAt(indexNum);
         
         }
             catch (StringIndexOutOfBoundsException sioobe)
            {
               System.out.println("There is no character at the index you requested.  Please check where you are searching.");
            }
      
      //Here we are going to cause an exception by trying to format a string into a double.
         System.out.println("\nHere we are asking the program format a string into a double.");
         try
         {
            System.out.println("The string we are trying to format is '" + letters + "'");
            num = Double.parseDouble(letters);//Cannot format a string into a double.
         }
             catch (NumberFormatException nfe)//Handles error.
            {
               System.out.println("A format error has occured.  Please check the item you are trying to format.");
            }
      
      //This block will attempt to find a file that DNE.
         try
         {
            fileName = "LookForMePlease.txt";
            System.out.println("\nWe are now creating the Scanner object which will refer to '" + fileName + "'");
            System.out.println("The program will attempt to find and access the file '" + fileName + "'");
         
            fileNF = new Scanner(new File(fileName));
         
         }
             catch (FileNotFoundException fnfe)
            {
               System.out.println("The computer cannot seem to locate your file.  Please check its location.");
            }
      
      
         System.out.println("\nThis program has ended normally.");
      }
   }  
