Kaynağa Gözat

first pass w/o test cases

Daniel Horowitz 6 yıl önce
ebeveyn
işleme
91ce14f789

+ 11
- 0
pom.xml Dosyayı Görüntüle

@@ -8,5 +8,16 @@
8 8
     <artifactId>phonebok</artifactId>
9 9
     <version>1.0-SNAPSHOT</version>
10 10
 
11
+    <dependencies>
12
+    <!-- https://mvnrepository.com/artifact/junit/junit -->
13
+    <dependency>
14
+        <groupId>junit</groupId>
15
+        <artifactId>junit</artifactId>
16
+        <version>4.12</version>
17
+        <scope>test</scope>
18
+    </dependency>
19
+
20
+    </dependencies>
21
+
11 22
 
12 23
 </project>

+ 74
- 0
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java Dosyayı Görüntüle

@@ -1,7 +1,81 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
+import java.util.Set;
4
+import java.util.TreeMap;
5
+import java.util.TreeSet;
6
+
3 7
 /**
4 8
  * Created by leon on 1/23/18.
5 9
  */
6 10
 public class PhoneBook {
11
+
12
+    private String name;
13
+    private String number;
14
+
15
+    TreeMap<String, String> myTree = new TreeMap<String, String>();
16
+
17
+
18
+    public PhoneBook(){
19
+
20
+    }
21
+
22
+//    public PhoneBook(String name, String number) {
23
+//        this.name = name;
24
+//        this.number = number;
25
+//
26
+//    }
27
+
28
+    public void addEntry(String name, String number) {
29
+        myTree.put(name, number);
30
+
31
+
32
+    }
33
+
34
+
35
+    public void remove(String name, String number) {
36
+        myTree.remove(name);
37
+
38
+    }
39
+
40
+    public String stringlookup(String name) {
41
+
42
+       return myTree.get(name);
43
+
44
+
45
+
46
+    }
47
+
48
+    public String listNames() {
49
+        ;
50
+        Set<String> contacts = myTree.keySet();
51
+
52
+        String allNames = "";
53
+        for (String contact : contacts) {
54
+            allNames += contact + "\n";
55
+
56
+        }
57
+        return allNames;
58
+    }
59
+
60
+    public String[] listPhoneBook() {
61
+
62
+        return null;
63
+    }
64
+
65
+
66
+    public static void main(String[] args) {
67
+
68
+        PhoneBook phonebookEntry = new PhoneBook();
69
+
70
+        phonebookEntry.addEntry("Brian", "3027619121");
71
+        phonebookEntry.addEntry("Dan", "4846394190");
72
+        phonebookEntry.addEntry("Garret", "3027894586");
73
+
74
+        System.out.println(phonebookEntry.listNames());
75
+
76
+        phonebookEntry.stringlookup("Brian");
77
+
78
+        System.out.println(phonebookEntry.stringlookup("Dan"));
79
+    }
80
+
7 81
 }

+ 29
- 0
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java Dosyayı Görüntüle

@@ -1,7 +1,36 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
+import org.junit.Assert;
4
+import org.junit.Before;
5
+import org.junit.Test;
6
+import org.junit.experimental.theories.suppliers.TestedOn;
7
+
8
+
3 9
 /**
4 10
  * Created by leon on 1/23/18.
5 11
  */
6 12
 public class PhoneBookTest {
13
+
14
+    @Before
15
+    public void setUp() {
16
+        testBook = new PhoneBook();
17
+    }
18
+
19
+
20
+
21
+
22
+    @Test
23
+    public void addTest() {
24
+
25
+        PhoneBook testBook = new PhoneBook();
26
+        String name = "Dan";
27
+        String number = "4847986543";
28
+       // String expected = "Dan 4847986543";
29
+
30
+        testBook.add(name, number);
31
+        Assert.assertEquals(expected, actual);
32
+    }
33
+
34
+
35
+
7 36
 }