// Program Name:                 IntegerListSTest.java
// Course:                       CSE 1302J
// Student Name:                 Bradley Shedd
// Assignment Number:            Lab#8
// Due Date:                     10/27/2010
// Purpose:                      Provide a menu-driven tester for the IntegerList class.
//                               (Version S - for use in the linear search lab exercise).


   import java.util.Scanner;

   
public class IntegerListSTest
   {
     
static IntegerListS list = new IntegerListS(10);
     
static Scanner scan = new Scanner(System.in);
  
   
// ------------------------------------------------------------------
    //   Creates a list, then repeatedly print the menu and do what the
    //   user asks until they quit.
    // ------------------------------------------------------------------
       public static void main(String[] args)
      {
         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 loc;
        
switch(choice)
        {
           
case 0:
               System.out.println(
"Bye!");
              
break;
           
case 1:
              System.out.println(
"How big should the list be?");
              
int size = scan.nextInt();
               list =
new IntegerListS(size);
               list.randomize();
              
break;
           
case 2:
               list.selectionSort();
               
break;
           
case 3:
               System.out.print(
"Enter the value to look for: ");
               loc = list.linearSearch(scan.nextInt());
              
if (loc != -1)
                  System.out.println(
"Found at location " + loc);
               
else
                  System.out.println("Not in list");
              
break;
           
case 4:
               list.print();
              
break;
           
case 5:  System.out.print("Enter the value to look for: ");
               loc = list.linearSearchRec(scan.nextInt());
              
if (loc != -1)
                  System.out.println(
"Found at location " + loc);
              
else
                  System.out.println("Not in list");
              
break;
       
           
case 6:  System.out.print("Enter the value to look for: ");
               loc = list.binarySearch(scan.nextInt());
              
if (loc != -1)
                  System.out.println(
"Found at location " + loc);
             
else
                  System.out.println("Not in list");
              
break;
        
           
case 7:  System.out.print("Enter the value to look for: ");
               loc = list.binarySearchRec(scan.nextInt());
              
if (loc != -1)
                  System.out.println(
"Found at location " + loc);
              
else
                  System.out.println("Not in list");
              
break;
        
        
        
         
//add case 5 and 6 and 7
            default:
               System.out.println(
"Sorry, invalid choice");
         }
      }
  
   
// -------------------------------------
    //   Prints the menu of user's choices.
    // -------------------------------------
       public static void printMenu()
      {
         System.out.println(
"\n   Menu   ");
         System.out.println(
"================================================");
         System.out.println(
"0: Quit");
         System.out.println(
"1: Create new list elements (** do this first!! **)");
         System.out.println(
"2: Sort the list using selection sort");
         System.out.println(
"3: Find an element in the list using linear search");
         System.out.println(
"4: Print the list");
         System.out.println(
"5: Find a number using Recursive Linear Search");
         System.out.println(
"6: Find a number using Binary Search");
         System.out.println(
"7: Find a number using Binary Recursive Search");
         System.out.print(
"\nEnter your choice: ");
      }
  
   }

Homepage