Guest User

Untitled

a guest
Jan 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. public class Book
  2. {
  3.  
  4. //instance variables
  5. private String title;
  6. private String author;
  7. private double price;
  8.  
  9. //default constructor
  10. public Book()
  11. {
  12. title = "";
  13. author = "";
  14. price = 0.0;
  15. }
  16.  
  17. //overload constructor
  18. public Book(String t, String a, double p)
  19. {
  20. title = t;
  21. author = a;
  22. price = p;
  23. }
  24.  
  25. //getTitle() method
  26. public String getTitle()
  27. {
  28. return title;
  29. }
  30.  
  31. //getAuthor() method
  32. public String getAuthor()
  33. {
  34. return author;
  35. }
  36.  
  37. //getPrice() method
  38. public double getPrice()
  39. {
  40. return price;
  41. }
  42.  
  43. //toString() method
  44. public String toString()
  45. {
  46. return title + "\t" + author + "\t" + price;
  47. }
  48.  
  49.  
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. import java.util.ArrayList;
  57. public class BookStore
  58. {
  59.  
  60. private ArrayList<Book> books;
  61.  
  62. //default constructor
  63. public BookStore()
  64. {
  65. books = new ArrayList<Book>();
  66. }
  67.  
  68. //addBook() method
  69. public void addBook(Book bookAdded)
  70. {
  71. books.add(bookAdded);
  72. }
  73.  
  74. //listAll() method
  75. public void listAll()
  76. {
  77. for(Book a:books)
  78. {
  79. System.out.println(a.toString());
  80. }
  81. }
  82.  
  83. //Easy Option searchByTitle() method
  84. /*public Book searchByTitle(String searchStr)
  85. {
  86. for(Book a:books)
  87. {
  88. if(searchStr.equalsIgnoreCase(a.getTitle()));
  89. {
  90. return a;
  91. }
  92. }
  93. return null;
  94. }*/
  95.  
  96. //more difficult Option searchByTitle() method (not done yet)
  97. public ArrayList<Book> searchByTitle(String searchStr)
  98. {
  99. ArrayList<Book> matches = new ArrayList<Book>();
  100.  
  101. for( a)
  102. {
  103.  
  104. }
  105. }
  106.  
  107.  
  108. }
Add Comment
Please, Sign In to add comment