|
@@ -41,7 +41,7 @@ public class PhoneBook {
|
41
|
41
|
if(reverseLookup(phoneNumber).equals("no match")){
|
42
|
42
|
System.out.println("\n**Number not found.**");
|
43
|
43
|
}else{
|
44
|
|
- System.out.println("This is " + reverseLookup(phoneNumber) + "'s number.");
|
|
44
|
+ System.out.println("\n**" + phoneNumber + " listed to:**\n" + reverseLookup(phoneNumber));
|
45
|
45
|
}
|
46
|
46
|
continueMessage();
|
47
|
47
|
break;
|
|
@@ -149,15 +149,14 @@ public class PhoneBook {
|
149
|
149
|
}
|
150
|
150
|
|
151
|
151
|
public String reverseLookup(String number){
|
152
|
|
- String nameForAGivenNumber = "no match";
|
|
152
|
+ StringBuilder personsWithGivenNumber = new StringBuilder();
|
153
|
153
|
for(String name: phonebook.keySet()){
|
154
|
154
|
Entry entry = phonebook.get(name);
|
155
|
|
- String phoneNumber = entry.getPhoneNumber();
|
156
|
|
- if (phoneNumber.equals(number)){
|
157
|
|
- nameForAGivenNumber = name;
|
|
155
|
+ if (entry.hasPhoneNumber(number)){
|
|
156
|
+ personsWithGivenNumber.append(name + "\n");
|
158
|
157
|
}
|
159
|
158
|
}
|
160
|
|
- return nameForAGivenNumber;
|
|
159
|
+ return personsWithGivenNumber.toString();
|
161
|
160
|
}
|
162
|
161
|
|
163
|
162
|
//Deletion
|