Book.java and BookList.java.
String title: title of the book.String author : author of the book.Book(String title, String author)boolean searchTitle(String keyword): search if the title contains the keyword. boolean searchAuthor(String keyword): returns true if the athors names contains the keyword.boolean search(Sring keyword) : returns true if either title or author names contain the keyword.searchTitle("Charles") is same as searchTitle("CHARLES")searchTitle("no") should return true because the word Java notes
contains no. void showInfo(): show the information of the book at the Dos Prompt. The format is like this
Title: Java Notes Author: Charles Li
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"));
}
}
|
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(): construct an empty book. void add(Book book): add a book to the BookList, ignore it if there are more than 1000 books. void search(String keyword): search the keyword in all the books in the booklist.
If a book contains the keyword,
prints out the information at the Dos Prompt. See the sample output for the format.
{{"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"}}
|
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");
|
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 .
|
String class, toLowerCase(), toUpperCase() return lower case (or upper case) or the String.
Please refer to this link
and this link.String class, indexOf(String str)
returns the index within this string of the first occurrence of the specified substring, it returns -1 if str is not found.
You should use the method in all the search methods.
Please refer to this link. /** Name: Charles Li * Student ID : 000 000 000 * PIC ID: ccli * E-mail: ccli@math.ucla.edu * Discussion: 1A * Assignment: hw1 * * I, Charles Li, pledge that this is my own independent work, which * conforms to the guidelines of academic honesty as described in the course * syllabus. * */