|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
2
|
|
|
3
|
+import java.util.ArrayList;
|
3
|
4
|
import java.util.Map;
|
4
|
5
|
import java.util.Set;
|
5
|
6
|
import java.util.TreeMap;
|
|
@@ -7,7 +8,9 @@ import java.util.TreeMap;
|
7
|
8
|
public class PhoneBook {
|
8
|
9
|
|
9
|
10
|
//the below defines what kind of attribute you have, which in this case is your "contacts"
|
10
|
|
- Map<String, Person> personMap;
|
|
11
|
+ TreeMap<String, String> personMap;
|
|
12
|
+
|
|
13
|
+ String name = "";
|
11
|
14
|
|
12
|
15
|
//this is your constructor. whenever you see public + the classname, that is your constructor
|
13
|
16
|
//
|
|
@@ -21,14 +24,16 @@ public class PhoneBook {
|
21
|
24
|
// this treeMap initializes the "blank pages of the book". the treemap is the structure of how your book will hold info
|
22
|
25
|
|
23
|
26
|
//if you were to not set this, your person map would be null(default setting)
|
24
|
|
- this.personMap = new TreeMap<String, Person>();
|
|
27
|
+ this.personMap = new TreeMap<String, String>();
|
25
|
28
|
}
|
26
|
29
|
|
27
|
30
|
// this is our method below. it describes what we can do with this phonebook
|
28
|
31
|
|
29
|
32
|
//so later, when you call "phonebook.add", that's like someone literally writing a new name and number in your phonebook object
|
30
|
|
- public void add(String name, String number){
|
31
|
|
- this.personMap.put(name, new Person(name, number));
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+ public void add(String name, String number) {
|
|
36
|
+ personMap.put(name, number);
|
32
|
37
|
}
|
33
|
38
|
|
34
|
39
|
/*
|
|
@@ -40,18 +45,23 @@ public class PhoneBook {
|
40
|
45
|
|
41
|
46
|
*/
|
42
|
47
|
|
43
|
|
- public Person lookup(String name) {
|
|
48
|
+ public void remove(String name, String number) {
|
44
|
49
|
|
45
|
|
- return personMap.get(name);
|
|
50
|
+ personMap.remove(name);
|
|
51
|
+ }
|
|
52
|
+
|
|
53
|
+ public String lookup(String name) {
|
|
54
|
+
|
|
55
|
+ return personMap.get(name);
|
46
|
56
|
|
47
|
57
|
}
|
48
|
58
|
|
49
|
|
- public String reverseLookup (String phoneNumber){
|
|
59
|
+ /* public String reverseLookup (String phoneNumber){
|
50
|
60
|
|
51
|
61
|
//this will "grab" all the listings in your book. it does NOT print them.
|
52
|
|
- Set<Map.Entry<String, Person>> entries = personMap.entrySet();
|
|
62
|
+ Set<Map.Entry<String, String> = personMap.entrySet();
|
53
|
63
|
|
54
|
|
- for (Map.Entry<String, Person> phoneBookEntry : entries) {
|
|
64
|
+ for (Map.Entry<String, String> phoneBookEntry : entries) {
|
55
|
65
|
|
56
|
66
|
Person person = phoneBookEntry.getValue();
|
57
|
67
|
|
|
@@ -64,5 +74,17 @@ public class PhoneBook {
|
64
|
74
|
|
65
|
75
|
}
|
66
|
76
|
|
|
77
|
+ */
|
|
78
|
+
|
|
79
|
+ public void displayAllEntries() {
|
|
80
|
+
|
|
81
|
+ for (Map.Entry<String, String> entry : personMap.entrySet()) {
|
|
82
|
+ String name = entry.getKey();
|
|
83
|
+ String number = entry.getValue();
|
|
84
|
+ }
|
|
85
|
+
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+
|
67
|
89
|
}
|
68
|
90
|
|