Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How to fill the function getallbooks?(How to make a connection between bookcolle

ID: 3675243 • Letter: H

Question

How to fill the function getallbooks?(How to make a connection between bookcollection and allbooks?) public class Libraryi private LibraryBook[] bookCollection ; private Personl] libraryUsers private Book[] allbooks public LibraryO // create an empty library public Library (LibraryBook [ books) // create a library with sone books in it! bookCol lection-books public void addBooks (LibraryBook[ books) // add some books to a library LibraryBook[] nenBookCollection = new LibraryBookl bookCollection. length + books. length]; int lenbookCollection. length for ( int i=0; i

Explanation / Answer

// There should be an method in LibraryBooks class for getting
// Book object reference in it, in other words getter for Book.
// In LibraryBook.java
public Book getBook() {
   return book;
}

// To get all the books in libray just iterate
// through the collection of LibraryBooks and get book reference
public Book[] getAllBooks() {
   // create new book array
   allBooks = new Book[bookCollection.length];

   // iterate through all the LibraryBook objects in collection
   // and get the actual Book object
   for (int i = 0; i < bookCollection.length; ++i) {
       allBooks[i] = bookCollection[i].getBook();
   }

   // return allBooks array
   return allBooks;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote