Kris Blassingame 6 years ago
parent
commit
e9b939151a
3 changed files with 348 additions and 32 deletions
  1. 261
    0
      .idea/workspace.xml
  2. 51
    1
      PhoneBook.java
  3. 36
    31
      PhoneBookTest.java

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

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

+ 51
- 1
PhoneBook.java View File

@@ -1,7 +1,57 @@
1
- 
1
+import java.util.TreeMap;
2
+import java.util.Map;
3
+import java.util.ArrayList;
4
+import java.util.Map.Entry;
2 5
 
3 6
 /**
4 7
  * Created by leon on 1/23/18.
5 8
  */
6 9
 public class PhoneBook {
10
+    Map<String, ArrayList> phoneBook = new TreeMap<String, ArrayList>();
11
+
12
+    public String add(String name, String phoneNumber){
13
+        ArrayList<String> numbers = new ArrayList<String>();
14
+        numbers.add(phoneNumber);
15
+        phoneBook.put(name, numbers);
16
+        return name + " has been added.";
17
+    }
18
+
19
+    public int getSize(){
20
+        return phoneBook.size();
21
+    }
22
+
23
+    public boolean keyExists(String name){
24
+        return phoneBook.containsKey(name);
25
+    }
26
+
27
+    public String remove(String name){
28
+        phoneBook.remove(name);
29
+        return name + " has been deleted.";
30
+    }
31
+
32
+    public String lookup(String name){
33
+        return String.join(", ", phoneBook.get(name));
34
+    }
35
+
36
+    public String reverseLookup(String phoneNumber){
37
+        for(Map.Entry<String,ArrayList> entry : phoneBook.entrySet()) {
38
+            String key = entry.getKey();
39
+            ArrayList value = entry.getValue();
40
+            if (value.equals(phoneNumber)) {
41
+
42
+            }
43
+            return entry.getKey();
44
+        }
45
+        return "";
46
+
47
+    }
48
+
49
+    public void display(){
50
+        for(Map.Entry<String, ArrayList> entry : phoneBook.entrySet()) {
51
+            String key = entry.getKey();
52
+            ArrayList value = entry.getValue();
53
+            System.out.println(key + " => " + value);
54
+        }
55
+
56
+    }
7 57
 }

+ 36
- 31
PhoneBookTest.java View File

@@ -1,42 +1,47 @@
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;
5
+import java.util.TreeMap;
6
+import java.util.Map;
7
+import java.util.ArrayList;
8
+
9
+public class PhoneBookTest {
10
+    PhoneBook pb = new PhoneBook();
11
+    ArrayList<String> numbers = new ArrayList<String>();
12
+    @Test
13
+    public void addTest(){
14
+
15
+        String entry = pb.add("Kris", "666-666-6666");
16
+        int actual = pb.getSize();
7 17
 
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
-    {
18
+        assertEquals(1, actual);
21 19
     }
22 20
 
23
-    /**
24
-     * Sets up the test fixture.
25
-     *
26
-     * Called before every test case method.
27
-     */
28
-    @Before
29
-    public void setUp()
30
-    {
21
+    @Test
22
+    public void removeTest(){
23
+        pb.add("Emily", "777-777-7777");
24
+        pb.add("Karl", "888-888-8888");
25
+        pb.add("Chad", "999-999-9999");
26
+        String entry = pb.remove("Emily");
27
+
28
+        assertEquals(false, pb.keyExists("Emily"));
29
+    }
30
+
31
+    @Test
32
+    public void lookupTest(){
33
+        pb.add("Karl", "888-888-8888");
34
+        String entry = pb.lookup("Karl");
35
+
36
+        assertEquals("888-888-8888",pb.lookup("Karl"));
31 37
     }
38
+    
39
+    @Test
40
+    public void reverseLookupTest(){
41
+        pb.add("Chad", "999-999-9999");
42
+        String entry = pb.reverseLookup("Chad");
32 43
 
33
-    /**
34
-     * Tears down the test fixture.
35
-     *
36
-     * Called after every test case method.
37
-     */
38
-    @After
39
-    public void tearDown()
40
-    {
44
+        assertEquals("Chad",pb.reverseLookup("999-999-9999"));
41 45
     }
46
+    
42 47
 }