Simple Phonebook

PhoneBook.java 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import java.util.Scanner;
  2. import java.util.ArrayList;
  3. import java.util.*;
  4. /**
  5. * Created by leon on 1/23/18.
  6. */
  7. public class PhoneBook {
  8. private String name;
  9. private String phoneNumber;
  10. TreeMap<String, String>phonebook = new TreeMap<>();
  11. public PhoneBook()
  12. {
  13. }
  14. public PhoneBook(String name, String phoneNumber) {
  15. this.name = name; this.phoneNumber = phoneNumber;
  16. }
  17. public PhoneBook (TreeMap<String, String>phonebook) {
  18. this.phonebook = phonebook;
  19. }
  20. public void add(String name, String phoneNumber) {
  21. phonebook.put(name, phoneNumber);
  22. }
  23. public void remove(String name) {
  24. phonebook.remove(name);
  25. }
  26. public void removeRecord() {
  27. phonebook.clear();
  28. }
  29. public Collection<String> lookup (String name) {
  30. return phonebook.values();
  31. }
  32. public Collection<String> reverseLookup(String phoneNumber) {
  33. return phonebook.keySet();
  34. }
  35. public TreeMap<String, String> display() {
  36. return phonebook;
  37. }
  38. public void entries () {
  39. }
  40. }