/***********************************************************************
 * Written by Ben Mathew
 * for Cornell University CS 100 Summer 2001
 * 
 * This program runs a simple text base menu that shows the usefulness of
 * the String.equalsIgnoreCase() method. It also demonstrates how the
 * String.toUpperCase() and String.toLowerCase() methods work.
 **********************************************************************/

public class StringMenu2
{
    
    public static void main (String [] args)
    {
        
        String input; //String to store the entered string
        String choice; //String to store the menu choice
	
        //infinite loop for input from user
        while (true)
            {
                //get a string to operate on
                System.out.println("Enter a string");
                input = SavitchIn.readLine();
                
                //get a command from the user
                System.out.println("Enter a command:\nUpper\nLower\nExit");
                choice = SavitchIn.readLine();
                			
                //check input and perform correct operation
                if (choice.equalsIgnoreCase("UPPER"))
                    {
                        System.out.println("\n" + input.toUpperCase() + "\n");
                    }
                
                else if (choice.equalsIgnoreCase("LOWER"))
                    {
                        System.out.println("\n" + input.toLowerCase() + "\n");
                    }
                
                else if (choice.equalsIgnoreCase("EXIT"))
                    {
                        System.exit(0);
                    }
                
                //print an error message for invalid menu choice
                else
                    {
                        System.out.println("\nFor typing lessons," +
                                           " see me after class.\n");
                    }

                /* Notice that when you enter in a menu choice, you do not need
                 * to type the String exactly as it appears in the menu display.
                 * This is useful because in your code you can list your choices
                 * in all capital letters, making your code more readable, but
                 * at the same time you allow the user to type the command in a
                 * number of forms, all capitals, all lowercase, first letter
                 * capitalized. This allows you to design the program to be more
                 * pleasing to the eye, as well as more understandable to the
                 * coder. In addition, notice what the two commands you may
                 * select actually do. If you would like to disect the String
                 * into characters, perhaps you were entering a DNA sequence or
                 * some other sort of information. You could make your code run
                 * more quickly by only having to check against one type of
                 * character, as opposed to checking both the upper case and
                 * lowercase variant of it. Therefore, if you were to set the
                 * String to all uppercase, then you would only need to check for
                 * instances of the uppercase character. In addition, if you
                 * intend to work with the character values, it is also much
                 * more convenient to deal with only one case of each character.
                 * These are just a couple of examples for uses of the command,
                 * I am sure you will come up with many more :)
                 *
                 * - b
                 */
                
            }
		
    }
    
}
