|
@@ -1,7 +1,63 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
|
2
|
+import java.util.Map;
|
|
3
|
+import java.util.Set;
|
|
4
|
+import java.util.HashMap;
|
2
|
5
|
|
3
|
6
|
/**
|
4
|
7
|
* Created by leon on 1/23/18.
|
5
|
8
|
*/
|
6
|
9
|
public class PhoneBook {
|
|
10
|
+
|
|
11
|
+ String name;
|
|
12
|
+ String number;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+ private Map<String, String> contactsList;
|
|
16
|
+
|
|
17
|
+ public PhoneBook(){
|
|
18
|
+ this.contactsList = new HashMap<String, String>();
|
|
19
|
+ contactsList.put("Pete Jones", "2678849087");
|
|
20
|
+ contactsList.put("Ron Burgundy", "5604329932");
|
|
21
|
+ contactsList.put("Nala Bits", "2345578122");
|
|
22
|
+
|
|
23
|
+ }
|
|
24
|
+ public Map<String, String> getContactsList(){
|
|
25
|
+ return contactsList;
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ public void addContact(String name, String number) {
|
|
29
|
+ if (!contactsList.containsKey(name)) {
|
|
30
|
+ contactsList.put(name, number);
|
|
31
|
+ System.out.println("New contact " + name + " has been added");
|
|
32
|
+ } else {
|
|
33
|
+ System.out.println("Contact already exists");
|
|
34
|
+ }
|
|
35
|
+ }
|
|
36
|
+
|
|
37
|
+ public void removeContact(String name) {
|
|
38
|
+ if (contactsList.containsKey(name)) {
|
|
39
|
+ contactsList.remove(name);
|
|
40
|
+ System.out.println("Contact has been removed");
|
|
41
|
+ } else {
|
|
42
|
+ System.out.println("No " + name + " contact exists");
|
|
43
|
+ }
|
|
44
|
+ }
|
|
45
|
+
|
|
46
|
+ public String lookUpContactByName(String name){
|
|
47
|
+ return contactsList.get(name) == null ? "Sorry name not found" : contactsList.get(name);
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ public void listAllByName(String name){
|
|
51
|
+ for(String ContactsByName : contactsList.keySet()){
|
|
52
|
+ System.out.println(contactsList.get(name));
|
|
53
|
+ }
|
|
54
|
+
|
|
55
|
+ }
|
|
56
|
+ public void listAllNamesAndNumbers(){
|
|
57
|
+ Set<Map.Entry<String, String>>listingAll = contactsList.entrySet();
|
|
58
|
+ System.out.println(contactsList);
|
|
59
|
+ }
|
|
60
|
+
|
|
61
|
+}
|
|
62
|
+
|
7
|
63
|
}
|