Answer:
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class PhoneBook {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Map<String, String> map = new HashMap<>();
String name, number, choice;
do {
System.out.print("Enter name: ");
name = in.next();
System.out.print("Enter number: ");
number = in.next();
map.put(name, number);
System.out.print("Do you want to try again(y or n): ");
choice = in.next();
} while (!choice.equalsIgnoreCase("n"));
System.out.print("Enter name to search for: ");
name = in.next();
if (map.containsKey(name)) {
System.out.println(map.get(name));
} else {
System.out.println(name + " is not in the phone book");
}
}
}