Browse Source

first commit

mbowe4 6 years ago
parent
commit
5fc439aba8

+ 7
- 0
pom.xml View File

7
     <groupId>com.zipcodewilmington</groupId>
7
     <groupId>com.zipcodewilmington</groupId>
8
     <artifactId>phonebok</artifactId>
8
     <artifactId>phonebok</artifactId>
9
     <version>1.0-SNAPSHOT</version>
9
     <version>1.0-SNAPSHOT</version>
10
+    <dependencies>
11
+        <dependency>
12
+            <groupId>junit</groupId>
13
+            <artifactId>junit</artifactId>
14
+            <version>RELEASE</version>
15
+        </dependency>
16
+    </dependencies>
10
 
17
 
11
 
18
 
12
 </project>
19
 </project>

+ 28
- 0
src/main/java/com/zipcodewilmington/phonebook/Person.java View File

1
+package com.zipcodewilmington.phonebook;
2
+
3
+import java.util.HashMap;
4
+
5
+public class Person {
6
+
7
+    private String name;
8
+    private String phoneNumber;
9
+
10
+
11
+        public Person(String name, String phoneNumber) {
12
+
13
+            this.name = name;
14
+            this.phoneNumber = phoneNumber;
15
+        }
16
+
17
+        public String getName() {
18
+            return name;
19
+        }
20
+
21
+
22
+        public String getPhoneNumber() {
23
+            return phoneNumber;
24
+        }
25
+
26
+
27
+
28
+}

+ 34
- 0
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java View File

1
 package com.zipcodewilmington.phonebook;
1
 package com.zipcodewilmington.phonebook;
2
 
2
 
3
+import java.util.HashMap;
4
+import java.util.TreeMap;
5
+
3
 /**
6
 /**
4
  * Created by leon on 1/23/18.
7
  * Created by leon on 1/23/18.
5
  */
8
  */
9
+
10
+
6
 public class PhoneBook {
11
 public class PhoneBook {
12
+
13
+    TreeMap<String, String> contacts;
14
+
15
+    public PhoneBook () {
16
+        contacts = new TreeMap();
17
+    }
18
+
19
+    public String addPerson(String name, String phoneNumber) {
20
+        return contacts.put(name, phoneNumber);
21
+    }
22
+
23
+    public String lookupPhoneNumber(String name) {
24
+        return contacts.get(name);
25
+    }
26
+
27
+    public String removePerson(String name) {
28
+        return contacts.remove(name);
29
+    }
30
+
31
+    public void  listNamesAndNums(String name, String phoneNumber) {
32
+
33
+        for (String key : contacts.keySet()){
34
+            String value = contacts.get(key);
35
+            System.out.println(key + ": " + value);
36
+        }
37
+
38
+    }
39
+
40
+
7
 }
41
 }

+ 38
- 0
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java View File

1
 package com.zipcodewilmington.phonebook;
1
 package com.zipcodewilmington.phonebook;
2
 
2
 
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+
3
 /**
7
 /**
4
  * Created by leon on 1/23/18.
8
  * Created by leon on 1/23/18.
5
  */
9
  */
6
 public class PhoneBookTest {
10
 public class PhoneBookTest {
11
+
12
+    @Test
13
+    public void testConstructor() {
14
+        // Given
15
+        String expectedName = "";
16
+        String expectedPhoneNumber = "";
17
+
18
+        // When
19
+        Person person = new Person(expectedName, expectedPhoneNumber);
20
+
21
+        // Then
22
+        String actualName = person.getName();
23
+        String actualPhoneNumber = person.getPhoneNumber();
24
+
25
+        Assert.assertEquals(expectedName, actualName);
26
+        Assert.assertEquals(expectedPhoneNumber, actualPhoneNumber);
27
+    }
28
+
29
+    @Test
30
+    public void testConstructorWithNameAndPhonNumber() {
31
+        // Given
32
+        String expectedName = "Leon";
33
+        String expectedPhoneNumber = "123";
34
+
35
+        // When
36
+        Person person = new Person(expectedName, expectedPhoneNumber);
37
+
38
+        // Then
39
+        String actualPhoneNumber = person.getPhoneNumber();
40
+        String actualName = person.getName();
41
+
42
+        Assert.assertEquals(expectedPhoneNumber, actualPhoneNumber);
43
+        Assert.assertEquals(expectedName, actualName);
44
+    }
7
 }
45
 }