   import java.util.Scanner;
   import java.io.*;

/**
 * creating five exception programs
 *
/**
 * Yoshihiro Fujio
 * CS239 Section 2
 * Lab - Handling Exception
 * V1 2007/1/17
**/

    public class Exceptions_Lab_fujioyx_HandlingExceptions
   {
       public static void main (String [] args)
      {
      /**
      * making five blocks each have different exception program
      */
         String message; // any string that each blocks use
         int num; // any numbers each blocks use
         String alpha; // string for texts inside the file
         Scanner keyb; // Scanner for keyboard
         Scanner fileS; // fileScanner
      
         keyb = new Scanner(System.in);
      // trying FileNotFoundException
         System.out.print("enter a file name: ");
         message = keyb.nextLine();
      
         System.out.println("file you want open is " + message);
      
         try
         {
            fileS = new Scanner(new File(message)); // searching file named in String Message
            while (fileS.hasNextLine())
            {
               alpha = fileS.nextLine();
               System.out.println("you have got " + alpha); // showing the texts inside the file that was found
            }
         }
         
             catch (FileNotFoundException fnfe)
            {
               System.out.println("no excpected file found");
            }
         System.out.println("\n");
      
      // trying NumberFormatException		
         System.out.print("enter a integer number: "); // type integer number in String
         message = keyb.nextLine();
      
         System.out.println("number you typed is " + message);
      
         try
         {
            num = Integer.parseInt(message); // change String to Integer
         
            System.out.println("you have got " + num);
         }
         
             catch (NumberFormatException nfe)
            {
               System.out.println("number format wrong");
            }
         System.out.println("\n");
      
      // trying ClassNotFoundException
         System.out.print("enter a class name: ");
         message = keyb.nextLine();
      
         System.out.println("class you typed is " + message);
         try
         {
            Class.forName(message); // searching class from the folder this program is in
            System.out.println("class you have got is " + message);
         }
         
             catch (ClassNotFoundException cnfe)
            {
               System.out.println("you typed wrong class");
            }
         System.out.println("\n");
      
      // trying IllegalArgumentException
         System.out.print("enter a integer number: "); // type integer number in String
         message = keyb.nextLine();
      
         System.out.println("number you typed is " + message);
      
         try
         {
            num = Integer.parseInt(message); // change String to Integer
         
            System.out.println("you have got " + num);
         }
         
             catch (IllegalArgumentException iae)
            {
               System.out.println("number format wrong");
            }
         System.out.println("\n");
      
      // trying IOException
         System.out.print("enter a file name: ");
         message = keyb.nextLine();
      
         System.out.println("file you want open is " + message);
      
         try
         {
            fileS = new Scanner(new File(message)); // searching file named in String Message
            while (fileS.hasNextLine())
            {
               alpha = fileS.nextLine();
               System.out.println("you have got " + alpha); // showing the texts inside the file that was found
            }
         }
         
             catch (IOException ioe)
            {
               System.out.println("no excpected file found");
            }
         System.out.println("\n");
      
         System.out.println("program ran correctly\n"); // note program run correctly
      
      }
   }
				
		
