You are on page 1of 2

public class BookStore {

private Book[] books;

public BookStore() {
books = new Book[5];
books[0] = new Book("Stephen King","It",20);
books[1] = new Book("JK rowling","Harry Potter", 30);
books[2] = new Book("F Scott Fitzgerald","Great Gatsby",25);
books[3] = new Book("Of Mice and Men","John Steinbeck",10);
books[4] = new Book("The Giving Tree","Shel Silverstein", 26);
}
public Book searchForTitle(String word){
for(int i=0;i<books.length;i++){
Book current=books[i];
if(current.getTitle().contains(word)) {
return current;
}
}
return null;
}
public String Records(){
String result="";
for (int i=0;i<books.length;i++) {
Book current = books[i];
result+=current.getTitle()+", "+current.getAuthor()+",
"+current.getPrice()+"\n";
}
return result;
}
public String toString(){
String result="";
for (int i=0;i<books.length;i++) {
Book current = books[i];
result+=current.getTitle()+", "+current.getAuthor()+",
"+current.getPrice()+"\n";
}
return result;
}
public String printBook(String word) {
String result="";
for (int i = 0; i < books.length; i++) {
Book current = books[i];
if (current.getTitle().contains(word)) {
result+=current.getTitle()+", "+current.getAuthor()+",
"+current.getPrice()+"\n";
}
}
return result;
}
}

You might also like