|
@@ -3,6 +3,7 @@ package com.zipcodewilmington.phonebook;
|
3
|
3
|
import java.util.Set;
|
4
|
4
|
import java.util.TreeMap;
|
5
|
5
|
import java.util.TreeSet;
|
|
6
|
+import java.util.Map;
|
6
|
7
|
|
7
|
8
|
/**
|
8
|
9
|
* Created by leon on 1/23/18.
|
|
@@ -19,11 +20,6 @@ public class PhoneBook {
|
19
|
20
|
|
20
|
21
|
}
|
21
|
22
|
|
22
|
|
-// public PhoneBook(String name, String number) {
|
23
|
|
-// this.name = name;
|
24
|
|
-// this.number = number;
|
25
|
|
-//
|
26
|
|
-// }
|
27
|
23
|
|
28
|
24
|
public void addEntry(String name, String number) {
|
29
|
25
|
myTree.put(name, number);
|
|
@@ -32,12 +28,12 @@ public class PhoneBook {
|
32
|
28
|
}
|
33
|
29
|
|
34
|
30
|
|
35
|
|
- public void remove(String name, String number) {
|
|
31
|
+ public void remove(String name) {
|
36
|
32
|
myTree.remove(name);
|
37
|
33
|
|
38
|
34
|
}
|
39
|
35
|
|
40
|
|
- public String stringlookup(String name) {
|
|
36
|
+ public String stringLookup(String name) {
|
41
|
37
|
|
42
|
38
|
return myTree.get(name);
|
43
|
39
|
|
|
@@ -46,7 +42,9 @@ public class PhoneBook {
|
46
|
42
|
}
|
47
|
43
|
|
48
|
44
|
public String listNames() {
|
49
|
|
- ;
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
50
|
48
|
Set<String> contacts = myTree.keySet();
|
51
|
49
|
|
52
|
50
|
String allNames = "";
|
|
@@ -57,9 +55,19 @@ public class PhoneBook {
|
57
|
55
|
return allNames;
|
58
|
56
|
}
|
59
|
57
|
|
60
|
|
- public String[] listPhoneBook() {
|
|
58
|
+ public String listPhoneBook() {
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+ String allInfo = "";
|
61
|
62
|
|
62
|
|
- return null;
|
|
63
|
+ for (Map.Entry<String, String> entry: myTree.entrySet()){
|
|
64
|
+ String getKeys = String.format("%1$-15s", entry.getKey());
|
|
65
|
+ String getValues = String.format("%1$-15s", entry.getValue());
|
|
66
|
+
|
|
67
|
+ allInfo += getKeys + getValues + "\n";
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ return allInfo;
|
63
|
71
|
}
|
64
|
72
|
|
65
|
73
|
|
|
@@ -70,12 +78,16 @@ public class PhoneBook {
|
70
|
78
|
phonebookEntry.addEntry("Brian", "3027619121");
|
71
|
79
|
phonebookEntry.addEntry("Dan", "4846394190");
|
72
|
80
|
phonebookEntry.addEntry("Garret", "3027894586");
|
|
81
|
+ phonebookEntry.addEntry("Luke", "3147619121");
|
|
82
|
+ phonebookEntry.addEntry("Kate", "4899994190");
|
|
83
|
+ phonebookEntry.addEntry("Lenore", "3097894586");
|
|
84
|
+
|
|
85
|
+
|
73
|
86
|
|
74
|
|
- System.out.println(phonebookEntry.listNames());
|
75
|
87
|
|
76
|
|
- phonebookEntry.stringlookup("Brian");
|
|
88
|
+ phonebookEntry.listPhoneBook();
|
|
89
|
+ System.out.println(phonebookEntry.listPhoneBook());
|
77
|
90
|
|
78
|
|
- System.out.println(phonebookEntry.stringlookup("Dan"));
|
79
|
91
|
}
|
80
|
92
|
|
81
|
93
|
}
|