Guest User

Untitled

a guest
Oct 18th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. import java.util.LinkedList;
  2.  
  3. public class PhoneBook {
  4.  
  5. private int index;
  6. private int numberOfEntries;
  7. private LinkedList<Entry> book = new LinkedList<Entry>();
  8.  
  9.  
  10. public PhoneBook(int maxSize){
  11. }
  12.  
  13. final boolean addNewEntry(TelephoneNumber t, Person p, Address a){
  14. book.add(index, new Entry(t, p, a));
  15. return true;
  16. }
  17.  
  18. final int getIndex(){
  19. return index;
  20. }
  21.  
  22. final boolean removeMarkedEntry(){
  23. if (book.isEmpty()== true){
  24. return false;
  25. }else{
  26. //getMarkedEntry()
  27. book.remove(getMarkedEntry());
  28.  
  29. return true;
  30. }
  31. }
  32.  
  33. final int countEntries(){
  34. return book.size();
  35. }
  36.  
  37. public Entry getFirstEntry(){
  38. if(book.size() > 0){
  39. return book.get(0);
  40. }
  41. return null;
  42. }
  43.  
  44. // final Entry getFirstEntry(){
  45. // if (book.isEmpty()){
  46. // return null;
  47. // }else
  48. // return book.getLast();
  49. // }
  50.  
  51. final Entry getLastEntry(){
  52. if (book.isEmpty()){
  53. return null;
  54. }else
  55. return book.getFirst();
  56. }
  57.  
  58. final Entry getMarkedEntry(){
  59. if (book.isEmpty()== true){
  60. return null;
  61. }else
  62. return book.get(index);
  63.  
  64. }
  65.  
  66. final void markNextEntry(){
  67. index = index + 1;
  68. }
  69.  
  70. final void markPreviousEntry(){
  71. if (book.isEmpty()== false && book.getFirst()!=book.get(index))
  72. book.get(index-1);
  73. }
  74.  
  75. public final String toString(){
  76. return book.toString();
  77. }
  78. }
Add Comment
Please, Sign In to add comment