import java.util.Scanner;
import java.util.*;
import java.io.*;
/*******************************************
* This program deals with handling Exceptions
* that may arise.
*
*@author - Bryan Wiseman
*@version - 1
*********************************************/
//Date: January 17, 2007
//Section: 1
//Lab: 3

public class Exceptions_Lab_wisemabd_ExceptionHandler
{
   
   /*************************
   *this method executes five
   *problems and how to handle
   *them
	* File not Found
	* Converision
	* Divide by zero 
	* Array Index Out Of Bounds 
	* InputMismatch
   **************************/
	public static void main(String[] args)
   {
   	Scanner scan;		//The scanner
		Scanner file;		//the file scanner
     	int num;				//holds the inputed variable
		String fileName;	//holds the inputed filename
		int holder;			//zero divison holder 
		String str;			//holds string conversion
		int[] array1 = { 1, 2, 3};  //the array for input
		char holds;			//holds a char
     	 	
    	scan = new Scanner(System.in);
      
		//get filename
      System.out.print("Please enter the file name? ");
		fileName = scan.nextLine();
		System.out.println();
		System.out.println("filename = " + fileName);
      
		//catch file error
		try
		{
			file = new Scanner ( new File (fileName));
		}
		
		catch(FileNotFoundException fnfe)
		{
			System.out.println("Your file was not found.");
			System.out.println();
		}
		//get string number
		//catch conversion error
		try
		{
			System.out.print("Please enter a number with a string:");
			str = scan.nextLine();
			System.out.println("Input is " + str);
			
			holder = Integer.parseInt(str);
		
		}
		catch(NumberFormatException nfe)
		{
			System.out.println("A string does not convert to a integer");
		}
	
		//get integer
      System.out.print("Please enter a number: ");
		num = scan.nextInt();
		System.out.println("num = " + num);
		
		//catches arithmatic exception
		try
		{
			holder = num / 0;
		}
		
		catch(ArithmeticException ae)
		{
			System.out.println(" You can not divide  by zero");
			System.out.println();
		}
		
		//catch arrray error
		try
		{
      	for(int index = 0; index<= 3; index++)
			{	
				System.out.println(array1[index]);
			}
		}
		catch(ArrayIndexOutOfBoundsException aiob)
		{
			System.out.println("The array is to small.");
			System.out.println();
		}
		//input exception
		try
		{
			System.out.print("Please enter a saying:");
			holder = scan.nextInt();
		}
		catch (InputMismatchException ime)
		{
			System.out.println("Wrong input type");
		}
		
		System.out.println("Successful Completeion");
		System.out.println("Program ended normally");
 	}
 }