
import java.util.Scanner;

/**
 * A driver program to illustrate the PhoneBook class.
 * 
 * @author Frederic Green
 */
public class PhoneOperator
{
 //The main method is in two parts.
 //In the first part, it prompts the user for up to 10 names.
 //In the second part, it asks the user to look up names.
 public static void main (String [] args)
 {
  Scanner keyboard = new Scanner(System.in);
  PhoneBook yellowPages = new PhoneBook(10);
  String name, number;
  int numberInBook = 0;
  String answer = "y";
  
  //First part: Read in names:
  while (!answer.equals("n") && numberInBook <= 10)
  {
    numberInBook++;
    System.out.print("Enter a name: ");
    name = keyboard.nextLine();
    System.out.print("Enter a number: ");
    number = keyboard.nextLine();
    yellowPages.addToBook(name, number);
    System.out.print("Add another name (no more than 10)? (y/n) --> ");
    answer = keyboard.nextLine();
   }//while
   
  System.out.println("The phone book as it exists now:");
  yellowPages.printBook();
  
  //Second part: Look up names:
  System.out.print("Do you want to look up a name? (y/n) --> ");
  
  answer = keyboard.nextLine();
  while (!answer.equals("n"))
  {
    System.out.print("Name please? ");
    name = keyboard.nextLine();
    System.out.println("Phone number for " + name + " is "
                       + yellowPages.lookUp(name) + ".");
    System.out.print("Do you want to look up another name? (y/n) --> ");
    answer = keyboard.nextLine();
  }//while
 }//main

}
