// ****************************************************************
// IntegerListTest.java
//
// Provide a menu-driven tester for the IntegerList class.
//          
// ****************************************************************
import java.util.Scanner;
public class IntegerListTest{

	static IntegerList list = new IntegerList(10);
	static Scanner in = new Scanner(System.in);

	//-------------------------------------------------------
	// Create a list, then repeatedly print the menu and do what the
	// user asks until they quit
	//-------------------------------------------------------
	public static void main(String[] args)
	{
		list.randomize();
		System.out.print("The random initial ");
		printMenu();
		int choice = in.nextInt();
		while (choice != 0)
		{
			dispatch(choice);
			printMenu();
			choice = in.nextInt();
		}
	}


	//-------------------------------------------------------
	// Do 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 = in.nextInt();
			list = new IntegerList(size);
			list.randomize();
			break;
		case 2:
			list.selectionSort();
			break;
		case 3:
			System.out.print("Enter the value to look for: ");
			loc = list.search(in.nextInt());
			if (loc != -1)
				System.out.println("Found at location " + loc);
			else
				System.out.println("Not in list");
			break;
		default:
			System.out.println("Sorry, invalid choice");
		}
	}


	//-------------------------------------------------------
	// Print the user's choices
	//-------------------------------------------------------
	public static void printMenu()
	{
		System.out.println("List is: "+list);
		System.out.println("\n   Menu   ");
		System.out.println("   ====");
		System.out.println("0: Quit");
		System.out.println("1: Create a new list (** do this first!! **)");
		System.out.println("2: Sort the list using selection sort");
		System.out.println("3: Find an element in the list using sequential search");
		System.out.print("\nEnter your choice: ");
	}
}

