|
@@ -1,36 +1,54 @@
|
1
|
1
|
package com.zipcodewilmington.phonebook;
|
2
|
|
-import org.junit.Assert;
|
3
|
|
-import org.junit.Test;
|
4
|
|
-import org.junit.jupiter.api.Test;
|
5
|
|
-import sun.jvm.hotspot.utilities.Assert;
|
6
|
|
-
|
7
|
|
-//added all useful utilities
|
8
|
|
-Private class Person {
|
9
|
|
- private String name;
|
10
|
|
- private String phNumber;
|
11
|
|
-//initialize strings
|
12
|
|
- public Person (String name, String phNumber) {
|
13
|
|
- this.name = name;
|
14
|
|
- this.phNumber = phNumber;
|
15
|
|
- }
|
16
|
|
-//get entry (name and number)
|
17
|
|
- public void removeEntry(String name) {
|
18
|
2
|
|
|
3
|
+import java.util.ArrayList;
|
|
4
|
+import java.util.Map;
|
|
5
|
+import java.util.TreeMap;
|
|
6
|
+
|
|
7
|
+//Declare Treemap name
|
|
8
|
+public class PhoneBook {
|
|
9
|
+ //Declare Treemap name
|
|
10
|
+ //method 1
|
|
11
|
+ private TreeMap<String, ArrayList<String>> contacts;
|
|
12
|
+ private static final String add = "No such entry";
|
|
13
|
+ public String name;
|
|
14
|
+ public String phoneNumber;
|
|
15
|
+
|
|
16
|
+ public PhoneBook() {
|
|
17
|
+ contacts = new TreeMap<>();
|
19
|
18
|
}
|
20
|
|
-//remove entry from list
|
21
|
|
- public String[] getEntry() {
|
22
|
|
- return getEntry();
|
|
19
|
+
|
|
20
|
+ //Instantiate new array list and add the number
|
|
21
|
+ public void add(String name, String phoneNumber) {
|
|
22
|
+ this.name = name;
|
|
23
|
+ this.phoneNumber = phoneNumber;
|
|
24
|
+ if (contacts.containsKey(name)) {
|
|
25
|
+ contacts.get(name).add(phoneNumber);
|
|
26
|
+ }
|
|
27
|
+
|
|
28
|
+ else {
|
|
29
|
+ ArrayList<String> phoneNumbers = new ArrayList<>();
|
|
30
|
+ phoneNumbers.add(phoneNumber);
|
|
31
|
+ contacts.put(name, phoneNumbers);
|
|
32
|
+ }
|
23
|
33
|
}
|
24
|
|
-//Look up person
|
25
|
|
- public void listAll(){
|
26
|
|
- String[] listAll = new String[];
|
27
|
|
- return;
|
|
34
|
+
|
|
35
|
+ public void remove(String phoneNumber) {
|
|
36
|
+ for (Map.Entry<String, ArrayList<String>> entry : contacts.entrySet()) {
|
|
37
|
+ ArrayList<String> phoneNumArrList = entry.getValue();
|
|
38
|
+ for (int i = 0; i < phoneNumArrList.size(); i++) {
|
|
39
|
+ if (phoneNumber.equals(phoneNumArrList.get(i))) {
|
|
40
|
+ phoneNumArrList.remove(i);
|
|
41
|
+ }
|
|
42
|
+ }
|
|
43
|
+ }
|
28
|
44
|
}
|
29
|
|
-//List all names in registry
|
30
|
|
- public String getPhNumber() {
|
31
|
|
- return getPhNumber+= listAll();
|
|
45
|
+
|
|
46
|
+ public ArrayList<String> lookup(String name) {
|
|
47
|
+ //not sure of this yet
|
|
48
|
+ return contacts.get(name);
|
32
|
49
|
}
|
33
|
|
-//List all entries
|
34
|
|
-}
|
35
|
50
|
|
36
|
|
-//this is just a skeleton, gonna work on syntax
|
|
51
|
+ public void removeRecord(String name) {
|
|
52
|
+ contacts.remove(name);
|
|
53
|
+ }
|
|
54
|
+}
|