   import java.io.*;
   import java.util.*;
/******************************************************************
* This class handles 5 execptions FileNotFoundException, ArrayOutOfBoundsException,
* NumberFormatException, StringIndexOutOfBoundsException , ArithmeticException.
*
* @author - Andrew Kelley
* @version - V1 - 01/17/07
*******************************************************************/
//Andrew Kelley
//01/10/07
//Lab 2
//MW 2:30

    public class Exceptions
   {
   
       public static void main(String args [])
      {
		 
         FileReader freader;
         char character;
         String andrew;
         int number;
         int num;
         int[] array = {1,2,3,4,5,6};
         Scanner keyboard;
      
         keyboard = new Scanner(System.in);
         andrew = "andrew";
			num = 0;
      
      //FileNotFoundException
         try
         {
            System.out.println("The file you are trying to open is JUNK.txt");
            freader = new FileReader("JUNK.txt");
         
         }
             catch(FileNotFoundException fnfe)
            {
               System.out.println("The file JUNK.txt was not found.");
               System.out.println(fnfe.getMessage());
            }
      
         System.out.print("\n");
      
      //ArrayOutOfBoundsException
         try
         {
            System.out.print("The array has 6 numbers: ");
            for(int i = 0; i < array.length; i++)
            {
               System.out.print(" " + array[i]);
            
            }
            System.out.print("\n");
            System.out.println("Try to access the 7th element of the array.");
            System.out.println(array[7]);
         }
             catch(ArrayIndexOutOfBoundsException aoobe)
            {
               System.out.println("The element trying to be accessed does not exist.");
               System.out.println(aoobe.getMessage());
            }
      
         System.out.print("\n");
        //NumberFormatException
         try
         {
            System.out.println("You are trying to convert the string Number to a integer.");
            number = Integer.parseInt("Number");
         }
             catch(NumberFormatException nfe)
            {
               System.out.println("Input is a non numeric data.");
               System.out.println(nfe.getMessage());
            }
      
         System.out.print("\n");
      
      //StringIndexOutOfBoundsException
         try
         {	System.out.println("String : " + andrew);
            System.out.println("Looking for character 7 on the String " + andrew);
         
            character = andrew.charAt(6);
         }
             catch(StringIndexOutOfBoundsException sioobe)
            {
               System.out.println("The character you are looking for does not exist in " + andrew);
               System.out.println(sioobe.getMessage());
            }
      
         System.out.print("\n");
      
      //ArithmeticException
         try
         {
         
            System.out.print("Inter a integer to be divided by 0: ");
            num = keyboard.nextInt();
				num = num / 0;
         }
             catch(ArithmeticException ae)
            {
               System.out.println("The number you enterd is " + num);
					System.out.println("You can not divide " + num + " by 0");
               System.out.println(ae.getMessage());
            }
         finally
         {
				System.out.print("\n");
            System.out.println("This program has ended correcly.");
         }
      }	
   }