|
@@ -65,25 +65,31 @@ public class PhoneBook {
|
65
|
65
|
|
66
|
66
|
printBook.append(key).append(" = ").append(value).append("\n");
|
67
|
67
|
|
68
|
|
-// String allInfo = "";
|
69
|
|
-//
|
70
|
|
-// for (Map.Entry<String, String> entry: myTree.entrySet()){
|
71
|
|
-// String getKeys = String.format("%1$-15s", entry.getKey());
|
72
|
|
-// String getValues = String.format("%1$-15s", entry.getValue());
|
73
|
|
-//
|
74
|
|
-// allInfo += getKeys + getValues + "\n";
|
75
|
68
|
}
|
76
|
69
|
String result = printBook.toString();
|
77
|
70
|
|
78
|
71
|
return result;
|
79
|
72
|
}
|
80
|
73
|
|
81
|
|
- public String reverseLookup() {
|
|
74
|
+ public String reverseLookup(String number) {
|
|
75
|
+
|
|
76
|
+ String getName = "";
|
|
77
|
+ for (Map.Entry<String, String> entry : myTree.entrySet()) {
|
|
78
|
+ if (entry.getValue() == number) {
|
|
79
|
+ getName += entry.getKey();
|
|
80
|
+ return getName;
|
|
81
|
+ }
|
|
82
|
+
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+ return "not in my phone book";
|
82
|
87
|
|
83
|
|
- return null;
|
84
|
88
|
}
|
85
|
89
|
|
86
|
90
|
|
|
91
|
+
|
|
92
|
+
|
87
|
93
|
public static void main(String[] args) {
|
88
|
94
|
|
89
|
95
|
PhoneBook phonebookEntry = new PhoneBook();
|
|
@@ -99,7 +105,7 @@ public class PhoneBook {
|
99
|
105
|
|
100
|
106
|
|
101
|
107
|
phonebookEntry.listPhoneBook();
|
102
|
|
- System.out.println(phonebookEntry.listPhoneBook());
|
|
108
|
+ System.out.println(phonebookEntry.reverseLookup("4899994190"));
|
103
|
109
|
|
104
|
110
|
}
|
105
|
111
|
|