|
@@ -1,7 +1,81 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import java.util.Set;
|
|
4
|
+import java.util.TreeMap;
|
|
5
|
+import java.util.TreeSet;
|
|
6
|
+
|
3
|
7
|
/**
|
4
|
8
|
* Created by leon on 1/23/18.
|
5
|
9
|
*/
|
6
|
10
|
public class PhoneBook {
|
|
11
|
+
|
|
12
|
+ private String name;
|
|
13
|
+ private String number;
|
|
14
|
+
|
|
15
|
+ TreeMap<String, String> myTree = new TreeMap<String, String>();
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+ public PhoneBook(){
|
|
19
|
+
|
|
20
|
+ }
|
|
21
|
+
|
|
22
|
+// public PhoneBook(String name, String number) {
|
|
23
|
+// this.name = name;
|
|
24
|
+// this.number = number;
|
|
25
|
+//
|
|
26
|
+// }
|
|
27
|
+
|
|
28
|
+ public void addEntry(String name, String number) {
|
|
29
|
+ myTree.put(name, number);
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+ }
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+ public void remove(String name, String number) {
|
|
36
|
+ myTree.remove(name);
|
|
37
|
+
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ public String stringlookup(String name) {
|
|
41
|
+
|
|
42
|
+ return myTree.get(name);
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ public String listNames() {
|
|
49
|
+ ;
|
|
50
|
+ Set<String> contacts = myTree.keySet();
|
|
51
|
+
|
|
52
|
+ String allNames = "";
|
|
53
|
+ for (String contact : contacts) {
|
|
54
|
+ allNames += contact + "\n";
|
|
55
|
+
|
|
56
|
+ }
|
|
57
|
+ return allNames;
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ public String[] listPhoneBook() {
|
|
61
|
+
|
|
62
|
+ return null;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+ public static void main(String[] args) {
|
|
67
|
+
|
|
68
|
+ PhoneBook phonebookEntry = new PhoneBook();
|
|
69
|
+
|
|
70
|
+ phonebookEntry.addEntry("Brian", "3027619121");
|
|
71
|
+ phonebookEntry.addEntry("Dan", "4846394190");
|
|
72
|
+ phonebookEntry.addEntry("Garret", "3027894586");
|
|
73
|
+
|
|
74
|
+ System.out.println(phonebookEntry.listNames());
|
|
75
|
+
|
|
76
|
+ phonebookEntry.stringlookup("Brian");
|
|
77
|
+
|
|
78
|
+ System.out.println(phonebookEntry.stringlookup("Dan"));
|
|
79
|
+ }
|
|
80
|
+
|
7
|
81
|
}
|