I\'m having trouble with the library for multiple books. I wanted to see them im
ID: 3744969 • Letter: I
Question
I'm having trouble with the library for multiple books. I wanted to see them implementation of this to use as reference in Java. I have an ebook class complete that returns author, title, and linesoftext already. Also can read page and and return number of pages. Any help would be appreciated
• BookReader(int capacity, int linesPerPage)
o constructor
o capacity is the maximum number of books this bookReader can store
o linesPerPage indicates the linesPerPage that this EbookReader can fit on its screen.
• public void addBook(URL url)
o adds a book to this EbookReader
o url is the Project Gutenberg url of the text file of a book. Convert it to the text of the book using the method Utilities.download.
o throws a EbookException if the EbookReader has exceeded its capacity
• public void addBook(String text)
o adds a book to this EbookReader. This version of addBook is useful for testing because it doesn’t require a connection to the internet
o text is just the full text of a book
o throws a EbookException if the EbookReader has exceeded its capacity
• public void deleteBook(int bid)
o deletes the bidth book from this EbookReader. All Ebooks after bid move down to fill the open spot.
o bid is the index of the book to open
o throws a EbookException if bid is not valid (less than 0 or <= to the number of books in this EbookReader)
• public int numberOfBooks()
o returns the number of books in this EbookReader
• public void printTitles() {
o prints all the book title/authors, one per line, in order. You should print the bid of each book in its line. Should use the Ebook.toString method.
• public void openBook(int bid) {
o Opens the bidth book (see readPage for this to make sense).
o bid is the index of the book to open
o throws a EbookException if bid is not valid (less than 0 or greater than or equal to the number of Ebooks in this EbookReader)
• public String readPage(int page)
o Returns the text of page from the currently open book. The currently open book is the last one openBook was called on. If I open a book, then delete it, and then try to read it, it should still work on the same book even though it is now deleted. .
o page is the page number of the page you want to read from
Explanation / Answer
/*First of all use any dynamic data structure like linked list to store the Ebooks record, so that you can add any number of books easily, or if you have a particular number of books in library with fixed number then use the array. I AM PROVIDING A DUMMY STRUCTURE FOR COMPLETE SOLUTION FOR AS MUCH AS I UNDERSTOOD THIS PROBLEM, FIX ACCORDING TO YOU WHILE COMPILING*/
class ebook
{
EbookReader head;
String author;
String title;
int LOT;
int bidno;
ebook(String author, String title, int LOT) //This is constructor to initialize info from user
{
this.bidno = bid; //This is the static bid being increased statically by class EbookReader
this.author = author;
this.title = title;
this.LOT = LOT;
System.out.println("AUTHOR"+author+" "+"TITLE"+title+" LinesofText"+LOT);
}
static class EbookReader
{
static int bid;
StringBuffer booktext = new StringBuffer(capacity); //set the booktext to be of size capacity.
String nameofthebook;
String author;
String title;
EbookReader next;
EbookReader(String data,String title, String author)
{
bid=bid+1;
author = author;
title = title;
nameofthebook = data ;
booktext =null;
next =null;
} //static class closed
} //ebook class closed
}
class BookReader extends ebook
{
ebook(String aurthor, String title, int LOT)
{
this.author = super.author;
this.title = super.title;
this.LOT = super.LOT;
}
BookReader(int capacity, int linesperpage)
{
this.capacity = capacity;
this.linesperpage = linesperpage;
}
public void addBook(URL url)
{
String url = //this is standalone java program module and will basically use the file handling system with HttpRequest Response mechanism. Code will be available online.
System.out.println("Enter the name of the book");
String Name_of_the_book = br.readLine();
EbookReader ebr = new EbookReader(Name_of_the_book,title,author); // a new node in EbookReader linked list will be created ,the title and author were already obtained from parent class ebook
ebr.next = head;
head = ebr;
try
{
ebr.booktext = //The url obtained into string format will fill the Stringbuffer till its fixed capacity only.
}
catch(EbookException e)
{
System.out.println("Exception caught : lines exceeded the capacity");
}
}
void addBook(String text)
{
String text = text;
System.out.println("Enter the name of the book");
String Name_of_the_book = br.readLine();
EbookReader ebr = new EbookReader(Name_of_the_book,title,author); // a new node in EbookReader linked list will be created, title and author already obtained from parent class ebook.
try
{
ebr.booktext = text;
}
catch(EbookException e)
{
System.out.println("Exception caught : lines exceeded the capacity");
}
}
public void deleteBook(int bid)
{
if(head == null)
{
System.out.println("EbookReader is already empty ");
return ;
}
EbookReader temp = head;
EbookReader previous = null;
if(temp!=null && temp.bid == bid)
{
head = temp.next ;
}
while(temp!=null && temp.bid!= bid)
{
previous = temp;
temp =temp.next;
}
previous.next = temp.next ;
}
public int numberOfBooks()
{
EbookReader temp = head;
int count =0;
while(temp!= null)
{
count ++;
temp = temp.next;
}
System.out.println("Number of Books is: "+count);
}
public void printTitles()
{
EbookReader temp = head;
while(temp!= null)
{
System.out.println("Bid no."+temp.bid);
System.out.println("Title "+temp.title);
System.out.println("author"+temp.author);
}
public void openBook(int bid)
{
EbookReader temp = head;
while(temp!= null && temp.bid==bid)
{
(Either this 1) File f = open(booktext); // for now the book text is string, this is solution for URL string imported into file , so open that file ,
(or this 1) System.out.println(temp.booktext); //this will directly print the text in the book on screen
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.