// "PhoneBook2.java" - The PhoneBook module
import java.util.*;

public class PhoneBook2
{
    // The arrays containing the names and phone numbers.
    static Vector names = new Vector ();
    static Vector phoneNumbers = new Vector ();

    // Return the index into the array containing the record
    // which matches the name parameter.  The find method
    // is not part of the interface.
    static int find (String name)
    {
	for (int count = 0 ; count < names.size () ; count++)
	{
	    if (name.equals ((String) names.elementAt (count)))
	    {
		return count;
	    }
	}
	return - 1;
    } // find method


    // Add a record to the data base.  This does not check
    // to see if the array is full.  The add method
    // is part of the interface
    public static void add (String name, String phoneNumber)
    {
	names.addElement (name);
	phoneNumbers.addElement (phoneNumber);
	System.out.println (name + " added");
    } // add method


    // Delete a record from the data base.  The delete
    // method is part of the interface.
    public static void delete (String name)
    {
	int entry = find (name);
	if (entry == -1)
	{
	    System.out.println ("Can't find " + name + " in the phone book");
	    return;
	}
	names.removeElementAt (entry);
	phoneNumbers.removeElementAt (entry);
	System.out.println (name + " deleted");
    } // delete method


    // Change the phone number of a record in the data base.
    // The change method is part of the interface.
    public static void change (String name, String newPhoneNumber)
    {
	int entry = find (name);
	if (entry == -1)
	{
	    System.out.println ("Can't find " + name + " in the phone book");
	    return;
	}
	phoneNumbers.setElementAt (newPhoneNumber, entry);
	System.out.println ("Phone number for " + name + " changed");
    } // change method


    // Look up a name in the data base and return the associated phone
    // number.  The lookUp method is part of the interface.
    public static String lookUp (String name)
    {
	int entry = find (name);
	if (entry == -1)
	{
	    return null;
	}
	return (String) phoneNumbers.elementAt (entry);
    } // lookUp method
} // PhoneBook2 class
