Build a simple PhoneBook program.

PhoneBook.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // HashMap<List, String> c;
  15. // Iterator<String> iter = c.iterator();
  16. public PhoneBook(){
  17. }
  18. public void add(List <String> number, String name){
  19. phonebook.put(number, 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 removeRecord(){
  31. // iter.forEachRemaining(Map<List, String>, iter.remove(List));
  32. // }
  33. public void display(){
  34. System.out.println(" ***** WLECOME TO THE WORLD BOOK ***** ");
  35. for (Map.Entry<List,String> entry : phonebook.entrySet()){
  36. System.out.println("Όνομα: \n" + entry.getValue() + "\n" +
  37. "Αριθμός τηλεφώνου:" + "\n" + entry.getKey() + "\n");
  38. }
  39. }
  40. // public void addMultiple(){
  41. //
  42. // while(electronicPhonebook = true){
  43. // System.out.println("Enter a number and then a name. ");
  44. // String number = input.nextLine();
  45. // String name = input.nextLine();
  46. // phonebook.put(number, name);
  47. //
  48. // System.out.println("Are you done adding entries¿");
  49. // String exit = input.nextLine();
  50. // if (exit.equalsIgnoreCase("yes") || exit.equalsIgnoreCase("yeah") || exit.equalsIgnoreCase("Affirmative")){
  51. // electronicPhonebook = false;
  52. // } else
  53. // if (exit.equalsIgnoreCase("no") || exit.equalsIgnoreCase("nope") || exit.equalsIgnoreCase("nah")){
  54. // System.out.println("Okay...");
  55. // } else {System.out.println("I guess not...");
  56. // }
  57. // }
  58. // }
  59. // public static void commandCenter(){
  60. // PhoneBook runningbook = new PhoneBook();
  61. // while(electronicPhonebook = true){
  62. // runningbook.addMultiple();
  63. // }
  64. //
  65. // }
  66. }