import java.io.*;
import LinkedList;

/**
 *@author Group_1:
 *@author Eddie_Char
 *@author Eric_Berry
 *@author Bryan_Carcelen
 *@author Farat_Ali
 *@author Minh_Bui
 *@author Johnny_Chien
 *CS 240
 *5/10/01
 *Project3.java
 *
 *This program prompts the user for options.  The selected option then
 *goes to its respective method and performs the appropriate operation.
 */

public class Project3
{

/**
 *@param input input from user in selecting options.
 *@param inputCode input an airport code when insert option is selected.
 *@param LL creates a LinkedList object.
 *@throws IOException for input from the user.
 */

   public static void main (String[] args) throws IOException
   {
      InputStreamReader isr = new InputStreamReader (System.in);
      BufferedReader br = new BufferedReader (isr);

      int input;
      String inputCode;
      LinkedList LL = new LinkedList(new ListNode("ZZZ"));    // sets the first node to be a dummy node
                                                                                                                        // of value "ZZZ"
      System.out.println ();

      do
      {
         System.out.println ("1 - Insert a first node.");
         System.out.println ("2 - Delete a first node.");
         System.out.println ("3 - Insert a last node.");
         System.out.println ("4 - Delete a last node.");
         System.out.println ("5 - Display number of values in the list.");
         System.out.println ("6 - Display values in the list.");
         System.out.println ("7 - Search for a value in the list.");
         System.out.println ("0 - Exit program.");
         System.out.println ();

         System.out.print ("Enter an option: ");
         input = Integer.parseInt (br.readLine ());
         System.out.println ();

         switch (input)
         {
            case 1:
               System.out.print ("Enter an airport code to insert: ");
               inputCode = br.readLine ();
               System.out.println ();
               LL.insertFirstNode (inputCode.toUpperCase ());
               break;
            case 2:
               LL.deleteFirstNode ();
               break;
            case 3:
               System.out.print ("Enter an airport code to insert: ");
               inputCode = br.readLine ();
               System.out.println ();
               LL.insertLastNode (inputCode.toUpperCase ());
               break;
            case 4:
               LL.deleteLastNode ();
               break;
            case 5:
               System.out.print("You have ");
               System.out.println(LL.getSize ()+" listed values\n");
               System.out.println();
               break;
            case 6:
               LL.displayAll ();
               break;
            case 7:
               System.out.print ("Enter an airport code to search for: ");
               inputCode = br.readLine ();
               System.out.println ();
               System.out.println(LL.doSearch (LL.firstNode,inputCode.toUpperCase()));
               break;
            case 0:
               System.out.println ("You have terminated the program.");
               break;
            default:
               System.out.println ("There was an error in input.\n");
         } //end switch

      } //end do
      while (input != 0);

   } //end main method
} //end class
