Browse Source

PhoneBookLab

Roy 6 years ago
parent
commit
e641ce96c7
8 changed files with 404 additions and 28 deletions
  1. 9
    0
      .idea/ZCW-PhoneBook.iml
  2. 6
    0
      .idea/misc.xml
  3. 8
    0
      .idea/modules.xml
  4. 6
    0
      .idea/vcs.xml
  5. 223
    0
      .idea/workspace.xml
  6. 62
    0
      PhoneBook.java
  7. 71
    22
      PhoneBookTest.java
  8. 19
    6
      package.bluej

+ 9
- 0
.idea/ZCW-PhoneBook.iml View File

@@ -0,0 +1,9 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<module type="JAVA_MODULE" version="4">
3
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+    <exclude-output />
5
+    <content url="file://$MODULE_DIR$" />
6
+    <orderEntry type="inheritedJdk" />
7
+    <orderEntry type="sourceFolder" forTests="false" />
8
+  </component>
9
+</module>

+ 6
- 0
.idea/misc.xml View File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="JavaScriptSettings">
4
+    <option name="languageLevel" value="ES6" />
5
+  </component>
6
+</project>

+ 8
- 0
.idea/modules.xml View File

@@ -0,0 +1,8 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ProjectModuleManager">
4
+    <modules>
5
+      <module fileurl="file://$PROJECT_DIR$/.idea/ZCW-PhoneBook.iml" filepath="$PROJECT_DIR$/.idea/ZCW-PhoneBook.iml" />
6
+    </modules>
7
+  </component>
8
+</project>

+ 6
- 0
.idea/vcs.xml View File

@@ -0,0 +1,6 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="VcsDirectoryMappings">
4
+    <mapping directory="" vcs="Git" />
5
+  </component>
6
+</project>

+ 223
- 0
.idea/workspace.xml View File

@@ -0,0 +1,223 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="ChangeListManager">
4
+    <list default="true" id="cdde17a4-24c8-4cb3-95c5-3b9fbe37338f" name="Default" comment="">
5
+      <change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
6
+      <change beforePath="$PROJECT_DIR$/PhoneBook.java" beforeDir="false" afterPath="$PROJECT_DIR$/PhoneBook.java" afterDir="false" />
7
+      <change beforePath="$PROJECT_DIR$/package.bluej" beforeDir="false" afterPath="$PROJECT_DIR$/package.bluej" afterDir="false" />
8
+    </list>
9
+    <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
10
+    <option name="TRACKING_ENABLED" value="true" />
11
+    <option name="SHOW_DIALOG" value="false" />
12
+    <option name="HIGHLIGHT_CONFLICTS" value="true" />
13
+    <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
14
+    <option name="LAST_RESOLUTION" value="IGNORE" />
15
+  </component>
16
+  <component name="FileEditorManager">
17
+    <leaf>
18
+      <file leaf-file-name="PhoneBook.java" pinned="false" current-in-tab="true">
19
+        <entry file="file://$PROJECT_DIR$/PhoneBook.java">
20
+          <provider selected="true" editor-type-id="text-editor">
21
+            <state relative-caret-position="120">
22
+              <caret line="8" column="4" lean-forward="true" selection-start-line="8" selection-start-column="4" selection-end-line="8" selection-end-column="4" />
23
+            </state>
24
+          </provider>
25
+        </entry>
26
+      </file>
27
+      <file leaf-file-name="PhoneBookTest.java" pinned="false" current-in-tab="false">
28
+        <entry file="file://$PROJECT_DIR$/PhoneBookTest.java">
29
+          <provider selected="true" editor-type-id="text-editor" />
30
+        </entry>
31
+      </file>
32
+    </leaf>
33
+  </component>
34
+  <component name="Git.Settings">
35
+    <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
36
+  </component>
37
+  <component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
38
+  <component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
39
+  <component name="JsGulpfileManager">
40
+    <detection-done>true</detection-done>
41
+    <sorting>DEFINITION_ORDER</sorting>
42
+  </component>
43
+  <component name="NodePackageJsonFileManager">
44
+    <packageJsonPaths />
45
+  </component>
46
+  <component name="ProjectFrameBounds" extendedState="6">
47
+    <option name="x" value="10" />
48
+    <option name="y" value="43" />
49
+    <option name="width" value="1260" />
50
+    <option name="height" value="688" />
51
+  </component>
52
+  <component name="ProjectView">
53
+    <navigator proportions="" version="1">
54
+      <foldersAlwaysOnTop value="true" />
55
+    </navigator>
56
+    <panes>
57
+      <pane id="Scope" />
58
+      <pane id="ProjectPane">
59
+        <subPane>
60
+          <expand>
61
+            <path>
62
+              <item name="ZCW-PhoneBook" type="b2602c69:ProjectViewProjectNode" />
63
+              <item name="ZCW-PhoneBook" type="462c0819:PsiDirectoryNode" />
64
+            </path>
65
+          </expand>
66
+          <select />
67
+        </subPane>
68
+      </pane>
69
+      <pane id="AndroidView" />
70
+      <pane id="PackagesPane" />
71
+    </panes>
72
+  </component>
73
+  <component name="PropertiesComponent">
74
+    <property name="WebServerToolWindowFactoryState" value="false" />
75
+    <property name="aspect.path.notification.shown" value="true" />
76
+    <property name="last_opened_file_path" value="$PROJECT_DIR$" />
77
+    <property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
78
+    <property name="nodejs_npm_path_reset_for_default_project" value="true" />
79
+  </component>
80
+  <component name="RecentsManager">
81
+    <key name="MoveFile.RECENT_KEYS">
82
+      <recent name="$PROJECT_DIR$/Test/java/io.zipcoder" />
83
+    </key>
84
+  </component>
85
+  <component name="RunDashboard">
86
+    <option name="ruleStates">
87
+      <list>
88
+        <RuleState>
89
+          <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
90
+        </RuleState>
91
+        <RuleState>
92
+          <option name="name" value="StatusDashboardGroupingRule" />
93
+        </RuleState>
94
+      </list>
95
+    </option>
96
+  </component>
97
+  <component name="RunManager">
98
+    <configuration default="true" type="Application" factoryName="Application">
99
+      <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
100
+    </configuration>
101
+    <configuration default="true" type="JUnit" factoryName="JUnit">
102
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
103
+      <option name="ALTERNATIVE_JRE_PATH" />
104
+      <option name="PACKAGE_NAME" />
105
+      <option name="MAIN_CLASS_NAME" />
106
+      <option name="METHOD_NAME" />
107
+      <option name="TEST_OBJECT" value="class" />
108
+      <option name="VM_PARAMETERS" value="-ea" />
109
+      <option name="PARAMETERS" />
110
+      <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
111
+      <option name="PASS_PARENT_ENVS" value="true" />
112
+      <option name="TEST_SEARCH_SCOPE">
113
+        <value defaultName="singleModule" />
114
+      </option>
115
+      <patterns />
116
+    </configuration>
117
+    <configuration default="true" type="TestNG" factoryName="TestNG">
118
+      <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
119
+      <option name="ALTERNATIVE_JRE_PATH" />
120
+      <option name="SUITE_NAME" />
121
+      <option name="PACKAGE_NAME" />
122
+      <option name="MAIN_CLASS_NAME" />
123
+      <option name="METHOD_NAME" />
124
+      <option name="GROUP_NAME" />
125
+      <option name="TEST_OBJECT" value="CLASS" />
126
+      <option name="VM_PARAMETERS" value="-ea" />
127
+      <option name="PARAMETERS" />
128
+      <option name="WORKING_DIRECTORY" value="%MODULE_WORKING_DIR%" />
129
+      <option name="OUTPUT_DIRECTORY" />
130
+      <option name="PASS_PARENT_ENVS" value="true" />
131
+      <option name="TEST_SEARCH_SCOPE">
132
+        <value defaultName="singleModule" />
133
+      </option>
134
+      <option name="USE_DEFAULT_REPORTERS" value="false" />
135
+      <option name="PROPERTIES_FILE" />
136
+      <properties />
137
+      <listeners />
138
+    </configuration>
139
+  </component>
140
+  <component name="SvnConfiguration">
141
+    <configuration />
142
+  </component>
143
+  <component name="TaskManager">
144
+    <task active="true" id="Default" summary="Default task">
145
+      <changelist id="cdde17a4-24c8-4cb3-95c5-3b9fbe37338f" name="Default" comment="" />
146
+      <created>1529949194188</created>
147
+      <option name="number" value="Default" />
148
+      <option name="presentableId" value="Default" />
149
+      <updated>1529949194188</updated>
150
+      <workItem from="1529949195752" duration="806000" />
151
+    </task>
152
+    <servers />
153
+  </component>
154
+  <component name="TimeTrackingManager">
155
+    <option name="totallyTimeSpent" value="806000" />
156
+  </component>
157
+  <component name="ToolWindowManager">
158
+    <frame x="0" y="23" width="1280" height="717" extended-state="6" />
159
+    <layout>
160
+      <window_info anchor="right" id="Palette" />
161
+      <window_info anchor="bottom" id="TODO" order="6" />
162
+      <window_info anchor="right" id="Palette&#9;" />
163
+      <window_info id="Image Layers" />
164
+      <window_info anchor="right" id="Capture Analysis" />
165
+      <window_info anchor="bottom" id="Event Log" side_tool="true" />
166
+      <window_info anchor="right" id="Maven Projects" />
167
+      <window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
168
+      <window_info anchor="bottom" id="Version Control" />
169
+      <window_info anchor="bottom" id="Run" order="2" />
170
+      <window_info anchor="bottom" id="Terminal" />
171
+      <window_info id="Capture Tool" />
172
+      <window_info id="Designer" />
173
+      <window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
174
+      <window_info anchor="right" id="Database" />
175
+      <window_info id="Structure" order="1" side_tool="true" weight="0.25" />
176
+      <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
177
+      <window_info id="UI Designer" />
178
+      <window_info anchor="right" id="Theme Preview" />
179
+      <window_info id="Favorites" side_tool="true" />
180
+      <window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
181
+      <window_info anchor="bottom" id="Find" order="1" />
182
+      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
183
+      <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
184
+      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
185
+      <window_info anchor="bottom" id="Message" order="0" />
186
+      <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
187
+    </layout>
188
+  </component>
189
+  <component name="TypeScriptGeneratedFilesManager">
190
+    <option name="version" value="1" />
191
+  </component>
192
+  <component name="VcsContentAnnotationSettings">
193
+    <option name="myLimit" value="2678400000" />
194
+  </component>
195
+  <component name="editorHistoryManager">
196
+    <entry file="file://$PROJECT_DIR$/PhoneBookTest.java">
197
+      <provider selected="true" editor-type-id="text-editor" />
198
+    </entry>
199
+    <entry file="file://$PROJECT_DIR$/PhoneBook.java">
200
+      <provider selected="true" editor-type-id="text-editor">
201
+        <state relative-caret-position="120">
202
+          <caret line="8" column="4" lean-forward="true" selection-start-line="8" selection-start-column="4" selection-end-line="8" selection-end-column="4" />
203
+        </state>
204
+      </provider>
205
+    </entry>
206
+  </component>
207
+  <component name="masterDetails">
208
+    <states>
209
+      <state key="ProjectJDKs.UI">
210
+        <settings>
211
+          <last-edited>1.8</last-edited>
212
+          <splitter-proportions>
213
+            <option name="proportions">
214
+              <list>
215
+                <option value="0.2" />
216
+              </list>
217
+            </option>
218
+          </splitter-proportions>
219
+        </settings>
220
+      </state>
221
+    </states>
222
+  </component>
223
+</project>

+ 62
- 0
PhoneBook.java View File

@@ -3,5 +3,67 @@
3 3
 /**
4 4
  * Created by leon on 1/23/18.
5 5
  */
6
+import java.util.*;
7
+import java.lang.*;
6 8
 public class PhoneBook {
9
+    Map<String, ArrayList<String>> phoneBook = new TreeMap<String, ArrayList<String>>();
10
+    
11
+    
12
+    public PhoneBook(){
13
+        
14
+    }
15
+    
16
+    public ArrayList<String> add(String name, String phoneNumber){
17
+        ArrayList<String> numbers = new ArrayList<>();
18
+        
19
+        if(phoneBook.containsKey(name)) numbers = phoneBook.get(name);
20
+        
21
+        numbers.add(phoneNumber);
22
+        add(name, numbers);
23
+        return phoneBook.get(name);
24
+       // phoneBook.put(name, phoneNumber);
25
+    }
26
+    
27
+    public ArrayList<String> add(String name, ArrayList<String> phoneNumbers){
28
+        phoneBook.put(name, phoneNumbers);
29
+        return phoneBook.get(name);
30
+    }
31
+    
32
+    public ArrayList<String> remove(String name){
33
+        phoneBook.remove(name);
34
+        return phoneBook.get(name);
35
+    }
36
+    
37
+    public ArrayList<String> lookUp(String name){
38
+        ArrayList<String> number = new ArrayList<>();
39
+        for(Map.Entry<String, ArrayList<String>> book: phoneBook.entrySet()){
40
+            if(book.getKey().equals(name)){
41
+                number = book.getValue();
42
+            }
43
+        }
44
+        return number;
45
+    }
46
+    
47
+    public String reverseLookUp(ArrayList<String> phoneNumber){
48
+        String name = null;
49
+        for(Map.Entry<String, ArrayList<String>> book: phoneBook.entrySet()){
50
+            if(book.getValue().equals(phoneNumber)){
51
+                name = book.getKey();
52
+            }
53
+        }
54
+        return name;
55
+    }
56
+    
57
+    public void display(){
58
+        for(Map.Entry<String, ArrayList<String>> book: phoneBook.entrySet()){
59
+            System.out.println(book.getKey());
60
+            for(String num: book.getValue()){ 
61
+                System.out.println("- "+ num);
62
+            }
63
+        }
64
+    }
65
+    
66
+    public int size(){
67
+        return phoneBook.size();
68
+    }
7 69
 }

+ 71
- 22
PhoneBookTest.java View File

@@ -1,9 +1,9 @@
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;
6
+import java.util.*;
7 7
 
8 8
 /**
9 9
  * The test class PhoneBookTest.
@@ -13,30 +13,79 @@ import org.junit.Test;
13 13
  */
14 14
 public class PhoneBookTest
15 15
 {
16
-    /**
17
-     * Default constructor for test class PhoneBookTest
18
-     */
19
-    public PhoneBookTest()
20
-    {
21
-    }
22
-
23
-    /**
24
-     * Sets up the test fixture.
25
-     *
26
-     * Called before every test case method.
27
-     */
16
+    PhoneBook phoneBook;
17
+    
28 18
     @Before
29 19
     public void setUp()
30 20
     {
21
+        phoneBook = new PhoneBook();
31 22
     }
32
-
33
-    /**
34
-     * Tears down the test fixture.
35
-     *
36
-     * Called after every test case method.
37
-     */
38
-    @After
39
-    public void tearDown()
40
-    {
23
+    
24
+    @Test
25
+    public void addTest(){
26
+        phoneBook.add("Zebra", "111-222-333");
27
+        phoneBook.add("Dog", "222-444-4444");
28
+        int expected = 2;
29
+        int actual = phoneBook.size();
30
+        assertEquals(expected, actual);
31
+    }
32
+    
33
+    @Test
34
+    public void addToMapTest(){
35
+        ArrayList<String> numbers = new ArrayList<>();
36
+        numbers.add("111-222-333");
37
+        numbers.add("222-444-4444");
38
+        phoneBook.add("Zebra", numbers);
39
+        //phoneBook.add("Dog", "222-444-4444");
40
+        int expected = 1;
41
+        int actual = phoneBook.size();
42
+        assertEquals(expected, actual);
43
+    }
44
+    
45
+    @Test
46
+    public void removeTest(){
47
+        ArrayList<String> numbers1 = new ArrayList<>();
48
+        ArrayList<String> numbers2 = new ArrayList<>();
49
+        numbers1.add("111-222-333");
50
+        numbers1.add("222-444-4444");
51
+        numbers2.add("444-222-332");
52
+        numbers2.add("555-444-6666");
53
+        phoneBook.add("Roy", numbers1);
54
+        phoneBook.add("Josh", numbers2);
55
+        int expected = 1;
56
+        phoneBook.remove("Josh");
57
+        int actual = phoneBook.size();
58
+        assertEquals(expected, actual);
59
+    }
60
+    
61
+    @Test
62
+    public void lookUpTest(){
63
+        ArrayList<String> numbers1 = new ArrayList<>();
64
+        ArrayList<String> numbers2 = new ArrayList<>();
65
+        numbers1.add("111-222-333");
66
+        numbers1.add("222-444-4444");
67
+        numbers2.add("444-222-332");
68
+        numbers2.add("555-444-6666");
69
+        phoneBook.add("Roy", numbers1);
70
+        phoneBook.add("Josh", numbers2);
71
+        
72
+        ArrayList<String> expected = numbers1;
73
+        ArrayList<String> actual = phoneBook.lookUp("Roy");
74
+        assertEquals(expected, actual);
75
+    }
76
+    @Test
77
+    public void reverseLookUpTest(){
78
+        ArrayList<String> numbers1 = new ArrayList<>();
79
+        ArrayList<String> numbers2 = new ArrayList<>();
80
+        numbers1.add("111-222-333");
81
+        numbers1.add("222-444-4444");
82
+        numbers2.add("444-222-332");
83
+        numbers2.add("555-444-6666");
84
+        phoneBook.add("Roy", numbers1);
85
+        phoneBook.add("Josh", numbers2);
86
+        
87
+        String expected = "Roy";
88
+        String actual = phoneBook.reverseLookUp(numbers1);
89
+        assertEquals(expected, actual);
41 90
     }
42 91
 }

+ 19
- 6
package.bluej View File

@@ -1,8 +1,8 @@
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
+editor.fx.0.height=722
3
+editor.fx.0.width=800
4
+editor.fx.0.x=240
5
+editor.fx.0.y=27
6 6
 objectbench.height=101
7 7
 objectbench.width=461
8 8
 package.divider.horizontal=0.6
@@ -14,7 +14,7 @@ package.editor.y=143
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