// "PhoneBookDemo.java" - A PhoneBook module driver program

import java.io.*;

public class PhoneBookDemo
{
    public static void main (String [] args) throws IOException
    {
	BufferedReader keyboard =
	    new BufferedReader (new InputStreamReader (System.in));
	String choice, name, phoneNumber;
	while (true)
	{
	    System.out.println ("1 .. Add a name");
	    System.out.println ("2 .. Delete a name");
	    System.out.println ("3 .. Change a name");
	    System.out.println ("4 .. Look up a name");
	    System.out.println ("5 .. Quit");

	    System.out.print ("Choice: ");
	    choice = keyboard.readLine ();

	    if (choice.equals ("1"))
	    {
		System.out.print ("Enter name to be added: ");
		name = keyboard.readLine ();
		System.out.print ("Enter " + name + "'s phone number: ");
		phoneNumber = keyboard.readLine ();
		PhoneBook.add (name, phoneNumber);
	    }
	    else if (choice.equals ("2"))
	    {
		System.out.print ("Enter name to be deleted: ");
		name = keyboard.readLine ();
		PhoneBook.delete (name);
	    }
	    else if (choice.equals ("3"))
	    {
		System.out.print ("Enter name to be changed: ");
		name = keyboard.readLine ();
		System.out.print ("Enter new phone number for " + name + ": ");
		phoneNumber = keyboard.readLine ();
		PhoneBook.change (name, phoneNumber);
	    }
	    else if (choice.equals ("4"))
	    {
		System.out.print ("Enter name to be looked up: ");
		name = keyboard.readLine ();
		phoneNumber = PhoneBook.lookUp (name);
		if (phoneNumber == null)
		{
		    System.out.println ("Couldn't find " + name +
			    "'s phone number.");
		}
		else
		{
		    System.out.println (name + "'s phone number is " +
			    phoneNumber);
		}
	    }
	    else if (choice.equals ("5"))
	    {
		break;
	    }
	    else
	    {
		System.out.println ("Enter a choice between 1 and 5");
	    }
	} // while loop
    } // main method
} // PhoneBookDemo class
