import java.util.Scanner;
import java.io.*;
/***************************************
* This is an exception handling program
*
* @author Andrew Cox
* @version V1 1/17/07
* 
* Section 1
* Lab 3
*
* Exceptions used in this program:
* ArithmeticException
* ArrayIndexOutOfBoundsException
* FileNotFoundException
* NumberFormatException
***************************************/
public class Exceptions_Lab_cox2ar_exceptionHandler
{
	public static void main(String args[])
	{
		Scanner keyboard;
		keyboard = new Scanner(System.in);
		int number;
		int error;
		String word;
		String array[] = new String[3];
		Scanner fileScanner;
		String fileName = "";
		int value;
		int x;
		String input = null;
		
		//This piece of code uses an exception handler for dividing by zero.
		
		try
		{
			System.out.print("Enter any integer number to try to divide it by 0: ");
			number = keyboard.nextInt();
			System.out.println("Value you entered: " + number);
			error = number / 0;
		}
		catch (ArithmeticException ae)
		{
			System.out.print("ERROR: You cannot divide by zero.\n\n");
		}
		
		//This code performs an Array out of bounds exception.				
		try
		{
			word = array[4];
		}
		
		catch (ArrayIndexOutOfBoundsException aioobe)
		{
			System.out.print("ERROR: Cant access number in array\n\n");
		}
		
		//This code performs a file not found exception.	
		try
		{
			fileScanner = new Scanner(new File (fileName));
			while (fileScanner.hasNextInt());
			{
				value = fileScanner.nextInt();
			}
		}
		catch (FileNotFoundException fnfe)
		{
			System.out.print("ERROR: File cannot be found.\n\n");
			System.out.println();
		}
		
		//This code executes a Number Format Exception
		try
		{
			System.out.print("Type something. Anything: ");
			input = keyboard.next();
			x = Integer.parseInt( input );
		} 
		catch ( NumberFormatException e ) 
		{ 
			System.out.println(input + " is not a valid format for an integer.\n\n" );
		}
		
		System.out.print("This program has ended normally");

	}
}