   import java.util.Scanner;
   import java.io.*;
   import java.util.*;
   import java.lang.*;
/***********************************************
 * causes and handles 5 exceptions
 *
 * @author -Jason Crownover
 * @version - V1
 ************************************************/
 //Section3
 //1/17/07
 //Exceptions
 
    public class Exception
   {
   /********************************************
    * causes and handles 5 exceptions
    *
    * @param args not used
    *********************************************/
       public static void main(String args[])
      {
         String fileName;
         Scanner fileScanner;
         Scanner keyboard;
         int userint;
         int filevalue;
         int intarray[] = {1, 2, 3,};
			
			try //trys to create an array of negative size
			{
			int[] negarray = new int[-1];
			}
      	catch(NegativeArraySizeException nase)
			{
			System.out.println("This array has a negative size");
			}
      	
      	
         keyboard = new Scanner (System.in);
      	
			System.out.println(" ");
			
			// trys to ask user for an integer
         try
         {
            System.out.println(" Please enter an integer ");
            userint = keyboard.nextInt();
         }
         // handles an exception if input is not an integer
             catch (InputMismatchException ime)
            {
               System.out.println(" You did not enter an integer");
            }
      	 
         System.out.println(" ");
      	 
         keyboard.nextLine();
			
			//asks the user for a file name    
         System.out.println (" Please enter name of file holding integers and hit return ");
         fileName = keyboard.nextLine();
      
         System.out.println (" The name of the file you want to open is " + fileName);
      	
			// trys to open the file the user entered
         try
         { 
            fileScanner = new Scanner (new File (fileName));
            while (fileScanner.hasNextInt()) 
            {
               filevalue = fileScanner.nextInt();
               System.out.println (" The value you got from the file is " + filevalue);
            }
         }  
			// handles an exception if the file is not found
             catch (FileNotFoundException fnfe)
            {
               System.out.println (" The file you wanted to open could not be found ");
            }
      		
         System.out.println(" ");
      		
         System.out.println(" Enter an integer to divide by");
         userint =  keyboard.nextInt();
      	
			// trys to divide 10 by a given integer
         try
         {
            System.out.println(" 10 / " + userint + " = " + 10/userint);
         }
			// handles an exception if input is 0
             catch(ArithmeticException db0)
            {
               System.out.println(" You have attempted to divide by 0");
            }
      	
         System.out.println(" ");
      	
			// trys to look at the values in an array
         try
         {
            for (int i = 0; i <= 3; i++)
            {
               System.out.println(intarray[i]);
            }
         }
			//handles an array index out of bounds exception due 
			//to an off by one error in the for loop
             catch(ArrayIndexOutOfBoundsException aioobe)
            {
               System.out.println(" This Array has gone out of bounds");
            }
				

				
				
				
      		
      }
   }
		
