import java.util.*; /** * Created by leon on 1/23/18. */ public class PhoneBook { TreeMap phoneListName = new TreeMap(); TreeMap phoneListNumber = new TreeMap(); public void add(String name, String number){ phoneListName.put(name, number); phoneListNumber.put(number, name); } public void remove(String name){ String number = lookUp(name); phoneListName.remove(name); phoneListNumber.remove(number); } public String lookUp(String name){ return phoneListName.get(name); } public String reverseLookUp(String number){ return phoneListNumber.get(number); } public void display(){ Set set = phoneListName.entrySet(); Iterator i = set.iterator(); while(i.hasNext()){ Map.Entry me = (Map.Entry)i.next(); System.out.println(me.getKey() + ": " + me.getValue()); } } }