import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * A simple class for performing a "Caller ID"
 * (i.e., look up a person's name given their
 * phone number)
 *
 * This class illustrates the use of the HashMap
 * class.
 *
 * @author  Prof. David Bernstein, James Madison University
 * @version 2.0 (Using a type-safe parameterized class)
 */
public class CallerID
{

    /**
     * The entry point of the program
     *
     * @param args  The command-line arguments
     */
    public static void main(String[] args)
    {
        Scanner                    scanner;        
	Map<String, String>        names;       // v2.0
	String                     id, number;

        scanner = new Scanner(System.in);        

	// Construct a new HashMap
	names = new HashMap<String, String>();     // v2.0


	// Fill the HashMap
	names.put("540-568-1671","Bernstein, D.");
	names.put("540-568-2773","Fox, C.");
	names.put("540-568-6288","Grove, R.");
	names.put("540-568-2774","Harris, A.");
	names.put("540-568-8771","Harris, N.");
	names.put("540-568-8745","Heydari, N.");
	names.put("540-568-2772","Lane, M.");
	names.put("540-568-2727","Marchal, J.");
	names.put("540-568-2775","Mata-Toledo, R.");
	names.put("540-568-2777","Norton, M.");


	// Prompt the user to enter a phone number
	// and then display the appropriate name
	do 
        {
           System.out.print("Phone Number: ");
           number = scanner.nextLine();
           
           id = names.get(number);          // v2.0

           if (id != null) System.out.printf("%s\n", id);
	} 
        while (!number.equals(""));
    }

}
