Bläddra i källkod

starting my treeMap

Carolynn Vansant 6 år sedan
förälder
incheckning
a818e1adcb

+ 39
- 0
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java Visa fil

@@ -1,7 +1,46 @@
1 1
 package com.zipcodewilmington.phonebook;
2
+import java.util.TreeMap;
3
+import java.util.Set;
4
+import java.util.Iterator;
5
+import java.util.Map;
2 6
 
3 7
 /**
4 8
  * Created by leon on 1/23/18.
5 9
  */
6 10
 public class PhoneBook {
11
+    //instance variable
12
+    private TreeMap<String, String> treeMap;
13
+
14
+    // void "no arguments" constructor -creates empty map
15
+    public PhoneBook() {
16
+        this.treeMap= new TreeMap<String, String>();
17
+    }
18
+
19
+    // single argument constructor -type Map -creates new map w/ same key/value mappings as argument
20
+    public PhoneBook(TreeMap treeMap) {
21
+        this.treeMap = treeMap;
22
+    }
23
+
24
+    //add a name & number entry
25
+    public void addNameNumberEntry(String name, String number) {
26
+        treeMap.put(name, number);
27
+    }
28
+
29
+    //remove a name & number entry
30
+    public void removeEntry(String name) {
31
+        treeMap.remove(name);
32
+    }
33
+
34
+    //find phone number lookup by name
35
+    public String lookupByName(String name) {
36
+         return treeMap.get(name);
37
+    }
38
+
39
+    //print out all of the entries in PhoneBook
40
+    public Set<Map.Entry<String,String>> printOutPhoneBook() {
41
+        return treeMap.entrySet();
42
+    }
43
+
44
+
45
+
7 46
 }

+ 1
- 0
src/test/java/com/zipcodewilmington/phonebook/PhoneBookTest.java Visa fil

@@ -4,4 +4,5 @@ package com.zipcodewilmington.phonebook;
4 4
  * Created by leon on 1/23/18.
5 5
  */
6 6
 public class PhoneBookTest {
7
+
7 8
 }