123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
-
- 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<String,String> phoneMap = new TreeMap<String, String>();
- 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;
- }
- }
|