Browse Source

TG finished

Tennessee Gibbs 6 years ago
parent
commit
3375fd88d9
4 changed files with 101 additions and 21 deletions
  1. 0
    7
      PhoneBook.java
  2. 56
    0
      PhoneBook1.java
  3. 19
    5
      PhoneBook1Test.java
  4. 26
    9
      package.bluej

+ 0
- 7
PhoneBook.java View File

@@ -1,7 +0,0 @@
1
- 
2
-
3
-/**
4
- * Created by leon on 1/23/18.
5
- */
6
-public class PhoneBook {
7
-}

+ 56
- 0
PhoneBook1.java View File

@@ -0,0 +1,56 @@
1
+                                     
2
+/**
3
+ * Write a description of class PhoneBook1 here.
4
+ *
5
+ * @author (your name)
6
+ * @version (a version number or a date)
7
+ */
8
+import java.util.TreeMap;
9
+import java.util.*;
10
+import java.util.Scanner;
11
+public class PhoneBook1
12
+{
13
+    // instance variables - replace the example below with your own
14
+    private String name, number;
15
+    
16
+    private Map<String, String> entries ;
17
+    
18
+
19
+    /**
20
+     * Constructor for objects of class PhoneBook1
21
+     */
22
+    public PhoneBook1(){        
23
+        this.entries = new TreeMap<String, String>();
24
+    }
25
+
26
+    /**
27
+     * An example of a method - replace this comment with your own
28
+     *
29
+     * @param  y  a sample parameter for a method
30
+     * @return    the sum of x and y
31
+     */
32
+    public void addNumber(String name, String number){
33
+        this.entries.put(name, number);
34
+        
35
+    }
36
+
37
+    public void remove(String name){
38
+        if (this.entries.containsKey(name))
39
+            System.out.println("found it");
40
+        this.entries.remove(name);
41
+    }
42
+
43
+    public void display(){
44
+        if (this.entries.isEmpty()) System.out.println("Empty");
45
+        for (Map.Entry<String, String> entry : entries.entrySet()) {
46
+        String value = entry.getValue();
47
+        String key = entry.getKey();
48
+        System.out.println(key + " " + value);
49
+        }
50
+        
51
+
52
+        
53
+
54
+    }
55
+}
56
+

PhoneBookTest.java → PhoneBook1Test.java View File

@@ -1,22 +1,21 @@
1 1
 
2
-
3 2
 import static org.junit.Assert.*;
4 3
 import org.junit.After;
5 4
 import org.junit.Before;
6 5
 import org.junit.Test;
7 6
 
8 7
 /**
9
- * The test class PhoneBookTest.
8
+ * The test class PhoneBook1Test.
10 9
  *
11 10
  * @author  (your name)
12 11
  * @version (a version number or a date)
13 12
  */
14
-public class PhoneBookTest
13
+public class PhoneBook1Test
15 14
 {
16 15
     /**
17
-     * Default constructor for test class PhoneBookTest
16
+     * Default constructor for test class PhoneBook1Test
18 17
      */
19
-    public PhoneBookTest()
18
+    public PhoneBook1Test()
20 19
     {
21 20
     }
22 21
 
@@ -39,4 +38,19 @@ public class PhoneBookTest
39 38
     public void tearDown()
40 39
     {
41 40
     }
41
+
42
+    @Test
43
+    public void Test1()
44
+    {
45
+        PhoneBook1 phoneBoo2 = new PhoneBook1();
46
+        phoneBoo2.addNumber("Zebra", "111-222-333");
47
+    }
48
+
49
+    @Test
50
+    public void Test2()
51
+    {
52
+        PhoneBook1 phoneBoo2 = new PhoneBook1();
53
+        phoneBoo2.addNumber("Zebra", "111-222-333");
54
+    }
42 55
 }
56
+

+ 26
- 9
package.bluej View File

@@ -1,20 +1,23 @@
1 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=PhoneBook1Test
3
+dependency1.to=PhoneBook1
4
+dependency1.type=UsesDependency
5
+editor.fx.0.height=722
6
+editor.fx.0.width=800
7
+editor.fx.0.x=320
8
+editor.fx.0.y=57
6 9
 objectbench.height=101
7 10
 objectbench.width=461
8 11
 package.divider.horizontal=0.6
9 12
 package.divider.vertical=0.8007380073800738
10 13
 package.editor.height=427
11 14
 package.editor.width=674
12
-package.editor.x=427
13
-package.editor.y=143
15
+package.editor.x=0
16
+package.editor.y=103
14 17
 package.frame.height=600
15 18
 package.frame.width=800
16
-package.numDependencies=0
17
-package.numTargets=1
19
+package.numDependencies=1
20
+package.numTargets=2
18 21
 package.showExtends=true
19 22
 package.showUses=true
20 23
 project.charset=UTF-8
@@ -23,4 +26,18 @@ readme.name=@README
23 26
 readme.width=47
24 27
 readme.x=10
25 28
 readme.y=10
26
-
29
+target1.height=50
30
+target1.name=PhoneBook1Test
31
+target1.showInterface=false
32
+target1.type=UnitTestTargetJunit4
33
+target1.width=100
34
+target1.x=100
35
+target1.y=40
36
+target2.association=PhoneBook1Test
37
+target2.height=50
38
+target2.name=PhoneBook1
39
+target2.showInterface=false
40
+target2.type=ClassTarget
41
+target2.width=100
42
+target2.x=70
43
+target2.y=70