Arin Turpin 6 年之前
父節點
當前提交
2f31c994a9
共有 3 個檔案被更改,包括 151 行新增46 行删除
  1. 86
    5
      PhoneBook.java
  2. 44
    33
      PhoneBookTest.java
  3. 21
    8
      package.bluej

+ 86
- 5
PhoneBook.java 查看文件

@@ -1,7 +1,88 @@
1
- 
2
-
1
+import java.util.*;
2
+import java.util.Scanner;
3 3
 /**
4
- * Created by leon on 1/23/18.
4
+ * Write a description of class PhoneBook here.
5
+ *
6
+ * @author (your name)
7
+ * @version (a version number or a date)
5 8
  */
6
-public class PhoneBook {
7
-}
9
+public class PhoneBook{
10
+    Map<List, String> phonebook = new HashMap<>();
11
+    List<String> multipleNumbers = new LinkedList<>();
12
+ //   public static boolean electronicPhonebook = true;
13
+ //   Scanner input = new Scanner(System.in);
14
+ //   Collection<String> c;
15
+ //   Iterator<String> iter = c.iterator();
16
+    public PhoneBook(){
17
+    }
18
+    public void add(List multipleNumbers, String name){
19
+        phonebook.put(multipleNumbers, name);
20
+    }
21
+    
22
+    public void remove(String name){
23
+        phonebook.remove(name);
24
+    }
25
+
26
+    public String lookup(String name){
27
+        return phonebook.get(name);
28
+    } 
29
+    
30
+    public String reverseLookup(List number){
31
+        return phonebook.get(number);
32
+    }
33
+    
34
+    public void display(){
35
+        System.out.println("                         ***** WLECOME TO THE WORLD BOOK *****           ");
36
+        for (Map.Entry<List,String> entry : phonebook.entrySet()){
37
+            System.out.println("Όνομα: \n" + entry.getValue() + "\n" +
38
+            "Αριθμός τηλεφώνου:" + "\n" + entry.getKey() + "\n");
39
+        }
40
+    }
41
+    
42
+    
43
+    
44
+    
45
+    
46
+    
47
+    
48
+    
49
+    
50
+    
51
+    
52
+    
53
+    
54
+    
55
+    
56
+    
57
+    
58
+    
59
+    
60
+    //  public void addMultiple(){
61
+  //
62
+     //   while(electronicPhonebook = true){
63
+    //        System.out.println("Enter a number and then a name. ");
64
+   //         String number = input.nextLine();
65
+    //        String name = input.nextLine();
66
+    //        phonebook.put(number, name);
67
+    //        
68
+    //        System.out.println("Are you done adding entries¿");
69
+    //        String exit = input.nextLine();
70
+    //            if (exit.equalsIgnoreCase("yes") || exit.equalsIgnoreCase("yeah") || exit.equalsIgnoreCase("Affirmative")){
71
+   //                 electronicPhonebook = false;
72
+     //           } else
73
+    //            if (exit.equalsIgnoreCase("no") || exit.equalsIgnoreCase("nope") || exit.equalsIgnoreCase("nah")){
74
+    //                System.out.println("Okay...");
75
+    //            } else {System.out.println("I guess not...");
76
+   //             }
77
+     //   }
78
+   // }
79
+    
80
+    
81
+ //   public static void commandCenter(){
82
+ //       PhoneBook runningbook = new PhoneBook();
83
+ //       while(electronicPhonebook = true){
84
+ //           runningbook.addMultiple();
85
+ //       }
86
+ //       
87
+ //   }
88
+    }

+ 44
- 33
PhoneBookTest.java 查看文件

@@ -1,42 +1,53 @@
1
-
1
+import java.util.*;
2 2
 
3 3
 import static org.junit.Assert.*;
4 4
 import org.junit.After;
5 5
 import org.junit.Before;
6 6
 import org.junit.Test;
7
-
8
-/**
9
- * The test class PhoneBookTest.
10
- *
11
- * @author  (your name)
12
- * @version (a version number or a date)
13
- */
14
-public class PhoneBookTest
15
-{
16
-    /**
17
-     * Default constructor for test class PhoneBookTest
18
-     */
19
-    public PhoneBookTest()
20
-    {
7
+public class PhoneBookTest{
8
+    Map<String, String> testPhonebook = new TreeMap<>();
9
+    public PhoneBookTest(){
21 10
     }
22
-
23
-    /**
24
-     * Sets up the test fixture.
25
-     *
26
-     * Called before every test case method.
27
-     */
28
-    @Before
29
-    public void setUp()
30
-    {
11
+    
12
+    @Test
13
+    public void addTest(){
14
+        String number = "302-559-6954";
15
+        String name = "Ken";
16
+        
17
+        testPhonebook.put(number, name);
18
+        String expected = testPhonebook.get(number);
19
+        assertEquals(name, expected);
31 20
     }
32
-
33
-    /**
34
-     * Tears down the test fixture.
35
-     *
36
-     * Called after every test case method.
37
-     */
38
-    @After
39
-    public void tearDown()
40
-    {
21
+    
22
+    @Test
23
+    public void removeTest(){
24
+        testPhonebook.put("9393939", "Hirself");
25
+        testPhonebook.remove("9393939");
26
+        
27
+        String actual = testPhonebook.get("9393939");
28
+        String expected = null;
29
+        assertEquals(actual, expected);
41 30
     }
31
+    
32
+    @Test
33
+    public void lookupTest(){
34
+        testPhonebook.put("9393939", "Hirself");
35
+        testPhonebook.get("9393939");
36
+        
37
+        String actual = testPhonebook.get("9393939");
38
+        String expected = "Hirself";
39
+        assertEquals(actual, expected);
40
+    }
41
+    
42
+    @Test
43
+    public void reverseLookupTest(){
44
+        testPhonebook.put("9393939", "Hirself");
45
+        testPhonebook.get("9393939");
46
+        
47
+        String actual = testPhonebook.get("Hirself");
48
+        String expected = "9393939";
49
+        assertEquals(actual, expected);
50
+    }
51
+    
52
+
42 53
 }

+ 21
- 8
package.bluej 查看文件

@@ -1,20 +1,20 @@
1 1
 #BlueJ package file
2
-editor.fx.0.height=0
3
-editor.fx.0.width=0
2
+editor.fx.0.height=699
3
+editor.fx.0.width=699
4 4
 editor.fx.0.x=0
5
-editor.fx.0.y=0
5
+editor.fx.0.y=22
6 6
 objectbench.height=101
7
-objectbench.width=461
7
+objectbench.width=776
8 8
 package.divider.horizontal=0.6
9 9
 package.divider.vertical=0.8007380073800738
10 10
 package.editor.height=427
11 11
 package.editor.width=674
12
-package.editor.x=427
13
-package.editor.y=143
12
+package.editor.x=0
13
+package.editor.y=117
14 14
 package.frame.height=600
15 15
 package.frame.width=800
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=120
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