Develop a Book Search program in Java AND design and implement a linked list dat
ID: 3703700 • Letter: D
Question
Develop a Book Search program in Java AND design and implement a linked list data structure in Java to keep track of the books.
Input file: pj4Data.txt
Assumption:
? The number of records in pj4Data.txt is unknown.
? Your program will skip/reject dirty data lines. For example, if a line contains 2 fields, it is considered as a dirty data line and will be rejected/skipped by your program.
Each line in pj4Data.txt contains 3 fields, separated by commas:
ID, Title, Publish Year
Shown below is a sample data line: 38176,Java For Beginners,2011
You are tasked to develop a Book Search program in Java to provide three menu selections:
? Summary Report – shows all books in alphabetical order by the title.
? Search by Publish Year – allows the user to search books by a specific year.
? Exit – terminates the program.
You are also required to design and implement a linked list data structure in Java to keep track of the books.
(You are not allowed to use any linked list related library class in Java.)
Shown below is an implementation of the Book class.
You can modify the Book class as you wish.
// The Book class has 3 attributes: ID, Title, Publish Year
public class Book implements java.io.Serializable
{
int ID; String title; int year;
public Book() { }
public Book(int i, String t, int y, String a) { ID = i; title = t; year = y; }
public int getID() { return ID; }
public String getTitle() { return title; }
public int getYear() { return year;}
public void setTitle(String t) { title = t; }
public void setYear(int y) { year = y; }
public String toString() { return ID + " " + title + " " + year + " " + author; }
} // Book
pj4Data.txt :
Explanation / Answer
public ArrayList findTitles(String title)
Generates an ArrayList of all books which have titles that match (exactly) with the passed argument and returns this list to the calling program. The String compareTo method is useful here
public void sort( )
Sorts the library’s book ArrayList in ascending order according to the title field (sort these titles just as they are, i.e. don’t worry about articles such as The or A, etc.).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.