|
@@ -1,34 +1,101 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
3
|
|
-import apple.laf.JRSUIUtils;
|
4
|
|
-import com.sun.tools.corba.se.idl.StringGen;
|
5
|
|
-
|
|
3
|
+import java.util.Map;
|
|
4
|
+import java.util.Set;
|
6
|
5
|
import java.util.TreeMap;
|
|
6
|
+import java.util.TreeSet;
|
7
|
7
|
|
8
|
8
|
/**
|
9
|
9
|
* Created by leon on 1/23/18.
|
10
|
10
|
*/
|
11
|
11
|
public class PhoneBook {
|
12
|
12
|
|
13
|
|
- private TreeMap<String, String> tmap;
|
|
13
|
+ private TreeMap<String String> contacts;
|
|
14
|
+
|
|
15
|
+ public PhoneBook() {
|
|
16
|
+
|
|
17
|
+ contacts = new TreeMap<>();
|
|
18
|
+ }
|
|
19
|
+ public void add (String name, String number){
|
|
20
|
+ contacts.put(name, number);
|
|
21
|
+ }
|
|
22
|
+ public String lookup (String name){
|
|
23
|
+ return contacts.get(name);
|
|
24
|
+ }
|
|
25
|
+ public void remove (String name){
|
|
26
|
+ contacts.remove(name);
|
|
27
|
+ }
|
|
28
|
+ public String display (){
|
|
29
|
+ StringBuilder sb = new StringBuilder();
|
|
30
|
+ for (Map.Entry<String, String>entry : contacts.entrySet()){
|
|
31
|
+ String name = entry.getKey();
|
|
32
|
+ String number = entry.getValue();
|
|
33
|
+ sb.append(name + " " + number + "\n");
|
|
34
|
+ }
|
|
35
|
+ return sb.toString();
|
|
36
|
+ }
|
|
37
|
+ public String reverseLookup (String number){
|
|
38
|
+ for (Map.Entry <String, String>entry: contacts.entrySet()){
|
|
39
|
+ if (entry.getValue().equals(number){
|
|
40
|
+ }
|
|
41
|
+ return null;
|
|
42
|
+ }
|
|
43
|
+ }
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
14
|
54
|
|
15
|
|
- PhoneBook(){
|
16
|
55
|
|
17
|
|
- this.tmap =new TreeMap<String, String>();
|
18
|
56
|
|
19
|
|
- }
|
20
|
57
|
|
21
|
|
- public void addAContact(String name, String number) {
|
22
|
|
- this.tmap.put(name, number);
|
23
|
|
- }
|
24
|
58
|
|
25
|
|
- public void removeAContact(String name, String number){
|
26
|
|
- this.tmap.remove(name, number);
|
27
|
|
- }
|
28
|
|
- public void lookupContact (String name, String number){
|
29
|
59
|
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+ public void addAContact(String name, String number) {
|
|
67
|
+ tmap.put(name, number);
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+ public String listOfAllNames(){
|
|
71
|
+ StringBuilder result = new StringBuilder();
|
|
72
|
+ for (Map.Entry<String, String> entry: tmap.entrySet()){
|
|
73
|
+ result.append(String.format("%-20s %8s\n", entry.getKey(), entry.getValue()));
|
|
74
|
+ //formats the way a string will print out on console^^^^^^
|
|
75
|
+ }
|
|
76
|
+ return String.valueOf(result);
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ public void removeAContact(String name) {
|
|
80
|
+ tmap.remove(name);
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ public String lookupContactName(String name) {
|
|
84
|
+ if (tmap.containsKey(name)) {
|
|
85
|
+ return tmap.get(name);
|
|
86
|
+ } else {
|
|
87
|
+ return "This Name Does Not Exist";
|
|
88
|
+ }
|
30
|
89
|
}
|
31
|
90
|
|
32
|
91
|
|
33
|
|
- }
|
|
92
|
+
|
|
93
|
+ public reverseLookUpNumber (String number){
|
|
94
|
+
|
|
95
|
+ }
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+}
|
|
99
|
+
|
|
100
|
+
|
34
|
101
|
|