Keith Brinker 6 years ago
parent
commit
6d2e6fea86

+ 4
- 4
src/main/java/com/zipcodewilmington/phonebook/Main.java View File

@@ -5,10 +5,10 @@ public class Main {
5 5
     public static void main(String[] args) {
6 6
 
7 7
         PhoneBook tester = new PhoneBook();
8
-        tester.add("Keith", "555-666-7777");
9
-        tester.add("John", "555-612-7777");
10
-        tester.add("Mike", "555-623-7777");
11
-        tester.add("Steve", "555-645-7777");
8
+        tester.addName("Keith", "555-666-7777");
9
+        tester.addName("John", "555-612-7777");
10
+        tester.addName("Mike", "555-623-7777");
11
+        tester.addName("Steve", "555-645-7777");
12 12
        String s = tester.listNames();
13 13
         System.out.println(s);
14 14
 

+ 8
- 7
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

@@ -19,11 +19,11 @@ public class PhoneBook {
19 19
 public PhoneBook() {
20 20
 }
21 21
 
22
- public void add(String name, String phonenum){
22
+ public void addName(String name, String phonenum){
23 23
        contacts.put(name, new PhoneNumberStorage(name, phonenum));
24 24
  }
25 25
 
26
-    public void add(String name, PhoneNumberStorage phoneNumberStorage){
26
+    public void addName(String name, PhoneNumberStorage phoneNumberStorage){
27 27
         contacts.put(name, phoneNumberStorage);
28 28
     }
29 29
 
@@ -58,11 +58,12 @@ public PhoneBook() {
58 58
     }
59 59
 
60 60
     public String reverselookup(String number){
61
-        Set<String> names = contacts.keySet();
62
-        for(String name: names)
63
-        {
64
-            if (contacts.get(name).equals(number)){
65
-                return name;
61
+        //Set<String> names = contacts.keySet();
62
+        for(PhoneNumberStorage nums : contacts.values())
63
+        { for( String phoneNumbers : nums.getPhoneNumbers())
64
+
65
+            if (number.equals(phoneNumbers)){
66
+                return nums.lookup();
66 67
             }
67 68
         }
68 69
         return null;

+ 14
- 2
src/main/java/com/zipcodewilmington/phonebook/PhoneNumberStorage.java View File

@@ -4,8 +4,9 @@ import java.util.ArrayList;
4 4
 
5 5
 public class PhoneNumberStorage {
6 6
 
7
-    String name;
8
-    ArrayList<String> phoneNumbers;
7
+    public String name;
8
+    public ArrayList<String> phoneNumbers;
9
+
9 10
 
10 11
     public PhoneNumberStorage(String name, ArrayList<String> phoneNumbers) {
11 12
         this.name = name;
@@ -17,4 +18,15 @@ public class PhoneNumberStorage {
17 18
         temp.add(phoneNumbers);
18 19
         new PhoneNumberStorage(name, temp);
19 20
     }
21
+
22
+
23
+
24
+
25
+    public String lookup(){
26
+        return this.name;
27
+    }
28
+
29
+    public ArrayList<String> getPhoneNumbers() {
30
+        return phoneNumbers;
31
+    }
20 32
 }

+ 30
- 28
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

@@ -22,36 +22,37 @@ public class PhoneBookTest {
22 22
         // Given
23 23
         PhoneBook testbook = new PhoneBook();
24 24
         PhoneNumberStorage temp = new PhoneNumberStorage("Keith", "555-666-7777");
25
-       testbook.add("Keith", temp);
25
+       testbook.addName("Keith", temp);
26 26
 
27 27
       PhoneNumberStorage testNumber = testbook.lookup("Keith");
28 28
       Assert.assertTrue(testNumber.equals(temp));
29 29
 
30 30
     }
31
-//@Test
32
-//    public void testPhoneBookDelete(){
33
-//        PhoneBook testbook = new PhoneBook();
34
-//        testbook.add("Keith", "555-666-7777");
35
-//        testbook.deleter("Keith");
36
-//        String testnumber = testbook.lookup("Keith");
37
-//        Assert.assertEquals(null, testnumber);
38
-//    }
39
-//@Test
40
-//    public void testPhoneBookLookUp(){
41
-//        PhoneBook testbook = new PhoneBook();
42
-//        testbook.add("Keith", "555-666-7777");
43
-//        String testnumber = testbook.lookup("Keith");
44
-//        Assert.assertEquals("555-666-7777", testnumber);
45
-//    }
31
+@Test
32
+    public void testPhoneBookDelete(){
33
+        PhoneBook testbook = new PhoneBook();
34
+        testbook.addName("Keith", "555-666-7777");
35
+        testbook.deleter("Keith");
36
+        PhoneNumberStorage temp = testbook.lookup("Keith");
37
+        Assert.assertNull(temp );
38
+    }
39
+@Test
40
+    public void testPhoneBookLookUp(){
41
+        PhoneBook testbook = new PhoneBook();
42
+        PhoneNumberStorage temp = new PhoneNumberStorage("Keith", "555-666-7777");
43
+        testbook.addName("Keith", temp);
44
+        PhoneNumberStorage actual = testbook.lookup("Keith");
45
+        Assert.assertEquals(actual, temp);
46
+    }
46 47
 
47 48
     @Test
48 49
     public void testPhoneBookList(){
49 50
 
50 51
         PhoneBook testbook = new PhoneBook();
51
-        testbook.add("Keith", "555-666-7777");
52
-        testbook.add("John", "555-612-7777");
53
-        testbook.add("Mike", "555-623-7777");
54
-        testbook.add("Steve", "555-645-7777");
52
+        testbook.addName("Keith", "555-666-7777");
53
+        testbook.addName("John", "555-612-7777");
54
+        testbook.addName("Mike", "555-623-7777");
55
+        testbook.addName("Steve", "555-645-7777");
55 56
 
56 57
         String expected = "John 555-612-7777\n" +
57 58
                 "Keith 555-666-7777\n" +
@@ -65,10 +66,10 @@ public class PhoneBookTest {
65 66
     public void testPhoneBookNames(){
66 67
 
67 68
         PhoneBook testbook = new PhoneBook();
68
-        testbook.add("Keith", "555-666-7777");
69
-        testbook.add("John", "555-612-7777");
70
-        testbook.add("Mike", "555-623-7777");
71
-        testbook.add("Steve", "555-645-7777");
69
+        testbook.addName("Keith", "555-666-7777");
70
+        testbook.addName("John", "555-612-7777");
71
+        testbook.addName("Mike", "555-623-7777");
72
+        testbook.addName("Steve", "555-645-7777");
72 73
 
73 74
         String expected = "John\n" +
74 75
                 "Keith\n" +
@@ -80,10 +81,11 @@ public class PhoneBookTest {
80 81
     @Test
81 82
     public void testPhoneBookReverseLookUp() {
82 83
         PhoneBook testbook = new PhoneBook();
83
-        testbook.add("Keith", "555-666-7777");
84
-        testbook.add("John", "555-612-7777");
85
-        testbook.add("Mike", "555-623-7777");
86
-        testbook.add("Steve", "555-645-7777");
84
+
85
+        testbook.addName("Keith", "555-666-7777");
86
+        testbook.addName("John", "555-612-7777");
87
+        testbook.addName("Mike", "555-623-7777");
88
+        testbook.addName("Steve", "555-645-7777");
87 89
         String testnumber = testbook.reverselookup("555-666-7777");
88 90
         Assert.assertEquals("Keith", testnumber);
89 91
     }