import java.util.Scanner;
import java.io.*;
import java.util.InputMismatchException;
import java.lang.ArrayIndexOutOfBoundsException;
import java.lang.NumberFormatException;
import java.lang.NegativeArraySizeException;
import java.lang.ArithmeticException;
/***************************
 * @author: Stephen Hack
 * @version Lab 3 - Exception Handling
	CS 239
	January 10, 2006
	Section 3. Lab by Dr. Adams and Dr. Harris. 
	I have not given nor recieved any unauthorized help.
	This document will have five different exceptions.  
*****************************/
public class Exceptions
{
	public static void main (String args[])
	{	
	
		//declare variables
		int integer = 0; //to store an integer
		double secondnumber = 0.0; //the string in the second exception
		Scanner keyboard = new Scanner(System.in); //scanner
		final int NUMBERS = 3;
		int[] hours = new int[NUMBERS];
		byte OutOfRange = 0;
		double notString = 0.0;
		String nonNumber = ">"; 
		double newnum = 0;
		int notZero = 6; //will be divided by 0 in 5th exception
		int sum = 0; //for the fifth exception

	
		//the first exception tries an integer and if it isn't prints out accordingly
		try
		{
		System.out.println("Type in an integer: "); //supposed to be an integer
		integer = keyboard.nextInt();
		}
	
		catch (InputMismatchException ime)
		{
		System.out.println("Wrong input");//responds if an integer isn't inputed
		}
	
		System.out.println(integer);
	
		//the second exception an example of an array out of bounds exception
		try
		{
		hours[3] = keyboard.nextInt(); 
		}
		
		catch (ArrayIndexOutOfBoundsException aiooe)
		{
		System.out.println("Not part of array");
		}
				
		
		//Third exception will try and convert a non-number string to an integer
		try
		{
		System.out.println("THis will try and convert a non-number string to integer");
		newnum = Double.parseDouble(nonNumber);
		}
		
		catch (NumberFormatException ife)
		{
		System.out.println("That String cannot be converted to a number");
		}
		
		//Fourth exception will deal with negative arrays
		try
		{
		int NEGNUMBERS = -4;
		int[] days = new int[NEGNUMBERS]; //4th exception
		System.out.println("This will look at a negative array exception");
		days[-2] = keyboard.nextInt(); 
		}
		
		catch (NegativeArraySizeException nase)
		{
		System.out.println("Negative array");
		}
		
		//Fifth exception will deal with an integer being divided by 0
		
		try
		{
		System.out.println("This will look at what happens when we divide an integer by 0");
		sum = notZero / 0;
		}
		
		catch (ArithmeticException ae)
		{
		System.out.println("An arithmetic exception, in this case dividing by 0");
		}
		
		System.out.println("This printed the way it should have!");
	}	
}