Build a simple PhoneBook program.

PhoneBook.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import java.util.*;
  2. import java.util.Scanner;
  3. /**
  4. * Write a description of class PhoneBook here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. public class PhoneBook{
  10. Map<List, String> phonebook = new HashMap<>();
  11. List<String> multipleNumbers = new LinkedList<>();
  12. // public static boolean electronicPhonebook = true;
  13. // Scanner input = new Scanner(System.in);
  14. // Collection<String> c;
  15. // Iterator<String> iter = c.iterator();
  16. public PhoneBook(){
  17. }
  18. public void add(List multipleNumbers, String name){
  19. phonebook.put(multipleNumbers, name);
  20. }
  21. public void remove(String name){
  22. phonebook.remove(name);
  23. }
  24. public String lookup(String name){
  25. return phonebook.get(name);
  26. }
  27. public String reverseLookup(List number){
  28. return phonebook.get(number);
  29. }
  30. public void display(){
  31. System.out.println(" ***** WLECOME TO THE WORLD BOOK ***** ");
  32. for (Map.Entry<List,String> entry : phonebook.entrySet()){
  33. System.out.println("Όνομα: \n" + entry.getValue() + "\n" +
  34. "Αριθμός τηλεφώνου:" + "\n" + entry.getKey() + "\n");
  35. }
  36. }
  37. // public void addMultiple(){
  38. //
  39. // while(electronicPhonebook = true){
  40. // System.out.println("Enter a number and then a name. ");
  41. // String number = input.nextLine();
  42. // String name = input.nextLine();
  43. // phonebook.put(number, name);
  44. //
  45. // System.out.println("Are you done adding entries¿");
  46. // String exit = input.nextLine();
  47. // if (exit.equalsIgnoreCase("yes") || exit.equalsIgnoreCase("yeah") || exit.equalsIgnoreCase("Affirmative")){
  48. // electronicPhonebook = false;
  49. // } else
  50. // if (exit.equalsIgnoreCase("no") || exit.equalsIgnoreCase("nope") || exit.equalsIgnoreCase("nah")){
  51. // System.out.println("Okay...");
  52. // } else {System.out.println("I guess not...");
  53. // }
  54. // }
  55. // }
  56. // public static void commandCenter(){
  57. // PhoneBook runningbook = new PhoneBook();
  58. // while(electronicPhonebook = true){
  59. // runningbook.addMultiple();
  60. // }
  61. //
  62. // }
  63. }