123456789101112131415161718192021222324252627282930313233343536373839 |
- import java.util.*;
-
- /**
- * Created by leon on 1/23/18.
- */
- public class PhoneBook {
- private String name, phoneNumber;
- private Map<String, String> entries;
-
- public PhoneBook(){
- this.entries = new TreeMap<String, String> ();
- }
-
- public void add(String name, String phoneNumber){
- this.entries.put(name, phoneNumber);
-
- }
-
- public void remove(String name){
- this.entries.remove(name);
- }
-
-
- public void display(){
-
- if (this.entries.isEmpty()) System.out.println("Empty");
-
- for (Map.Entry<String,String> entry : entries.entrySet()){
- String key = entry.getKey();
- String value = entry.getValue();
-
- System.out.println(key + " " + value);
- }
-
- }
-
-
- }
|