import java.util.Scanner;    // Needed for Scanner class

/**
   This program demonstrates the switch statement.
*/

public class SwitchDemo
{
   public static void main(String[] args)
   {
      int number;       // A number entered by the user
          
      // Create a Scanner object for keyboard input.
      Scanner keyboard;
      
      keyboard = new Scanner(System.in);
      
      // Get one of the numbers 1, 2, or 3 from the user.
      System.out.print("Enter 1, 2, or 3: ");
      
      if(keyboard.hasNextInt())
         number = keyboard.nextInt();
      else
         number = catchError(keyboard.next());

      // Determine the number entered.
      switch (number)
      {
         case 1:
            easyPrint(1);
            break;
         case 2:
            easyPrint(2);
            break;
         case 3:
            easyPrint(3);
            break;
         default:
            System.out.println("That's not 1, 2, or 3!");
      }
   }
   /***********************************************
    * easy print is a method to demonstrate parameter passing
    *
    * @param choice The choice that the user makes
    ***********************************************/
   public static void easyPrint(int choice)
   {
      System.out.println("You entered " + choice);
   }
   /***********************************************
    * catchError is a method that prints an error message
    *
    * @param token The erroneous token entered
    * @return A default value if there is an error
    ***********************************************/
   public static int catchError(String token)
   {
      System.out.println("You entered " + token + ". That is WRONG.");
      System.out.println("Using 0.");
      return 0;
   }
}
