// Philip Peng
// Nov 20, 2007
// For Mr. Benum
//
// The "UseNameList" class.
// This is a main method to test the class NameList.

import java.io.*;
import java.util.*;

public class UseNameList
{
    public static void main (String [] args)
    {
		Scanner input = new Scanner(System.in);
		String buffer; // Yay for buffers!
		NameList foobar;
		
		System.out.println("Welcome to the UseNameList tester!\n");
		while (true) {
			System.out.print("Please input the max size of your NameList: ");
			buffer = input.nextLine();
			try {
				//foobar = new NameList(Integer.parseInt(buffer));
				foobar = new SortedList(Integer.parseInt(buffer));
				break;
			} catch (NumberFormatException e) {
				System.out.println("Not a valid number!");
			}
		}
		
		System.out.println();
		System.out.println("Commands you can give after the prompt:");
		System.out.println(" i to insert a name");
		System.out.println(" d to delete a name");
		System.out.println(" p to print the list");
		System.out.println(" q to quit");
		
		while (true)
		{
		    System.out.print ("> "); // Prompt for command.
		    buffer = input.nextLine();
		    if (buffer.length() > 1 || buffer.length() == 0) {
		    	System.out.println("  Error: Unknown command");
		    } else {
		    	char command = Character.toLowerCase(buffer.charAt(0));
		    	switch (command) {
			    	case 'i':
			    		System.out.print("  Name to be inserted: ");
			    		foobar.insert(input.nextLine());
			    		break;
			    	case 'd':
			    		System.out.print("  Name to be deleted: ");
			    		foobar.delete(input.nextLine());
			    		break;
			    	case 'p':
			    		foobar.printList();
			    		break;
			    	case 'q':
			    		System.out.print("  Now quitting...");
			    		System.exit(0);
			    	default:
			    		System.out.println("  Error: Unknown command");
		    	}
		    }
		}
    } // main method
} // UseNameList class
