Build a simple PhoneBook program.

PhoneBook.java 518B

1234567891011121314151617181920212223
  1. import java.util.TreeMap;
  2. import java.util.Map;
  3. /**
  4. * Created by Mexi Liang on 06/11/18.
  5. */
  6. public class PhoneBook {
  7. String name = "";
  8. String phoneNumber= "";
  9. Map<String,String> phoneBook = new TreeMap<>();
  10. public void addEntry(String name,String phoneNumber){
  11. phoneBook.put(name, phoneNumber);
  12. }
  13. public void removeEntry(String name){
  14. phoneBook.remove(name);
  15. }
  16. public int size(){
  17. return phoneBook.size(); //return size of the phonebook
  18. }
  19. }