|
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
This shorter homework is due on the last day of class (Dec.12 (Fri)) 17:00. It involves one modification to lab14a.
As in lab14a, write a program which reads a “catalog file” of books, and then lets the users search for books by author's name. However, we will modify it so that the user doesn't need to provide the author's entire name: we will only search by the author's last name.
In order to implement this properly, we'll make another class: class Name, which has two fields (“first” and “last”). The class Book will still have exactly two fields -- a title (still a String), and an author (which is now a Name object).
Some details on class Name:
make a constructor which takes in one String, and creates a Name object containing both the first-name and the last-name separately For example,
Name unbearableAuthor; unbearableAuthor = new Name("Milan Kundera"); unbearableAuthor.getFirst() // should return "Milan" unbearableAuthor.getLast() // should return "Kundera" |
To split one string into two, use the String method split(" "). (Note that you'll want to pass in " " as the argument. To understand the return-type, see the documentation, and I also suggest experimenting in the Code Pad, double-clicking the small red icon to inspect the return value. Discuss on BlackBoard's discussion boards, if questions.)
Allow partial names to match, ignoring case: that is, if the user searches for author "rush" or "sh", this would include all books by Salman Rushdie.
(In this scheme, the fewer characters the users enters, the more records are matched. For example, "e" would match many authors. What authors woudl the empty-string match?)
new Name("Harry Connick") new Name("Harry Connick Jr.") new Name("Mr. Harry Connick") new Name("Mr. Harry Connick Jr.") |
home—info—labs—hws—exams
textbook—java.lang docs—java.util docs—archive
©2008, Ian Barland, Radford University Last modified 2008.Dec.09 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |