|
@@ -1,7 +1,72 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import java.util.List;
|
|
4
|
+import java.util.Map;
|
|
5
|
+import java.util.Set;
|
|
6
|
+import java.util.TreeMap;
|
|
7
|
+
|
3
|
8
|
/**
|
4
|
9
|
* Created by leon on 1/23/18.
|
5
|
10
|
*/
|
6
|
11
|
public class PhoneBook {
|
|
12
|
+ Map<String,String> phoneBook = new TreeMap<String, String>();
|
|
13
|
+ Set<String>names;
|
|
14
|
+ Set<String>phoneBookList;
|
|
15
|
+ String nameLists="";
|
|
16
|
+ String namesAndNumbers ="";
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+ public PhoneBook(Map<String, String> phoneBook) {
|
|
20
|
+ this.phoneBook = phoneBook;
|
|
21
|
+ }
|
|
22
|
+
|
|
23
|
+ public PhoneBook() {
|
|
24
|
+
|
|
25
|
+ }
|
|
26
|
+
|
|
27
|
+ public void add(String name,String phoneNumber) {
|
|
28
|
+
|
|
29
|
+ phoneBook.put(name, phoneNumber);
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ public void remove(String name){
|
|
33
|
+ if(phoneBook.containsKey(name)){
|
|
34
|
+ phoneBook.remove(name);
|
|
35
|
+ }
|
|
36
|
+ else{
|
|
37
|
+ System.out.println(name+" does not exist in the phone book list");
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ public String lookup(String name){
|
|
43
|
+
|
|
44
|
+ return phoneBook.get(name);
|
|
45
|
+ }
|
|
46
|
+
|
|
47
|
+ public String listNames(){
|
|
48
|
+ if(phoneBook.isEmpty()){
|
|
49
|
+ return null;
|
|
50
|
+ }else {
|
|
51
|
+ Set<String> names = phoneBook.keySet();
|
|
52
|
+
|
|
53
|
+ for (String name : names) {
|
|
54
|
+ nameLists += name + "\n";
|
|
55
|
+ }
|
|
56
|
+ return nameLists;
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+ public String listNamesAndNumbers(){
|
|
62
|
+ Set<String>PhoneBookList = phoneBook.keySet();
|
|
63
|
+ for (String nameKeys:phoneBookList) {
|
|
64
|
+ namesAndNumbers+=nameKeys + " "+phoneBook.get(nameKeys)+ "\n";
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ return namesAndNumbers;
|
|
68
|
+ }
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
7
|
72
|
}
|