|
@@ -1,7 +1,8 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
import java.util.Map;
|
3
|
3
|
import java.util.Set;
|
4
|
|
-import java.util.HashMap;
|
|
4
|
+import java.util.SortedMap;
|
|
5
|
+import java.util.TreeMap;
|
5
|
6
|
|
6
|
7
|
/**
|
7
|
8
|
* Created by leon on 1/23/18.
|
|
@@ -15,7 +16,7 @@ public class PhoneBook {
|
15
|
16
|
private Map<String, String> contactsList;
|
16
|
17
|
|
17
|
18
|
public PhoneBook(){
|
18
|
|
- this.contactsList = new HashMap<String, String>();
|
|
19
|
+ this.contactsList = new TreeMap<String, String>();
|
19
|
20
|
contactsList.put("Pete Jones", "2678849087");
|
20
|
21
|
contactsList.put("Ron Burgundy", "5604329932");
|
21
|
22
|
contactsList.put("Nala Bits", "2345578122");
|
|
@@ -23,6 +24,7 @@ public class PhoneBook {
|
23
|
24
|
}
|
24
|
25
|
public Map<String, String> getContactsList(){
|
25
|
26
|
return contactsList;
|
|
27
|
+
|
26
|
28
|
}
|
27
|
29
|
|
28
|
30
|
public void addContact(String name, String number) {
|
|
@@ -47,17 +49,21 @@ public class PhoneBook {
|
47
|
49
|
return contactsList.get(name) == null ? "Sorry name not found" : contactsList.get(name);
|
48
|
50
|
}
|
49
|
51
|
|
50
|
|
- public void listAllByName(String name){
|
51
|
|
- for(String ContactsByName : contactsList.keySet()){
|
52
|
|
- System.out.println(contactsList.get(name));
|
|
52
|
+ public String listAllByName(String strings) {
|
|
53
|
+ Set nameSet = contactsList.keySet();
|
|
54
|
+ for (Object names : nameSet) {
|
|
55
|
+ return names.toString();
|
53
|
56
|
}
|
54
|
57
|
|
55
|
|
- }
|
56
|
|
- public void listAllNamesAndNumbers(){
|
57
|
|
- Set<Map.Entry<String, String>>listingAll = contactsList.entrySet();
|
58
|
|
- System.out.println(contactsList);
|
59
|
|
- }
|
60
|
58
|
|
61
|
|
-}
|
|
59
|
+ public String listAllNamesAndNumbers(){
|
|
60
|
+ Set listingAll = contactsList.entrySet();
|
|
61
|
+ for (Object allEntries : listingAll )
|
|
62
|
+ return allEntries.toString();
|
62
|
63
|
|
|
64
|
+ }
|
|
65
|
+ }
|
63
|
66
|
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|