   import java.util.Scanner;
   import java.io.*;
/***********************************************
 * Lab 3 - Exceptions
 *
 * @author -Ben Hein
 * @version - V1 - Jan 17, 2007
 * Section: 1
 ************************************************/
 /*
 /  References and Ackknowledgements: I have recieved
 /  no help on this programming assignment
 /
 /***********************************************/
 
    public class Exceptions_Lab_heinbr_Exceptions
   {
   /******
   This lab is supposed to execute multiple try catch blocks, deliberately.
   
   Exceptions:
   FileNotFoundException
   NumberFormatException
   java.util.InputMismatchException
   ArrayIndexOutOfBoundsException
   IllegalArgumentException
   ******/
       public static void main(String[] args)
      {
      
      //declarations
         Scanner keyboard;
         FileReader freader;
         String fileName;
         String str;
         String strLine;
         int number;
         int number2;
         double number3;
         int[] arrayTest = {1, 2, 3};
      
      
      //initializations
         keyboard = new Scanner(System.in);
      
      
      /**
      Block 1, testing to see if a file is valid for reading
      **/
      
         System.out.println("Please enter the name of a file you would like to open: ");
         fileName = keyboard.nextLine();
      
         System.out.println("The name of the file you would like to open is: " + fileName);
      
         try
         {
            freader = new FileReader(fileName);//try to read the file
         }
         
             catch (FileNotFoundException fnfe)
            {
            
               System.out.println("File cannot be found.");//if the file was bad, print this message
            
            }
      
      
      /**
      Block 2, Testing to see if the string entered can be parsed as an integer
      **/
      
         System.out.println("Please enter a string: ");
         str = keyboard.nextLine();
      
         System.out.println("The string you entered is: " + str);//echo the value
      
         try
         {
            number = Integer.parseInt(str);//trying to parse the string
         }
             catch(NumberFormatException nfe)
            {
               System.out.println("Conversion error: " + nfe.getMessage());//prints when the string cannot be parsed as an Integer
            }
      
      /**
      Block 3, trying to read a double value in as an integer
      **/
         System.out.println("Please enter a double value: ");
      
         try
         {
            number2 = keyboard.nextInt();//trying to make a double value be input as an integer
         }
         
             catch(java.util.InputMismatchException ime)
            {
               System.out.println("The value you entered was a double, not an integer.\n");//will print when the number is not an integer
            }
      
         number3 = keyboard.nextDouble();
         System.out.println("The value you entered was " + number3);
      
      
      /**
      Block 4, trying to print the values of arrayTest declared at the beginning of the program.
      **/
      
         for(int i = 0; i<=3; i++)//runs one to many times
         {
            try
            {
               System.out.println(arrayTest[i]);//prints the value of arrayTest
            }
            
                catch(ArrayIndexOutOfBoundsException aioob)
               {
                  System.out.println("You have exceeded the maximum length of the array");//will print when the array goes over 1
               }
         }
      
      /**
      Block 5, again trying to parse a string to an integer, this time with a different error
      **/
         System.out.println("Please enter a string: ");
         strLine = keyboard.nextLine();
         str = keyboard.nextLine();
      
         System.out.println("The string you entered was: " + str);
      
         try
         {
            number = Integer.parseInt(str);
         }
             catch (IllegalArgumentException iae)
            {
               System.out.println("Bad number format.");//will print since this action cannot be done.
            }
      
         System.out.println("The program has completed successfully.");
      
      //program completed
      
      
      }//end of main
   }
