123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
-
-
- /**
- * Created by leon on 1/23/18.
- */
- import java.util.TreeMap;
- import java.util.Map;
- public class PhoneBook {
- String name;
- String phoneNumber;
- Map<String, String> entries = new TreeMap<String, String>();
-
- public void add(String name, String phoneNumber) {
- entries.put(name, phoneNumber);
- }
-
- public void remove(String name) {
- entries.remove(name);
- }
-
- public String lookUp(String name) {
- return entries.get(name);
- }
-
- public String reverseLookUp(String phoneNumber) {
- return entries.get(phoneNumber);
- }
-
- public void phoneNumberDisplay() {
- System.out.println(entries.values().toString());
- }
-
- public static void main(String[] args) {
- PhoneBook phonebook = new PhoneBook();
- phonebook.add("Jason", "302-444-6789");
- phonebook.add("Bill", "302-555-6543");
- phonebook.add("Johnny", "302-345-8901");
- phonebook.add("Andre", "302-231-4738");
- phonebook.add("Jerry", "302-565-5778");
- System.out.println(phonebook.lookUp("Jason"));
- phonebook.phoneNumberDisplay();
-
- }
- }
|