Преглед изворни кода

not finished will let you know

Amy Gill пре 6 година
родитељ
комит
7167b66972

+ 6
- 1
src/main/java/com/zipcodewilmington/phonebook/Person.java Прегледај датотеку

@@ -1,5 +1,7 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
+/*
4
+
3 5
 public class Person {
4 6
 
5 7
     //variables
@@ -7,7 +9,7 @@ public class Person {
7 9
     /*we made these private bc we don't want the user to be able to change the data. Another reason we want to do this
8 10
      is that you want to "hide" how you store the information from the users.
9 11
 
10
-    */
12
+
11 13
     private String name;
12 14
     private String phoneNumber;
13 15
 
@@ -35,3 +37,6 @@ public class Person {
35 37
 
36 38
 
37 39
 }
40
+
41
+*/
42
+

+ 31
- 9
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java Прегледај датотеку

@@ -1,5 +1,6 @@
1 1
 package com.zipcodewilmington.phonebook;
2 2
 
3
+import java.util.ArrayList;
3 4
 import java.util.Map;
4 5
 import java.util.Set;
5 6
 import java.util.TreeMap;
@@ -7,7 +8,9 @@ import java.util.TreeMap;
7 8
 public class PhoneBook {
8 9
 
9 10
     //the below defines what kind of attribute you have, which in this case is your "contacts"
10
-    Map<String, Person> personMap;
11
+    TreeMap<String, String> personMap;
12
+
13
+    String name = "";
11 14
 
12 15
     //this is your constructor. whenever you see public + the classname, that is your constructor
13 16
     //
@@ -21,14 +24,16 @@ public class PhoneBook {
21 24
         // this treeMap initializes the "blank pages of the book". the treemap is the structure of how your book will hold info
22 25
 
23 26
         //if you were to not set this, your person map would be null(default setting)
24
-        this.personMap = new TreeMap<String, Person>();
27
+        this.personMap = new TreeMap<String, String>();
25 28
     }
26 29
 
27 30
     // this is our method below. it describes what we can do with this phonebook
28 31
 
29 32
     //so later, when you call "phonebook.add", that's like someone literally writing a new name and number in your phonebook object
30
-    public void add(String name, String number){
31
-        this.personMap.put(name, new Person(name, number));
33
+
34
+
35
+    public void add(String name, String number) {
36
+        personMap.put(name, number);
32 37
     }
33 38
 
34 39
     /*
@@ -40,18 +45,23 @@ public class PhoneBook {
40 45
 
41 46
     */
42 47
 
43
-    public Person lookup(String name) {
48
+    public void remove(String name, String number) {
44 49
 
45
-       return personMap.get(name);
50
+        personMap.remove(name);
51
+    }
52
+
53
+    public String lookup(String name) {
54
+
55
+        return personMap.get(name);
46 56
 
47 57
     }
48 58
 
49
-    public String reverseLookup (String phoneNumber){
59
+   /* public String reverseLookup (String phoneNumber){
50 60
 
51 61
         //this will "grab" all the listings in your book. it does NOT print them.
52
-        Set<Map.Entry<String, Person>> entries = personMap.entrySet();
62
+        Set<Map.Entry<String, String> = personMap.entrySet();
53 63
 
54
-        for (Map.Entry<String, Person> phoneBookEntry : entries) {
64
+        for (Map.Entry<String, String> phoneBookEntry : entries) {
55 65
 
56 66
             Person person = phoneBookEntry.getValue();
57 67
 
@@ -64,5 +74,17 @@ public class PhoneBook {
64 74
 
65 75
     }
66 76
 
77
+    */
78
+
79
+    public void displayAllEntries() {
80
+
81
+        for (Map.Entry<String, String> entry : personMap.entrySet()) {
82
+            String name = entry.getKey();
83
+            String number = entry.getValue();
84
+        }
85
+
86
+    }
87
+
88
+
67 89
 }
68 90
 

+ 15
- 9
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java Прегледај датотеку

@@ -4,29 +4,35 @@ import org.junit.Assert;
4 4
 import org.junit.Before;
5 5
 import org.junit.Test;
6 6
 
7
+import java.util.Map;
8
+import java.util.TreeMap;
9
+
7 10
 /**
8 11
  * Created by leon on 1/23/18.
9 12
  */
10 13
 public class PhoneBookTest {
11 14
 
12
-    PhoneBook testPhonebook;
13
-    Person john;
15
+    PhoneBook testPhonebook = new PhoneBook();
16
+
17
+    TreeMap<String, String> personMapTest= new TreeMap<String, String>();
14 18
 
15 19
     @Before
16
-    public void setup() {
17
-        testPhonebook = new PhoneBook();
18
-        john = new Person("JohnDoe", "111-555-1234");
19
-    }
20 20
 
21
+    public void setup(){
22
+
23
+//Start off here. google "how to write a test for a map"
24
+
25
+    }
21 26
 
22 27
     @Test
23 28
     public void testLookup() {
24 29
 
25
-        testPhonebook.add(john.getName(), john.getPhoneNumber());
30
+        personMapTest.put("JohnDoe", "1123");
26 31
 
27
-        Person actualPerson = testPhonebook.lookup(john.getName());
32
+        String expected = "JohnDoe";
33
+        String actual = testPhonebook.lookup(expected);
28 34
 
29
-        Assert.assertEquals(john.getPhoneNumber(), actualPerson.getPhoneNumber());
35
+        Assert.assertEquals(expected, actual);
30 36
 
31 37
     }
32 38