/*
@author Daniel Heck
1/17/07
Lab 3 Section 1
*/
import java.util.Scanner;
import java.io.*;
/*
A series of 5 catch blocks that are
FileNotFoundException - Can not find the file error
NumberFormatException - Error formating the int
IllegalArgumentException - Bad Format data
IOException	- error in exception
 
*/
public class Exceptions_Lab_heckds_Execeptions
{
	public static void main(String[] args)
	{
		FileReader finput; // file input
		String filename; // to hold input
		String str; // string for testsing inputed variable
		int number; // to hold an int
		int boundries; // to set up for array try and catch
		int[] array = {1,2,3}; // array for try and catch
		Scanner keyboard;
		
		
		keyboard = new Scanner(System.in);
		System.out.print("Enter the name of the file ");
		filename = keyboard.nextLine();
		
		System.out.println(); // print space for Clearness
		
		System.out.print("Enter an Integer ");
		str = keyboard.nextLine();
		
		System.out.println(); // print space for Clearness
		
		System.out.print("Enter pick from the array of number 0 = 1, 1 = 2, 2 = 3 : ");
		boundries = keyboard.nextInt();

	 	
		try // tries to find the file and outputs if not sends it to the catch to deal with the exception
		{
			finput = new FileReader(filename);
			System.out.println("Found file: " + filename);
		}
		
		catch (FileNotFoundException fnfe) // catches an exception failure while trying to find the inputed file and then prints the error message
		{
			System.out.println("File: " + filename + " not found ");
		}
		
		try // tries to convert number to int and outputs and if it fails sends it to nfe
		{
			number = Integer.parseInt(str);
			System.out.println(str + " is correct input ");
		}
		
		catch (NumberFormatException nfe) // nfe outputs the failed exception for bad number format
		{
			System.out.println("Conversion error with input: " + str);
		}
		
		try // tries to change the format of number and if it fails sends it to iae catch to output error
		{
			number = Integer.parseInt(str);
			System.out.println("Input: " + str + " is correct ");
		}
		catch (IllegalArgumentException iae) // cataches the attempt to convert into an int and prints failure message
		{
			System.out.println(str + "is bad number format. ");
		}
		try // searches for file if not found sinds to catch with a default exception message
		{
			finput = new FileReader(filename);
			System.out.println("Found file: " + filename );
		}
		catch (IOException ioe) // cataches the ioe exception if it fails the try with a wrong file name
		{
		 	System.out.println("Error: " + filename + " file not found " + ioe.getMessage());
		}
		
		try // tries the array to see if it is inbounds
		{
			System.out.println(array[boundries] + " number is in bounds.");
		}
		
		catch (ArrayIndexOutOfBoundsException aioob) // catches the aioob exception if it fails the try
		{
			System.out.println(array[boundries] + " these numbers are out of bounds");
		}
		
		finally // displays final message after all other exceptionis
		{
			System.out.println(" aioob expection doesnt work everythign else run fine");
		}
		

	}

}