Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Book
- {
- //instance variables
- private String title;
- private String author;
- private double price;
- //default constructor
- public Book()
- {
- title = "";
- author = "";
- price = 0.0;
- }
- //overload constructor
- public Book(String t, String a, double p)
- {
- title = t;
- author = a;
- price = p;
- }
- //getTitle() method
- public String getTitle()
- {
- return title;
- }
- //getAuthor() method
- public String getAuthor()
- {
- return author;
- }
- //getPrice() method
- public double getPrice()
- {
- return price;
- }
- //toString() method
- public String toString()
- {
- return title + "\t" + author + "\t" + price;
- }
- }
- import java.util.ArrayList;
- public class BookStore
- {
- private ArrayList<Book> books;
- //default constructor
- public BookStore()
- {
- books = new ArrayList<Book>();
- }
- //addBook() method
- public void addBook(Book bookAdded)
- {
- books.add(bookAdded);
- }
- //listAll() method
- public void listAll()
- {
- for(Book a:books)
- {
- System.out.println(a.toString());
- }
- }
- //Easy Option searchByTitle() method
- /*public Book searchByTitle(String searchStr)
- {
- for(Book a:books)
- {
- if(searchStr.equalsIgnoreCase(a.getTitle()));
- {
- return a;
- }
- }
- return null;
- }*/
- //more difficult Option searchByTitle() method (not done yet)
- public ArrayList<Book> searchByTitle(String searchStr)
- {
- ArrayList<Book> matches = new ArrayList<Book>();
- for( a)
- {
- }
- }
- }
Add Comment
Please, Sign In to add comment