/*****************************************************
 *  This class is designed to learn how to handle and 
 *	 implement exceptions.
 * 
 * @author by: Alexander Alarif 
 * date: 1/17/07
 * Lab 3
 * section 2
 * 
 ******************************************************/
 import java.util.*;			//Calls the utilities necessary to write this program
 import java.io.*;			//Imports the i/o utilities					
 public class Exceptions_Lab_alarifac_Exceptions
 {
 	/**********************************************************************
	* This is the main class where all the code is stored and handlels the 
	* various exceptions within the program
	*
	* @excecption fnfe This excption executes when a file cannot be found
	*
	* @exeception iae This exception executes when an argument is passed in
	* that does not comply to the parameters of the method.
	*
	* @execption aioobe This execption is preformed when an array goes 
	* beyond the number of elements assigned to it.
	*
	* @execption nfe This exeception occurs when a number is not converted
	* or when a certian line of code cannot be converted into a number
	*
	* @exeception ae This exception occurs when an arithmetic operation
	* cannot execute.
	***********************************************************************/
 	public static void main (String [] args)
	{
		 //Declares the variables
		 Scanner keyboard;
		 String theFile;
		 Scanner readingFile;
		 int number;
		 int [] numbers;
		 int aNumber;
		 int aNumber2;
		 int aNumber3;
		 
		 //Initalizes the variables
		 keyboard = new Scanner (System.in);
		 numbers = new int [4];
		 
		 //Asks the user to enter a file or number.
		 System.out.print ("Enter a file or number.");
		 theFile = keyboard.nextLine();
		 
		 //Echoes the file you want to open.
		 System.out.println ("The file that is trying to be opened is " + theFile);
		 
		 //Sets up the FileNotFoundException
		 try
		 {
		 	//Initalizes the readingFile Scanner
		 	readingFile = new Scanner (new File (theFile));
			
			while (readingFile.hasNextInt())
			{
				number = readingFile.nextInt();
				
				//Echoes the file value you want.
				
				System.out.println ("The number you got from the file is " + number);
			}
		}
		catch (FileNotFoundException fnfe)
		{
			System.out.println ("We're sorry, but either you typed the wrong file "
			+ "or the file does not exist.");
		}	
		
		//Sets up the IllegalArgumentException
		try
		{
			//This is the number that will start the Illegal arument exception
			number = Integer.parseInt("Hello");
			
			//This echoes the arument trying to be passed
			System.out.println ("The argument trying to passed in is" + number);
		}
		catch (IllegalArgumentException iae)
		{
			System.out.println ("There was an illegal arument exception.");
		}
		
		//Sets up the ArrayIndexOutOfBounds Exception
		try
		{
			//Prints out the array
			for (int i = 0; i <= 4; i++)
			{
				System.out.println(numbers[i]);
				
				//Echoes the array
				
				System.out.println("Array at " + numbers[i]);
			}
			
			
		}
		catch (ArrayIndexOutOfBoundsException aioobe)
		{
			System.out.println ("I'm sorry but the array went out of bounds");
		}
		
		//Sets of the NumberFormat Exception
		try
		{
			//This will start the NumberFormat Exception
			number = Integer.parseInt ("It's a wonderful life.");
			
			//Echoes the what is trying to be parsed into an integer
			System.out.println ("The number trying to be passed in is " + number);
		}
		catch (NumberFormatException nfe)
		{
			System.out.println ("There was a problem formatting the number");
		}
		
		//Sets of the Arithmetic Exception
		try
		{
			aNumber = 4;					//Initalizes aNumber
			aNumber2 = 0;					//Initalizes aNumber2
			aNumber3 = aNumber / 0;		//Initalizes aNumber3
			
			
			//Echoes the number trying to be divied
			System.out.println ("The number trying to be divided by 0 is " + 
			aNumber);
		}
		catch (ArithmeticException ae)
		{
			System.out.println ("This number cannot be divided by 0");
		}
 }
}		 
