浏览代码

new changes

Xcuello 5 年前
父节点
当前提交
dd2f5155b3

+ 14
- 26
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java 查看文件

@@ -1,11 +1,6 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
-import java.sql.SQLOutput;
4
-import java.util.ArrayList;
5
-import java.util.HashMap;
6
-import java.util.Map;
7 3
 import java.util.TreeMap;
8
-import java.util.Collection;
9 4
 
10 5
 /**
11 6
  * Created by leon on 1/23/18.
@@ -13,41 +8,40 @@ import java.util.Collection;
13 8
 
14 9
 public class PhoneBook {
15 10
 
16
-    TreeMap <String, String> phoneBook = new TreeMap <String, String>();
11
+    TreeMap<String, String> phoneBook = new TreeMap<String, String>();
17 12
 
18 13
     public PhoneBook() {
19 14
 
20
-
21 15
     }
22 16
 
23 17
     public boolean hasEntry(String name) {
24 18
 
19
+        if (phoneBook.containsKey(name)) {
25 20
 
26
-
27
-        return phoneBook.containsKey(name);
21
+            return true;
22
+        }
23
+        return false;
28 24
     }
29 25
 
30
-
31 26
     public void add(String name, String phoneNumber) {
32 27
 
28
+        if (this.hasEntry(name)) {
33 29
 
34
-        phoneBook.put(name, phoneNumber);
35
-
30
+            this.phoneBook.get(name);
31
+        }
36 32
 
33
+        phoneBook.put(name, phoneNumber);
37 34
 
38 35
     }
39 36
 
40 37
     public String lookUp(String name) {
41 38
 
42
-
43 39
         return phoneBook.get(name);
44 40
 
45
-
46 41
     }
47 42
 
48 43
     public void remove(String name) {
49 44
 
50
-
51 45
         phoneBook.remove(name);
52 46
 
53 47
     }
@@ -56,9 +50,9 @@ public class PhoneBook {
56 50
 
57 51
         String result = "";
58 52
 
59
-        for(String keyName : phoneBook.keySet()) {
53
+        for (String keyName : phoneBook.keySet()) {
60 54
 
61
-            if(phoneBook.get(keyName).equals(phoneNumber)) {
55
+            if (phoneBook.get(keyName).equals(phoneNumber)) {
62 56
 
63 57
                 result = keyName;
64 58
 
@@ -70,17 +64,11 @@ public class PhoneBook {
70 64
 
71 65
     public void listNamesAndNumbers() {
72 66
 
73
-        for(String keyName : phoneBook.keySet()) {
74
-            System.out.println(keyName + " " + phoneBook.get(keyName));
75
-        }
76
-
67
+        for (String keyName : phoneBook.keySet()) {
77 68
 
69
+            System.out.println(keyName + " " + phoneBook.get(keyName));
78 70
         }
79
-
80
-
81
-
82
-
83
-
71
+    }
84 72
 }
85 73
 
86 74
 

+ 0
- 1
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java 查看文件

@@ -22,7 +22,6 @@ public class PhoneBookTest {
22 22
         String name = "xzavia";
23 23
         String phoneNumber = "302-399-3694";
24 24
         phone.add(name, phoneNumber);
25
-
26 25
         boolean actual = phone.hasEntry(name);
27 26
 
28 27
         Assert.assertTrue(actual);