/********************************************************************************
 * File name: PQDriver.java
 * Description: The driver program for testing PriorityQ.
 * Last change: Feb 9th, 2003
 *****************************************************************************/
 
 
import java.io.*;
 
public class PQDriver
{

	public static int getChoice() throws Exception
	{
		int choice;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String ans;
		
		System.out.println( "This driver program is to test the methods in the class Priority Q. " );
		System.out.println( "1) add element to the priority queue " );
		System.out.println( "2) remove the smallest element in the priority queue " );
		System.out.println( "3) display size of priority queue " );
		System.out.println( "4) is the queue empty? " );
		System.out.println( "5) display the smallest element " );
		System.out.println( "6) make the queue empty " );
		System.out.println( "7) Quit \n" );
		
		System.out.println( "Please enter your choice: ");
		
		choice = 0;
		
		ans = in.readLine();
		
		choice = Integer.parseInt( ans );
		
		return choice;
	} // end getChoice
	
/****************************************************************************/	
	
	public static void main( String [] args ) throws Exception
	{
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		PriorityQ PQ = new BinaryHeap();
		String element;
		int choice;
		
		choice = getChoice();
		
		while ( choice != 8 )
		{
			switch( choice )
			{
				case 1:      //test insert()
					System.out.println( "Before insert element " );
					PQ.printHeap();
					System.out.println( "\nPlease input a element: " );
					element = input.readLine();
					PQ.insert( element );
					System.out.println( "\n\nNow the queue is: " );
					PQ.printHeap();
					System.out.println( "\n\nPress any key to continue..." );
					input.readLine();
					break;
				
				case 2:      //test deleteMin()
					System.out.println( "Before delete element: " );
					PQ.printHeap();
					System.out.println( "\n\nPress any key to run deleteMin()." );
					input.readLine();
					System.out.println( "\nThe Min term of the heap is " + PQ.deleteMin() ); 
					System.out.println( "\n\nNow the queue is: " );
					PQ.printHeap();
					System.out.println( "\n\nPress any key to continue..." );
					input.readLine();
					break;
				
				case 3:      //test size()
					System.out.println( "\nThe queue now has " + PQ.size() );
					if ( PQ.size() == 1)
						System.out.print( " element. " );
					else
						System.out.print( " elements. " );
					
					System.out.println( "\n\nPress any key to continue..." );
					input.readLine();
					break;
				
				case 4:      //test isEmpty()
					if ( PQ.isEmpty() )
						System.out.println( "\nThe queue is empty. " );
					else
						System.out.println( "\nThe queue is not empty. " );
					
					System.out.println( "\n\nPress any key to continue..." );
					input.readLine();
					break;
				
				case 5:      //test findMin()
					System.out.println( "\nThe smallest element in the heap is " + PQ.findMin() );
					PQ.printHeap();
					System.out.println( "\n\nPress any key to continue..." );
					input.readLine();
					break;
				
				case 6:      //test makeEmpty()
					System.out.println( "\nMakes the queue empty. " );
					PQ.makeEmpty();
					PQ.printHeap();
					System.out.println( "\n\nPress any key to continue..." );
					input.readLine();
					break;

					
				case 7:
					System.exit(0);
					
				default:
					System.out.println( "Choice not in list." );
					System.out.println( "Please try again!" );
					System.out.println( "\n\nPress any key to continue..." );
					input.readLine();
				}    // end switch
				
				choice = getChoice();
			}  // end while
			
		}    // end main

}	// end this class

