Browse Source

maybe done...

Daniel Horowitz 6 years ago
parent
commit
90df99c1dc

+ 25
- 13
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

3
 import java.util.Set;
3
 import java.util.Set;
4
 import java.util.TreeMap;
4
 import java.util.TreeMap;
5
 import java.util.TreeSet;
5
 import java.util.TreeSet;
6
+import java.util.Map;
6
 
7
 
7
 /**
8
 /**
8
  * Created by leon on 1/23/18.
9
  * Created by leon on 1/23/18.
19
 
20
 
20
     }
21
     }
21
 
22
 
22
-//    public PhoneBook(String name, String number) {
23
-//        this.name = name;
24
-//        this.number = number;
25
-//
26
-//    }
27
 
23
 
28
     public void addEntry(String name, String number) {
24
     public void addEntry(String name, String number) {
29
         myTree.put(name, number);
25
         myTree.put(name, number);
32
     }
28
     }
33
 
29
 
34
 
30
 
35
-    public void remove(String name, String number) {
31
+    public void remove(String name) {
36
         myTree.remove(name);
32
         myTree.remove(name);
37
 
33
 
38
     }
34
     }
39
 
35
 
40
-    public String stringlookup(String name) {
36
+    public String stringLookup(String name) {
41
 
37
 
42
        return myTree.get(name);
38
        return myTree.get(name);
43
 
39
 
46
     }
42
     }
47
 
43
 
48
     public String listNames() {
44
     public String listNames() {
49
-        ;
45
+
46
+
47
+
50
         Set<String> contacts = myTree.keySet();
48
         Set<String> contacts = myTree.keySet();
51
 
49
 
52
         String allNames = "";
50
         String allNames = "";
57
         return allNames;
55
         return allNames;
58
     }
56
     }
59
 
57
 
60
-    public String[] listPhoneBook() {
58
+    public String listPhoneBook() {
59
+
60
+
61
+        String allInfo = "";
61
 
62
 
62
-        return null;
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
+
67
+            allInfo += getKeys + getValues + "\n";
68
+        }
69
+
70
+        return allInfo;
63
     }
71
     }
64
 
72
 
65
 
73
 
70
         phonebookEntry.addEntry("Brian", "3027619121");
78
         phonebookEntry.addEntry("Brian", "3027619121");
71
         phonebookEntry.addEntry("Dan", "4846394190");
79
         phonebookEntry.addEntry("Dan", "4846394190");
72
         phonebookEntry.addEntry("Garret", "3027894586");
80
         phonebookEntry.addEntry("Garret", "3027894586");
81
+        phonebookEntry.addEntry("Luke", "3147619121");
82
+        phonebookEntry.addEntry("Kate", "4899994190");
83
+        phonebookEntry.addEntry("Lenore", "3097894586");
84
+
85
+
73
 
86
 
74
-        System.out.println(phonebookEntry.listNames());
75
 
87
 
76
-        phonebookEntry.stringlookup("Brian");
88
+        phonebookEntry.listPhoneBook();
89
+        System.out.println(phonebookEntry.listPhoneBook());
77
 
90
 
78
-        System.out.println(phonebookEntry.stringlookup("Dan"));
79
     }
91
     }
80
 
92
 
81
 }
93
 }

+ 39
- 10
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

11
  */
11
  */
12
 public class PhoneBookTest {
12
 public class PhoneBookTest {
13
 
13
 
14
-    @Before
15
-    public void setUp() {
16
-        testBook = new PhoneBook();
17
-    }
18
 
14
 
15
+    @Test
16
+    public void addTest() {
17
+        PhoneBook testBook = new PhoneBook();
18
+        testBook.addEntry("Luke", "6109998787");
19
+        String testNumber = testBook.stringLookup("Luke");
20
+        Assert.assertTrue(testNumber.equals("6109998787"));
19
 
21
 
22
+    }
20
 
23
 
24
+    @Test
25
+    public void addTest1() {
26
+        PhoneBook testBook = new PhoneBook();
27
+        testBook.addEntry("Kate", "4846569090");
28
+        String testNumber = testBook.stringLookup("Kate");
29
+        Assert.assertTrue(testNumber.equals("4846569090"));
30
+
31
+    }
21
 
32
 
22
     @Test
33
     @Test
23
-    public void addTest() {
34
+    public void removeTest1() {
35
+        PhoneBook testBook = new PhoneBook();
36
+        testBook.addEntry("Kate", "4846569090");
37
+        testBook.remove("Kate");
38
+        String testNumber = testBook.stringLookup("Kate");
39
+        Assert.assertEquals(null, testNumber);
24
 
40
 
41
+
42
+    }
43
+
44
+    @Test
45
+    public void stringLookupTest() {
25
         PhoneBook testBook = new PhoneBook();
46
         PhoneBook testBook = new PhoneBook();
26
-        String name = "Dan";
27
-        String number = "4847986543";
28
-       // String expected = "Dan 4847986543";
47
+        testBook.addEntry("Kate", "4846569090");
48
+        String testNumber = testBook.stringLookup("Kate");
49
+        Assert.assertFalse(testNumber.equals("4846587091"));
29
 
50
 
30
-        testBook.add(name, number);
31
-        Assert.assertEquals(expected, actual);
32
     }
51
     }
33
 
52
 
53
+    @Test
54
+    public void stringLookupTest1() {
55
+        PhoneBook testBook = new PhoneBook();
56
+        testBook.addEntry("Kate", "4846569090");
57
+        String testNumber = testBook.stringLookup("Kate");
58
+        Assert.assertTrue(testNumber.equals("4846569090"));
59
+
60
+    }
34
 
61
 
35
 
62
 
36
 }
63
 }
64
+
65
+