|
@@ -12,6 +12,7 @@ public class PhoneBook {
|
12
|
12
|
//instance variable
|
13
|
13
|
private TreeMap<String, String> treeMap;
|
14
|
14
|
|
|
15
|
+
|
15
|
16
|
// void "no arguments" constructor -creates empty map
|
16
|
17
|
public PhoneBook() {
|
17
|
18
|
this.treeMap= new TreeMap<String, String>();
|
|
@@ -24,9 +25,11 @@ public class PhoneBook {
|
24
|
25
|
|
25
|
26
|
//add a name & number entry
|
26
|
27
|
public void add(String name, String number) {
|
|
28
|
+
|
27
|
29
|
if(!treeMap.containsKey(name)) {
|
28
|
30
|
treeMap.put(name, number);
|
29
|
31
|
}
|
|
32
|
+
|
30
|
33
|
}
|
31
|
34
|
|
32
|
35
|
//remove a name & number entry
|
|
@@ -40,13 +43,8 @@ public class PhoneBook {
|
40
|
43
|
|
41
|
44
|
//find phone number lookup by name
|
42
|
45
|
public String lookup(String name) {
|
43
|
|
- String look = "";
|
44
|
|
- if (treeMap.containsKey(name)) {
|
45
|
|
- look = treeMap.get(name);
|
46
|
|
- } else {
|
47
|
|
- look = name + " is not in database";
|
48
|
|
- }
|
49
|
|
- return look;
|
|
46
|
+ String number = treeMap.get(name);
|
|
47
|
+ return number;
|
50
|
48
|
}
|
51
|
49
|
|
52
|
50
|
//print out all of the entries in PhoneBook
|