1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- import java.util.*;
-
-
- /**
- * Created by leon on 1/23/18.
- */
- public class PhoneBook {
- TreeMap<String, String> phoneListName = new TreeMap();
- TreeMap<String, String> 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());
- }
-
- }
-
-
- }
|