// Program Name         IntListTest.java
// Course:              CSE 1302
// Student Name:        Bradley Shedd
// Assignment Number:   Project#5 ExtraCredit
// Due Date:            12/06/2010
// Purpose:  Driver to test IntList methods.
// *************************************************************

   import java.util.Scanner;

  
public class IntListTest
   {
     
private static Scanner scan;
     
private static IntList list = new IntList();
  
   
//----------------------------------------------------------------
    // Creates a list, then repeatedly prints the menu and does what
    // the user asks until they quit.
    //----------------------------------------------------------------
      public static void main(String[] args)
      {
         scan =
new Scanner(System.in);
         printMenu();
        
int choice = scan.nextInt();
        
while (choice != 0)
         {
            dispatch(choice);
            printMenu();
            choice = scan.nextInt();
         }
         System.out.println(
"Coded By: Bradley J. Shedd"); 
      }
  
   
//----------------------------------------
    //  Does what the menu item calls for.
    //----------------------------------------
      public static void dispatch(int choice)
      {
        
int oldVal;
        
int newVal;
        
switch(choice)
         {
           
case 0:
               System.out.println();
               System.out.println(
"Bye!");
              
break;
        
           
case 1:    //add to front
               System.out.println();
               System.out.println(
"Enter integer to add to front");
               newVal = scan.nextInt();
               list.addToFront(newVal);
              
break;
        
           
case 2:   //add to end
               System.out.println();
               System.out.println(
"Enter integer to add to end");
               newVal = scan.nextInt();
              list.addToEnd(newVal);
              
break;
        
           
case 3:  //remove first element
               System.out.println();     
               list.removeFirst();
              
break;
        
           
case 4:  //print
               System.out.println();
               list.print();
              
break;
        
          
case 5:
               System.out.println();
               System.out.println(list.length());
              
break;
           
case 6:
               System.out.println();
               System.out.println( list);
              
break;
           
case 7:
               System.out.println();
               list.removeLast();
              
break;
           
case 8:
               System.out.println();
               oldVal = scan.nextInt();
               newVal = scan.nextInt();
               list.replace(oldVal,newVal);
              
break;
           
case 9:
               System.out.println();
               list.printRec();
              
break;
           
case 10:
              System.out.println();
               list.printRecBkw();
              
break;
           
case 11:
               System.out.println();
               System.out.println(
"What integer should I delete?");
               oldVal = scan.nextInt();
               list.delete(oldVal);
              
break;
           
case 12:
               System.out.println();
               System.out.println(
"What should I insert into the list?");
               newVal = scan.nextInt();
               list.insertInOrder(newVal);
              
break;
           
default:
               System.out.println();
               System.out.println(
"Sorry, invalid choice");
         }
      }
  
   
//----------------------------------------
    //  Prints the user's choices
    //----------------------------------------
      public static void printMenu()
      {
         System.out.println(
"\n   Menu   ");
         System.out.println(
"   ====");
         System.out.println(
"0: Quit:");
         System.out.println(
"1: Add an integer to the front of the list:");
         System.out.println(
"2: Adds an integer to the end of the list:");
         System.out.println(
"3: Remove an integer from the front of the list:");
         System.out.println(
"4: Print the list:");
         System.out.println(
"5: Print the list length:");
         System.out.println(
"6: Prints the list with toString() method:");
         System.out.println(
"7: Remove the last element:");
         System.out.println(
"8: Find and Replace:");
         System.out.println(
"9: Print the list Recursively:");
         System.out.println(
"10: Recursive method prints list backwards:");
         System.out.println(
"11: Deletes a number selected by user:");
         System.out.println(
"12: Inserts a selected number into the list:");
         System.out.println(
"================================================");
         System.out.println();
         System.out.println(
"\n\nEnter your choice: ");
         System.out.println(
"************************************************");
     
      }
   }


Homepage