Simple Phonebook

PhoneBook.java 637B

123456789101112131415161718192021222324252627
  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); //add a new number
  12. }
  13. public void removeEntry(String name){
  14. phoneBook.remove(name);//delete a number
  15. }
  16. public int size(){
  17. return phoneBook.size(); //return size of the phonebook
  18. }
  19. public String lookUp(String name){
  20. return phoneBook.get(name);
  21. }
  22. }