Parcourir la source

before reconstruction

Eric Cordell il y a 6 ans
Parent
révision
6fa6558aad

+ 38
- 13
src/main/java/com/zipcodewilmington/phonebook/Person.java Voir le fichier

@@ -1,28 +1,53 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
-class Person {
3
+import java.util.ArrayList;
4
+import java.util.Arrays;
5
+
6
+public class Person {
4 7
 
5 8
     private String personName;
6
-    private String phoneNumber;
9
+    private ArrayList<String> phoneNumbers;
7 10
 
8
-    public Person(String personName, String phoneNumber) {
11
+    public Person(String personName){
9 12
         this.personName = personName;
10
-        this.phoneNumber = phoneNumber;
13
+        this.phoneNumbers = new ArrayList<>();
14
+        phoneNumbers
11 15
     }
12 16
 
17
+
13 18
     public String getPersonName() {
14 19
         return personName;
15 20
     }
16 21
 
17
-    public void setPersonName(String personName) {
18
-        this.personName = personName;
19
-    }
20 22
 
21
-    public String getPhoneNumber() {
22
-        return phoneNumber;
23
-    }
23
+//public String addNumbers(){
24
+//        return null;
25
+//}
26
+
27
+
28
+   //find a way to print each item in the ArrayList in order
29
+   public String getPhoneNumbers() {
30
+       return phoneNumbers.toString();
31
+   }
32
+//       StringBuilder sb = new StringBuilder();
33
+//       for(int i = 0; i < phoneNumbers.size(); i++){
34
+//           if(i == phoneNumbers.size()){
35
+//               sb.append();
36
+//           }
37
+//       }
38
+//        return phoneNumbers;
39
+//    }
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
24 48
 
25
-    public void setPhoneNumber(String phoneNumber) {
26
-        this.phoneNumber = phoneNumber;
27 49
     }
28
-}
50
+
51
+
52
+
53
+

+ 15
- 11
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java Voir le fichier

@@ -1,19 +1,22 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
-import java.util.Map;
4
-import java.util.Set;
5
-import java.util.TreeMap;
3
+import java.util.*;
6 4
 
7 5
 /**
8 6
  * Created by leon on 1/23/18.
9 7
  */
10 8
 public class PhoneBook {
11 9
 
12
-    TreeMap<String, String> phoneBook = new TreeMap<String, String>();
10
+    TreeMap<String, Person> phoneBook;
11
+
12
+public phoneBook(){
13
+    phoneBook = new TreeMap<String, Person>();
14
+    }
13 15
 
14 16
 
15 17
     public void addEntryToPhoneBook(String name, String phoneNumber) {
16
-        phoneBook.put(name, phoneNumber);
18
+       Person person = new Person(name, phoneNumber);
19
+        phoneBook.put(name, person);
17 20
     }
18 21
 
19 22
 
@@ -22,7 +25,7 @@ public class PhoneBook {
22 25
     }
23 26
 
24 27
     public String lookUp(String name) {
25
-        return phoneBook.get(name);
28
+        return phoneBook.get(name).getPhoneNumbers();
26 29
     }
27 30
 
28 31
     public String listNames() {
@@ -36,7 +39,7 @@ public class PhoneBook {
36 39
 
37 40
     public String listNumbers() {
38 41
         String completeListOfNumbers = "";
39
-        for (Map.Entry<String, String> entry : phoneBook.entrySet()) {
42
+        for (Map.Entry<String, Person> entry : phoneBook.entrySet()) {
40 43
             completeListOfNumbers += entry.getValue() + "\n";
41 44
         }
42 45
         return completeListOfNumbers;
@@ -45,17 +48,18 @@ public class PhoneBook {
45 48
 
46 49
     public String entryListAll() {
47 50
         String fullList = "";
48
-        for (Map.Entry<String, String> entry : phoneBook.entrySet()) {
51
+        for (Map.Entry<String, Person> entry : phoneBook.entrySet()) {
49 52
             fullList += entry.getKey() + " : " + entry.getValue() + "\n"; //reverse lookup
50 53
 
51 54
         }
55
+        System.out.println(fullList);
52 56
         return fullList;
53 57
     }
54 58
 
55 59
     public String reverseLookup(String numberToLookUp) {
56
-        for (Map.Entry<String,String > e : phoneBook.entrySet()) {
57
-            if (e.getValue().equals(numberToLookUp)){
58
-                return e.getKey();
60
+        for (Map.Entry<String,Person > entry : phoneBook.entrySet()) {
61
+            if (entry.getValue().equals(numberToLookUp)){
62
+                return entry.getKey();
59 63
             }
60 64
         }return null;
61 65
     }

+ 67
- 0
src/test/java/com/zipcodewilmington/phonebook/PersonTest.java Voir le fichier

@@ -0,0 +1,67 @@
1
+package com.zipcodewilmington.phonebook;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+
7
+import java.util.ArrayList;
8
+import java.util.Arrays;
9
+
10
+import static org.junit.Assert.*;
11
+
12
+public class PersonTest {
13
+
14
+
15
+    @Test
16
+    public void getPersonNameTest() {
17
+        //Given
18
+        Person human = new Person("Eric", "302-999-1234");
19
+
20
+        //When
21
+        String expectedName = "Eric";
22
+        String expectedNumber = "302-999-1234";
23
+        String actual = human.getPersonName() + human.getPhoneNumbers();
24
+
25
+
26
+        Assert.assertTrue(actual.contains(expectedName) && actual.contains(expectedNumber));
27
+    }
28
+
29
+//@Test
30
+//    public void addNumbersTest() {
31
+//        //Given
32
+//    Person human = new Person("Eric", "302-999-1234");
33
+//
34
+//    //When
35
+//    human.addNumbers("302-222-9876");
36
+//    String expectedNumber = "302-222-1234";
37
+//    String actual = human.getPhoneNumbers();
38
+//
39
+//    Assert.assertTrue(actual.contains(expectedNumber));
40
+//}
41
+
42
+@Test
43
+    public void printNameTest(){
44
+        //Given
45
+    Person human = new Person("Eric", "302-999-1234");
46
+
47
+    //When
48
+    String expectedName = "Eric";
49
+    String actual = human.getPersonName();
50
+
51
+    Assert.assertTrue(actual.contains(expectedName));
52
+}
53
+
54
+//@Test
55
+//    public void printNumbersTest(){
56
+//        //Given
57
+//    Person human = new Person("Eric", "302-999-1234");
58
+//    human.addNumbers("302-222-9876");
59
+//
60
+//    //When
61
+//    String expectedNumbers = "";
62
+//
63
+//}
64
+
65
+
66
+}
67
+

+ 12
- 9
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java Voir le fichier

@@ -5,6 +5,8 @@ import org.junit.Assert;
5 5
 import org.junit.Before;
6 6
 import org.junit.Test;
7 7
 
8
+import java.util.ArrayList;
9
+
8 10
 /**
9 11
  * Created by leon on 1/23/18.
10 12
  */
@@ -14,13 +16,14 @@ public class PhoneBookTest {
14 16
     @Before
15 17
     public void setUp() {
16 18
         phoneBook = new PhoneBook();
17
-        phoneBook.addEntryToPhoneBook("Eric", "3021234567");
18
-        phoneBook.addEntryToPhoneBook("Bob", "3029999999");
19
+        phoneBook.addEntryToPhoneBook("Eric", "302-123-4567");
20
+        phoneBook.addEntryToPhoneBook("Bob", "302-999-9999");
19 21
     }
20 22
 
23
+
21 24
     @Test
22 25
     public void testAddPhoneBookEntryToPhoneBook() {
23
-        String phoneNumber = "3025551111";
26
+        String phoneNumber = "302-555-1111";
24 27
         phoneBook.addEntryToPhoneBook("eric", phoneNumber);
25 28
         String actual = phoneBook.lookUp("eric");
26 29
         Assert.assertEquals(phoneNumber, actual);
@@ -28,7 +31,7 @@ public class PhoneBookTest {
28 31
 
29 32
     @Test
30 33
     public void testRemoveEntryFromPhoneBook() {
31
-        String phoneNumber = "3025551111";
34
+        String phoneNumber = "302-555-1111";
32 35
         String name = "eric";
33 36
         phoneBook.addEntryToPhoneBook(name, phoneNumber);
34 37
         phoneBook.removeEntryFromPhoneBook("eric", phoneNumber);
@@ -50,8 +53,8 @@ public class PhoneBookTest {
50 53
     public void testListNumber() {
51 54
 
52 55
 
53
-        String expected = "3029999999\n" +
54
-                "3021234567\n";
56
+        String expected = "302-999-9999\n" +
57
+                "302-123-4567\n";
55 58
         String actual = phoneBook.listNumbers();
56 59
 
57 60
         Assert.assertEquals(expected, actual);
@@ -61,8 +64,8 @@ public class PhoneBookTest {
61 64
     public void testEntryListAll() {
62 65
 
63 66
 
64
-        String expected = "Bob : 3029999999\n" +
65
-                "Eric : 3021234567\n";
67
+        String expected = "Bob : 302-999-9999\n" +
68
+                "Eric : 302-123-4567\n";
66 69
         String actual = phoneBook.entryListAll();
67 70
 
68 71
         Assert.assertEquals(expected, actual);
@@ -74,7 +77,7 @@ public class PhoneBookTest {
74 77
     public void testReverseLookup() {
75 78
         String expected = "Bob";
76 79
 
77
-        String actual = phoneBook.reverseLookup("3029999999");
80
+        String actual = phoneBook.reverseLookup("302-999-9999");
78 81
         Assert.assertEquals(expected,actual);
79 82
     }
80 83