 import java.util.Scanner;
 import java.io.*;
 import java.util.*;
/**********************************************************************
 * This class will run try catch blocks to catch certain exceptions that
 * might arise.  The exceptions will be in this order:
 * FileNotFoundException
 * ArrayIndexOutOfBoundsException
 * InputMismatchException
 * ArithmeticException
 * NegativeArraySizeException
 * 
 * @author  Justin Cruz
 * @version V1
 **********************************************************************
 * Name: Justin Cruz
 * Date: 1-17-07
 * Lab #: 3
 * Section: 1
 *********************************************************************/
    public class Exceptions_Lab_cruzja_ExceptionCatcher
    {
    /****************************************************************
    * This main method will be used to run the Exception Catcher 
    *
    * @param args Command line arguments, ignored
    *****************************************************************/
      public static void main(String[] args)
      {
			Scanner keyboard;  
			int number;
			int answer;
			FileReader freader;		// Used when throwing FileNotFoundException 
			String file;
			int[] array1 = {1, 2, 3, 4, 5};
			int[] array2;
			
			keyboard = new Scanner(System.in);
			
			// This try catch block is used to create a FileNotFoundException
         try
         {
            System.out.print("Enter The Name Of The File That Has Integer Data: ");
				file = keyboard.nextLine();
				System.out.println("You entered: " + file);
				
				freader = new FileReader(file);
         }
         catch (FileNotFoundException fnfe)
         {
            System.out.println("The file you entered was not found.\n");
        	}

			
			// This try catch block is used to create a ArrayIndexOutOfBoundsException
			try
			{
				for(int x = 0;x < 6;x++)  // Intentionally runs the array out of bounds
					System.out.println("Index " + x + " is " + array1[x]);
			}
			catch (ArrayIndexOutOfBoundsException aioobe)
			{
				System.out.println("The array went out of bounds.\n");
			}
			
			
			// This try catch block is used to create a InputMismatchException
			try
			{
				System.out.print("Enter An Integer Value: ");
				number = keyboard.nextInt();
				System.out.print("You entered: " + number + "\n\n");
			}
			catch(InputMismatchException ime)
			{
				System.out.println("You enter a value that wasn't an integer.\n");
			}
			

			// This try catch block is used to create a ArithmeticException	
			// The hope is here that the user will enter a zero to get the exception
			try
			{
				keyboard.nextLine();
				System.out.println("15 divided by x");
				System.out.print("Enter a value for x: ");
				number = keyboard.nextInt();
				System.out.println("You entered " + number);
				answer = 15 / number;		// Here is where the division by 0 should occur
				System.out.println("15 divided by " + number + " is " + answer);
			}
			catch(ArithmeticException ae)
			{
				System.out.println("You have entered invalid data");
			}
			catch(InputMismatchException ime) // This is here just in case the user enters wrong input
			{
				System.out.println("You have entered invalid data");
			}
		
			
			// This try catch block is used to create a NegativeArraySizeException
			try
			{
				keyboard.nextLine();
				System.out.print("\nEnter a size of an array: ");
				number = keyboard.nextInt();
				array2 = new int[number];		// This is where the negative array should be made
				System.out.println("The array has been created.");
			}
			catch(NegativeArraySizeException nase)
			{
				System.out.println("The number you entered as the array size was negative");
			}
			catch(InputMismatchException ime) // This is here just in case the user enters wrong input
			{
				System.out.println("You have entered invalid data");
			}
      } 
   }