import java.util.*; import java.util.TreeMap; import java.util.Set; import java.util.Map; import java.util.Iterator; public class PhoneBook { String phoneNumber; Map pb = new TreeMap (); public PhoneBook(){ } public void add(String name, String phoneNumber){ pb.put(name, phoneNumber); } public void remove(String name){ pb.remove(name); } public String display(){ Set set = pb.entrySet(); Iterator it = set.iterator(); StringBuilder display = new StringBuilder(); while(it.hasNext()) { Map.Entry me = (Map.Entry)it.next(); display.append(me.getKey() + " : " + me.getValue() + "\n"); } return display.toString(); } public String lookup(String name){ String phone = pb.get(name); return phone; } public String reverseLookup(String phoneNumber){ String key= null; for(Map.Entry entry: pb.entrySet()){ if(phoneNumber.equals(entry.getValue())){ key = entry.getKey().toString(); break; } } return key; } public int size() { return pb.size(); } }