import java.util.List; import java.util.ArrayList; import java.util.TreeMap; import java.util.Set; import java.util.Iterator; import java.util.Map; import java.util.Collections; /** * Created by leon on 1/23/18. */ public class PhoneBook { TreeMap phoneMap = new TreeMap(); String name; String phoneNumber; public PhoneBook(String name, String phoneNumber){ //Constructor this.name = name; this.phoneNumber = phoneNumber; } public void add(String name, String phoneNumber){ phoneMap.put(name, phoneNumber); } public void remove(String name){ phoneMap.remove(name); } public String lookup(String name){ return phoneMap.get(name); } public String reverseLookup(String phoneNumber){ return phoneMap.get(phoneNumber); } public String display(){ String resultString = ""; for(String e : phoneMap.keySet()){ String v = phoneMap.get(e); resultString = resultString + e + " -> " + v + "\n"; } return resultString; } }