Lewis Dominguez 6 år sedan
förälder
incheckning
7b573a7156
3 ändrade filer med 117 tillägg och 12 borttagningar
  1. 39
    0
      PhoneBook.java
  2. 54
    1
      PhoneBookTest.java
  3. 24
    11
      package.bluej

+ 39
- 0
PhoneBook.java Visa fil

@@ -3,5 +3,44 @@
3 3
 /**
4 4
  * Created by leon on 1/23/18.
5 5
  */
6
+import java.util. *;
6 7
 public class PhoneBook {
8
+    
9
+    TreeMap<String, String> phoneBook = new TreeMap<String, String>();
10
+    
11
+    public String add(String name, String number) {
12
+        phoneBook.put(name, number);
13
+        return name + " " + number;
14
+    }
15
+    
16
+    public String remove(String name) {
17
+        phoneBook.remove(name);
18
+        return name;
19
+        
20
+    }
21
+    
22
+    public String lookup(String name) {
23
+        return phoneBook.get(name);
24
+        
25
+        
26
+    }
27
+    
28
+    public String reverseLookup(String number) {
29
+        for(Map.Entry<String, String> entry : phoneBook.entrySet()) {
30
+            String value = entry.getValue();
31
+            if(value.equals(number)) {
32
+                return entry.getKey();
33
+            }
34
+        }
35
+        return "";
36
+    }
37
+    
38
+    public void display() {
39
+        for(Map.Entry<String, String> entry : phoneBook.entrySet()) {
40
+            String value = entry.getValue();
41
+            System.out.println(entry.getKey() + " -> " + entry.getValue());
42
+        }
43
+    }
44
+    
45
+    
7 46
 }

+ 54
- 1
PhoneBookTest.java Visa fil

@@ -1,5 +1,4 @@
1 1
 
2
-
3 2
 import static org.junit.Assert.*;
4 3
 import org.junit.After;
5 4
 import org.junit.Before;
@@ -29,6 +28,60 @@ public class PhoneBookTest
29 28
     public void setUp()
30 29
     {
31 30
     }
31
+    PhoneBook phonebook = new PhoneBook();
32
+    @Test
33
+    public void addTest() {
34
+        //Expected
35
+        String expected = "Lewis Dominguez 3023005754";
36
+        //Actual
37
+        String actual = phonebook.add("Lewis Dominguez", "3023005754");
38
+        
39
+        assertEquals(expected, actual);
40
+    }
41
+    
42
+    @Test
43
+    public void removeTest() {
44
+        phonebook.add("Lewis Dominguez", "3023005754");
45
+        //Expected
46
+        String expected = "Lewis Dominguez";
47
+        //Actual
48
+        String actual = phonebook.remove("Lewis Dominguez");
49
+        
50
+        assertEquals(expected, actual);
51
+    }
52
+    
53
+    @Test
54
+    public void lookupTest() {
55
+        phonebook.add("Lewis Dominguez", "3023005754");
56
+        //Expected
57
+        String expected = "3023005754";
58
+        //Actual
59
+        String actual = phonebook.lookup("Lewis Dominguez");
60
+        
61
+        assertEquals(expected, actual);
62
+    }
63
+    
64
+    @Test
65
+    public void reverseLookupTest() {
66
+        phonebook.add("Lewis Dominguez", "3023005754");
67
+        //Expected
68
+        String expected = "Lewis Dominguez";
69
+        //Actual
70
+        String actual = phonebook.reverseLookup("3023005754");
71
+        
72
+        assertEquals(expected, actual);
73
+    }
74
+    
75
+    // @Test
76
+    // public void displayTest() {
77
+        // phonebook.add("Lewis Dominguez", "3023005754");
78
+        // //Expected
79
+        // String expected = "Lewis Dominguez -> 3023005753";
80
+        // //Actual
81
+        // String actual = phonebook.display("Lewis Dominguez 3023005754");
82
+        
83
+        // assertEquals(expected, actual);
84
+    // }
32 85
 
33 86
     /**
34 87
      * Tears down the test fixture.

+ 24
- 11
package.bluej Visa fil

@@ -3,18 +3,18 @@ editor.fx.0.height=0
3 3
 editor.fx.0.width=0
4 4
 editor.fx.0.x=0
5 5
 editor.fx.0.y=0
6
-objectbench.height=101
7
-objectbench.width=461
6
+objectbench.height=100
7
+objectbench.width=597
8 8
 package.divider.horizontal=0.6
9
-package.divider.vertical=0.8007380073800738
10
-package.editor.height=427
11
-package.editor.width=674
12
-package.editor.x=427
13
-package.editor.y=143
14
-package.frame.height=600
15
-package.frame.width=800
9
+package.divider.vertical=0.834108527131783
10
+package.editor.height=531
11
+package.editor.width=495
12
+package.editor.x=288
13
+package.editor.y=38
14
+package.frame.height=703
15
+package.frame.width=621
16 16
 package.numDependencies=0
17
-package.numTargets=1
17
+package.numTargets=2
18 18
 package.showExtends=true
19 19
 package.showUses=true
20 20
 project.charset=UTF-8
@@ -23,4 +23,17 @@ readme.name=@README
23 23
 readme.width=47
24 24
 readme.x=10
25 25
 readme.y=10
26
-
26
+target1.height=50
27
+target1.name=PhoneBookTest
28
+target1.showInterface=false
29
+target1.type=UnitTestTargetJunit4
30
+target1.width=130
31
+target1.x=100
32
+target1.y=10
33
+target2.height=50
34
+target2.name=PhoneBook
35
+target2.showInterface=false
36
+target2.type=ClassTarget
37
+target2.width=100
38
+target2.x=70
39
+target2.y=70