//Converted all to ArrayLists 


// "PhoneBook.java" - The PhoneBook module

import java.util.*;

public class PhoneBook
{
    static ArrayList<String> names = new ArrayList<String>();
    static ArrayList<String> phoneNumbers = new ArrayList<String>();
    
	// The fields of the object
    //static final int ARRAY_SIZE = 100;
    // The arrays containing the names and phone numbers.
    //static String [] names = new String [ARRAY_SIZE];
    //static String [] phoneNumbers = new String [ARRAY_SIZE];
    // The number of entries in the data base.
    static int numEntries = 0;

    // 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)
    {
    	if (names.contains(name) == true) {
    		return names.indexOf(name);
    	} else {
    		return -1;
    	}
  
    /*
	for (int count = 0 ; count < numEntries ; count++)
	{
	    if (name.equals (names [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.add(numEntries, name);
    phoneNumbers.add(numEntries, phoneNumber);
	//names [numEntries] = name;
	//phoneNumbers [numEntries] = phoneNumber;
	numEntries++;
	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.remove(entry);
	phoneNumbers.remove(entry);
	/*
	for (int count = entry + 1 ; count < numEntries ; count++)
	{
		names [count - 1] = names [count];
	    phoneNumbers [count - 1] = phoneNumbers [count];
	}
	*/
	numEntries--;
	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.set(entry, newPhoneNumber);
	//phoneNumbers [entry] = newPhoneNumber;
	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 phoneNumbers.get(entry);
	//return phoneNumbers [entry];
    } // lookUp method
} // PhoneBook class
