123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
-
-
- import java.util.ArrayList;
- import java.util.Map;
- import java.util.TreeMap;
-
- /**
- * Created by leon on 1/23/18.
- */
- public class PhoneBook {
- public static void main (String[] args){
-
- }
-
-
- private Map<String, ArrayList<String>> directory;
-
- public PhoneBook (){
- directory= new TreeMap< String, ArrayList<String>>();
-
- }
- public void setValues(String name, ArrayList<String>phonenumber){
- this.directory.put(name, phonenumber);
- }
-
-
- public boolean hasEntry(String name) {
-
- return directory.containsKey(name);
-
- }
-
- public void add(String name, String number) {
- ArrayList<String> contact = new ArrayList<>();
- contact.add(number);
- directory.put(name,contact);
-
- }
-
-
-
- public ArrayList<String> getContact(String name) {
- return directory.get(name);
- }
- public String reverseLookUp(String number){
- String repply= "Not here";
- for (String name:directory.keySet()){
- ArrayList<String> reverse= directory.get(name);
- for (String looking: reverse){
- if (looking.equals(number)){
- repply= name;
- }
- }
- }
- return repply;
- }
-
- public void remove (String name){
- if (directory.containsKey(name)){
- directory.remove(name);
- }
- }
-
- public String listNameAndNumbers() {
- StringBuilder builder = new StringBuilder();
- for (String name:directory.keySet()){
- for (int i= 0; i< directory.get(name).size(); i++){
- builder.append(name + " " + directory.get(name).get(i) + "\n");
- }
- }
- return builder.toString();
- }
-
-
- public Map<String, ArrayList<String>> getDirectory() {
- return directory;
- }
- public Map<String, ArrayList<String>> getContact() {
- return directory;
- }
-
-
- public void setDirectory(Map<String, ArrayList<String>> directory) {
- this.directory = directory;
- }
-
-
-
- }
|