Browse Source

updated commit

Joshua Chung 6 years ago
parent
commit
751b95d5d1
3 changed files with 48 additions and 18 deletions
  1. 30
    6
      PhoneBook.java
  2. 1
    8
      PhoneBookTest.java
  3. 17
    4
      package.bluej

+ 30
- 6
PhoneBook.java View File

@@ -1,7 +1,31 @@
1
- 
1
+import java.util.*;
2
+import java.util.Map.Entry;
2 3
 
3
-/**
4
- * Created by leon on 1/23/18.
5
- */
6
-public class PhoneBook {
7
-}
4
+
5
+public class PhoneBook {    
6
+
7
+    Map<String, List<String>> phoneMap = new TreeMap<String, List<String>>();    
8
+    List<String> phoneNumbers = new ArrayList<String>();
9
+
10
+    public void add(String name, String phoneNumber){
11
+        phoneNumbers.add(phoneNumber);
12
+        phoneMap.put(name, phoneNumbers);
13
+    }
14
+
15
+    public void remove(String name){
16
+        phoneMap.remove(name);
17
+    }
18
+
19
+    public String lookup(String name){
20
+        return phoneNumbers.iterator(phoneMap.get(name));
21
+    }
22
+
23
+    public String reverseLookup(String phoneNumber){
24
+        for(Entry<String, String> entry : phoneMap.entrySet()){
25
+            if(entry.getValue().equals(phoneNumber)){
26
+                return entry.getKey();
27
+            }
28
+        }
29
+        return null;
30
+    }
31
+}

+ 1
- 8
PhoneBookTest.java View File

@@ -1,16 +1,9 @@
1
-
2
-
3 1
 import static org.junit.Assert.*;
4 2
 import org.junit.After;
5 3
 import org.junit.Before;
6 4
 import org.junit.Test;
7 5
 
8
-/**
9
- * The test class PhoneBookTest.
10
- *
11
- * @author  (your name)
12
- * @version (a version number or a date)
13
- */
6
+
14 7
 public class PhoneBookTest
15 8
 {
16 9
     /**

+ 17
- 4
package.bluej View File

@@ -9,12 +9,12 @@ 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=-239
13
+package.editor.y=-975
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=ClassTarget
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