12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import java.util.TreeMap;
- import java.util.Map;
- import java.util.ArrayList;
- import java.util.Map.Entry;
-
- /**
- * Created by leon on 1/23/18.
- */
- public class PhoneBook {
- Map<String, ArrayList> phoneBook = new TreeMap<String, ArrayList>();
-
- public String add(String name, String phoneNumber){
- ArrayList<String> numbers = new ArrayList<String>();
- numbers.add(phoneNumber);
- phoneBook.put(name, numbers);
- return name + " has been added.";
- }
-
- public int getSize(){
- return phoneBook.size();
- }
-
- public boolean keyExists(String name){
- return phoneBook.containsKey(name);
- }
-
- public String remove(String name){
- phoneBook.remove(name);
- return name + " has been deleted.";
- }
-
- public String lookup(String name){
- return String.join(", ", phoneBook.get(name));
- }
-
- public String reverseLookup(String phoneNumber){
- for(Map.Entry<String,ArrayList> entry : phoneBook.entrySet()) {
- String key = entry.getKey();
- ArrayList value = entry.getValue();
- if (value.equals(phoneNumber)) {
-
- }
- return entry.getKey();
- }
- return "";
-
- }
-
- public void display(){
- for(Map.Entry<String, ArrayList> entry : phoneBook.entrySet()) {
- String key = entry.getKey();
- ArrayList value = entry.getValue();
- System.out.println(key + " => " + value);
- }
-
- }
- }
|