PIC20A

Homework 2: Book Search

Assignment

You are going to write 2 classes Book.java and BookList.java.

Book.java

The class represents books. It has 2 private members:
Member variables It has one public constructor:
Constructor It has several public methods:
Methods Test1.java
public class Test1 {
    public static void main(String[] args) {
        Book book = new Book("Charles Li",  "Java Notes");
        book.showInfo();
        System.out.println("searchTitle(\"Java\") : " + book.searchTitle("Java"));
        System.out.println("searchTitle(\"hello\") : " + book.searchTitle("hello"));
        System.out.println("searchTitle(\"no\") : " + book.searchTitle("no"));
        System.out.println("searchAuthor(\"Amy\") : " + book.searchAuthor("Amy"));
        System.out.println("searchAuthor(\"Charles\") : " + book.searchAuthor("Charles"));
        System.out.println("searchAuthor(\"le\") : " + book.searchAuthor("li"));
        System.out.println("search(\"JAVA\") : " + book.search("JAVA"));
        System.out.println("serach(\"HELLO\") : " + book.search("HELLO"));
        System.out.println("search(\"notes\") : " + book.search("notes"));
        System.out.println("serach(\"ES\") : " + book.search("ES"));
    }
}
Output
Title: Java Notes   
Author: Charles Li
searchTitle("Java") : true
searchTitle("hello") : false
searchTitle("no") : true
searchAuthor("Amy") : false
searchAuthor("Charles") : true
searchAuthor("le") : true
search("JAVA") : true
serach("HELLO") : false
search("Notes") : true
search("ES") : true

BookList.java

The class represents a booklist. You can assume that there are no more than 1000 books in the booklist. You can have as many private members as you like.
The class has the following public methods:
Constructor
Methods
Suppose the booklist is
{{"Isaac Asimov", "Foundation"},
 {"Isaac Asimov",  "Second Foundation"},
 {"Isaac Asimov",  "Foundation and Empire"},
 {"Bruce Eckel",  "Thinking in Java"},
 {"John Lewis", "Java Software Solutions: Foundations of Program Design"},
 {"Charles Li", "Java Notes"},
 {"Agatha Christie", "And Then There Were None"},
 {"Agatha Christie", "Murder on the Orient Express"},
 {"Charles Dickens", "A Tale of Two Cities"},
 {"Joan M. Veon", "Prince Charles : The Sustainable Prince"},
 {"Edward Maitland Wright, Godfrey H. Hardy", "An Introduction to the Theory of Numbers"},
 {"Richard K. Guy", "Unsolved Problems in Number Theory"},
 {"Richard Monson-Haefel", "Enterprise JavaBeans"},
 {"Robin Driscoll, Rowan Atkinson", "Mr. Bean's Diary"},
 {"Brian Hatch","Hacking Linux Exposed"},
 {"John Chirillo", "Hack Attacks Encyclopedia: A Complete History of Hacks, Cracks, Phreaks, and Spies over Time"},
 {"John Chirillo","Hack Attacks Denied: Complete Guide to Network LockDown"},
 {"Julie Traxler", "Hack Proofing Your Web Applications"},
 {"David M. Burton","Elementary Number Theory"}}
Suppose you create a BookList booklist and add the books to it. For the following code:
System.out.println(booklist.search(\"bean\"));
booklist.search("bean");
System.out.println(booklist.search(\"hack\"));
booklist.search("hack");
System.out.println(booklist.search(\"xyz"\"));
booklist.search("xyz");
Output

booklist.search("bean")
1.
Title: Enterprise JavaBeans
Author: Richard Monson-Haefel

2.
Title: Mr. Bean's Diary
Author: Robin Driscoll, Rowan Atkinson

booklist.search("hack")
1.
Title: Hacking Linux Exposed
Author: Brian Hatch

2.
Title: Hack Attacks Encyclopedia: A Complete History of Hacks, Cracks, Phreaks, and Spies over Time
Author: John Chirillo

3.
Title: Hack Attacks Denied: Complete Guide to Network LockDown
Author: John Chirillo

4.
Title: Hack Proofing Your Web Applications
Author: Julie Traxler

booklist.search("xyz");
We were unable to find exact matches of your search for xyz .

Hints

What to submit

Call your source code file Book.java, BookList.java. Put this file in your submit folder. Do not place this file inside another folder within your submit folder.

Remark