Procházet zdrojové kódy

starting my treeMap

Carolynn Vansant před 6 roky
rodič
revize
a818e1adcb

+ 39
- 0
src/main/java/com/zipcodewilmington/phonebook/PhoneBook.java Zobrazit soubor

1
 package com.zipcodewilmington.phonebook;
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
  * Created by leon on 1/23/18.
8
  * Created by leon on 1/23/18.
5
  */
9
  */
6
 public class PhoneBook {
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 Zobrazit soubor

4
  * Created by leon on 1/23/18.
4
  * Created by leon on 1/23/18.
5
  */
5
  */
6
 public class PhoneBookTest {
6
 public class PhoneBookTest {
7
+
7
 }
8
 }