   import java.util.*;	//Brings in the the Utilities class
   import java.io.*;		//Brings in the I/O class

/***********************************************
 * Handles exceptions and suchwhat
 *
 * @author - Andrew Whitby
 * @version - V1.0 - 1-17-06
 ************************************************/
 /*
 /  Ackknowledgement: Elizabeth Adams and Nancy Harris
 /
 /***********************************************/
    public class Exceptions
   {
   /********************************************
    * Runs through five different types of exceptions in
    * try blocks, with appropriate catches for each one.
    *
    * @param args unused
    *********************************************/
       public static void main(String args[])
      {
      //Stating the variables.
         String bad;
         int[] alsoBad = {1, 2, 3};
         char need;
         int needy;
         FileReader read;
         int x;
         int zero;
      
      
      //Initializing the few needed to be initialized
         bad = "Wrong.txt";
         x = 9001;
         zero = 0;
         
      	
      	//Exception 1: Attempting to access a part of a string that doesn't exist
      	
         try
         {
            need = bad.charAt(14);
            System.out.println("The fifteenth character in the string " + bad + " is: " + need);
         
         }
             catch(StringIndexOutOfBoundsException e)
            {
            
               System.out.println("There is no fifteenth character in the string " + bad + ".");
            
            }
      	
         System.out.println();
      	
      	//Exception 2: Attempting to use a String value when needing an Integer value
      	
         try
         {
         
            needy = Integer.parseInt(bad);
         
         }
             catch(NumberFormatException e)
            {
            
               System.out.println(bad + " is not an integer value.");
            
            }
            
         System.out.println();
      	
      	//Exception 3: Attempting to access a file that doesn't exist
      	
         try
         {
            
            read = new FileReader(bad);
            
         }		
             catch(FileNotFoundException e)
            {
            
               System.out.println("The file you're looking for, " + bad + " does not exist");
            
            }
            
      		
         System.out.println();
      	
      	//Exception 4: Attempting to divide by zero
      	
         try
         {
         
            System.out.println(x + " divided by " + zero + " equals " + (x/zero) + ".");
         
         }
             catch(ArithmeticException e)
            {
               System.out.println("You cannot divide by " + zero + ".");
            }
            
         System.out.println();
      		
      		//Exception 5: Attempting to access a part of an array that doesn't exist
         try
         {
         
            System.out.println("Bow before the glory of the number " + alsoBad[3] + "!");
         
         }
             catch(ArrayIndexOutOfBoundsException e)
            {
            
               System.out.println("There is no fourth value in the array.");
            
            }
            
         System.out.println();
      			
         System.out.println("The program has ended normally.");
         System.out.println("Huzzah");
      }
   }  
