Daniel Horowitz 6 years ago
parent
commit
be7923bbd5

+ 19
- 6
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

@@ -57,17 +57,30 @@ public class PhoneBook {
57 57
 
58 58
     public String listPhoneBook() {
59 59
 
60
+        StringBuilder printBook = new StringBuilder();
60 61
 
61
-        String allInfo = "";
62
+        for (Map.Entry<String, String> entry : myTree.entrySet()) {
63
+            String key = entry.getKey();
64
+            String value = entry.getValue();
62 65
 
63
-        for (Map.Entry<String, String> entry: myTree.entrySet()){
64
-            String getKeys = String.format("%1$-15s", entry.getKey());
65
-            String getValues = String.format("%1$-15s", entry.getValue());
66
+            printBook.append(key).append(" = ").append(value).append("\n");
66 67
 
67
-            allInfo += getKeys + getValues + "\n";
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";
68 75
         }
76
+        String result = printBook.toString();
69 77
 
70
-        return allInfo;
78
+        return result;
79
+    }
80
+
81
+    public String reverseLookup() {
82
+
83
+        return null;
71 84
     }
72 85
 
73 86
 

+ 24
- 1
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

@@ -59,7 +59,30 @@ public class PhoneBookTest {
59 59
 
60 60
     }
61 61
 
62
+    @Test
63
+    public void listNamesTest1() {
64
+        PhoneBook testBook = new PhoneBook();
65
+        testBook.addEntry("Kate", "4846569090");
66
+        testBook.addEntry("Adam", "4864569090");
67
+        testBook.addEntry("Zeke", "4787869090");
68
+        String actual = testBook.listNames();
69
+        String expected = "Adam\nKate\nZeke\n";
70
+        Assert.assertEquals(actual, expected);
62 71
 
63
-}
64 72
 
73
+    }
65 74
 
75
+    @Test
76
+    public void listPhonebookTest1() {
77
+        PhoneBook testBook = new PhoneBook();
78
+        testBook.addEntry("Kate", "4846569090");
79
+        testBook.addEntry("Adam", "4864569090");
80
+        testBook.addEntry("Zeke", "4787869090");
81
+        String actual = testBook.listPhoneBook();
82
+        String expected = "Adam = 4864569090\nKate = 4846569090\nZeke = 4787869090\n";
83
+        Assert.assertEquals(actual, expected);
84
+
85
+
86
+    }
87
+
88
+}