Bladeren bron

committing Phone-book

chitraBegerhotta 6 jaren geleden
bovenliggende
commit
9eed2db49e
3 gewijzigde bestanden met toevoegingen van 91 en 9 verwijderingen
  1. 34
    1
      PhoneBook.java
  2. 34
    1
      PhoneBookTest.java
  3. 23
    7
      package.bluej

+ 34
- 1
PhoneBook.java Bestand weergeven

1
  
1
  
2
-
2
+import java.util.*;
3
 /**
3
 /**
4
  * Created by leon on 1/23/18.
4
  * Created by leon on 1/23/18.
5
  */
5
  */
6
 public class PhoneBook {
6
 public class PhoneBook {
7
+    //private String name;
8
+    //private String phoneNum;
9
+    TreeMap<String, String> phoneListByName = new TreeMap();
10
+    TreeMap<String, String> phoneListByNum = new TreeMap();
11
+    
12
+    public void add(String name, String phoneNumber){
13
+        phoneListByName.put(name, phoneNumber);
14
+        phoneListByNum.put(phoneNumber, name);
15
+        
16
+    }
17
+    public void remove(String name){
18
+        String phoneNumber = lookUp(name);
19
+        phoneListByName.remove(name);
20
+        phoneListByNum.remove(phoneNumber);
21
+    }
22
+    public String lookUp(String name){
23
+       return phoneListByName.get(name); 
24
+       
25
+    }
26
+    public String reverseLookUp(String phoneNumber){
27
+       return phoneListByNum.get(phoneNumber); 
28
+       
29
+    }
30
+    public void display(){
31
+        Set set = phoneListByName.entrySet();
32
+        //Set set2 = phoneListByNum.entrySet();
33
+        Iterator i = set.iterator();
34
+        
35
+        while(i.hasNext()){
36
+            Map.Entry name = (Map.Entry)i.next();
37
+            System.out.println(name.getKey() + ": " + name.getValue()) ;
38
+        }
39
+    }
7
 }
40
 }

+ 34
- 1
PhoneBookTest.java Bestand weergeven

13
  */
13
  */
14
 public class PhoneBookTest
14
 public class PhoneBookTest
15
 {
15
 {
16
+    
17
+    PhoneBook testObj;
16
     /**
18
     /**
17
      * Default constructor for test class PhoneBookTest
19
      * Default constructor for test class PhoneBookTest
18
      */
20
      */
28
     @Before
30
     @Before
29
     public void setUp()
31
     public void setUp()
30
     {
32
     {
33
+        testObj = new PhoneBook();
31
     }
34
     }
32
 
35
 
33
     /**
36
     /**
39
     public void tearDown()
42
     public void tearDown()
40
     {
43
     {
41
     }
44
     }
42
-}
45
+    @Test
46
+    public void testadd(){
47
+     String expected = "4545666667"; 
48
+     //PhoneBook phoneBook = new PhoneBook();
49
+     testObj.add("john",expected);
50
+     String actual = testObj.lookUp("john");
51
+     assertEquals(actual, expected);
52
+    }
53
+    @Test
54
+    public void testremoveAndLookUp(){
55
+    String expected = "5454";
56
+    testObj.add("gei", "5454");
57
+    assertEquals(expected,testObj.lookUp("gei"));
58
+    
59
+    String expectedAfterDelete = null;
60
+    testObj.remove("gei");
61
+    assertEquals(expectedAfterDelete, testObj.lookUp("gei"));
62
+      
63
+    }
64
+    @Test
65
+    public void testreverseLookUp(){
66
+    String expected = "John";
67
+    testObj.add("John", "4343");
68
+    assertEquals(expected, testObj.reverseLookUp("4343"));
69
+    
70
+    
71
+    
72
+    }
73
+     
74
+    }
75
+

+ 23
- 7
package.bluej Bestand weergeven

1
 #BlueJ package file
1
 #BlueJ package file
2
-editor.fx.0.height=0
3
-editor.fx.0.width=0
4
-editor.fx.0.x=0
5
-editor.fx.0.y=0
2
+dependency1.from=PhoneBookTest
3
+dependency1.to=PhoneBook
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=722
6
+editor.fx.0.width=800
7
+editor.fx.0.x=240
8
+editor.fx.0.y=25
6
 objectbench.height=101
9
 objectbench.height=101
7
 objectbench.width=461
10
 objectbench.width=461
8
 package.divider.horizontal=0.6
11
 package.divider.horizontal=0.6
13
 package.editor.y=143
16
 package.editor.y=143
14
 package.frame.height=600
17
 package.frame.height=600
15
 package.frame.width=800
18
 package.frame.width=800
16
-package.numDependencies=0
17
-package.numTargets=1
19
+package.numDependencies=1
20
+package.numTargets=2
18
 package.showExtends=true
21
 package.showExtends=true
19
 package.showUses=true
22
 package.showUses=true
20
 project.charset=UTF-8
23
 project.charset=UTF-8
23
 readme.width=47
26
 readme.width=47
24
 readme.x=10
27
 readme.x=10
25
 readme.y=10
28
 readme.y=10
26
-
29
+target1.height=50
30
+target1.name=PhoneBookTest
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=120
34
+target1.x=100
35
+target1.y=10
36
+target2.height=50
37
+target2.name=PhoneBook
38
+target2.showInterface=false
39
+target2.type=ClassTarget
40
+target2.width=100
41
+target2.x=70
42
+target2.y=70