|
@@ -1,7 +1,47 @@
|
1
|
1
|
|
|
2
|
+import java.util.List;
|
|
3
|
+import java.util.ArrayList;
|
|
4
|
+import java.util.TreeMap;
|
|
5
|
+import java.util.Set;
|
|
6
|
+import java.util.Iterator;
|
|
7
|
+import java.util.Map;
|
|
8
|
+import java.util.Collections;
|
2
|
9
|
|
3
|
10
|
/**
|
4
|
11
|
* Created by leon on 1/23/18.
|
5
|
12
|
*/
|
6
|
13
|
public class PhoneBook {
|
|
14
|
+ TreeMap<String,String> phoneMap = new TreeMap<String, String>();
|
|
15
|
+ String name;
|
|
16
|
+ String phoneNumber;
|
|
17
|
+ public PhoneBook(String name, String phoneNumber){
|
|
18
|
+ //Constructor
|
|
19
|
+ this.name = name;
|
|
20
|
+ this.phoneNumber = phoneNumber;
|
|
21
|
+ }
|
|
22
|
+
|
|
23
|
+ public void add(String name, String phoneNumber){
|
|
24
|
+ phoneMap.put(name, phoneNumber);
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ public void remove(String name){
|
|
28
|
+ phoneMap.remove(name);
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ public String lookup(String name){
|
|
32
|
+ return phoneMap.get(name);
|
|
33
|
+ }
|
|
34
|
+
|
|
35
|
+ public String reverseLookup(String phoneNumber){
|
|
36
|
+ return phoneMap.get(phoneNumber);
|
|
37
|
+ }
|
|
38
|
+
|
|
39
|
+ public String display(){
|
|
40
|
+ String resultString = "";
|
|
41
|
+ for(String e : phoneMap.keySet()){
|
|
42
|
+ String v = phoneMap.get(e);
|
|
43
|
+ resultString = resultString + e + " -> " + v + "\n";
|
|
44
|
+ }
|
|
45
|
+ return resultString;
|
|
46
|
+}
|
7
|
47
|
}
|