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

There are some errors in this code I want you to fix it and please make it clear

ID: 3738412 • Letter: T

Question

There are some errors in this code I want you to fix it and please make it clear

public class BookProcessor {

            private Book[] books;        // Array to store Book object references

    private int numBooks = 0; // Keeps count of books added into the array

    private BookComparator<Book> bc;

            public BookProcessor() {

                       

                        // Instantiate the array to a length of 10

                        for ( int i=0; i<10; i++) {

                                    books[i]=new Book();

                        }

                        // Instantiate BookComparator

                        bc = new BookComparator<Book>();

                       

           

            }

           

            public void addBook(Book bk) throws BookException {

           

                                    if(bk.bookID < 0)

                                                throw new BookException("Invalid BookId!!");

                                    else {

                                                books[numBooks] = bk;

                                                numBooks++;

                                    }

           

            }

           

            public void sortBooksRecurse(int startIndex) {

                       

                        // import java.util.Array

                        Arrays.sort(books, new SortBybookID);       

                       

                        // This will sort all the books, but there might be some empty elements in the array, to sort elemtns which really exists use "Arrays.sort(books, new SortBybookID, startIndex, numBooks)"

           

            }

           

}

Create Class: BookProcessor Description: This is the application's workhorse. It stores Book object references in an recursively Instance variables: Array to store Book object references private Book[] books; private int numBooks 0; Keeps count of books added into the array private BookComparator-Book? bo; Constructor public BookProcessor0 Instantiate the array to a length of 10 Instantiate BookComparator Methods: public void addBook(Book bk) throws BookException If the bookID of the book object referenced by bk

Explanation / Answer

Hi friend, I have fixed the issue : check BOLD texts

import java.awt.print.Book;

public class BookProcessor {

   private Book[] books; // Array to store Book object references

   private int numBooks = 0; // Keeps count of books added into the array

   private BookComparator<Book> bc;

   public BookProcessor() {

       // first create Book array

       books = new Book[10];

      

       // Instantiate the array to a length of 10

       for ( int i=0; i<10; i++) {

           books[i]=new Book();

       }

       // Instantiate BookComparator

       bc = new BookComparator<Book>();

   }

   public void addBook(Book bk) throws BookException {

       if(bk.bookID < 0)

           throw new BookException("Invalid BookId!!");

        else if(numBooks < books.length-1) {

           books[numBooks] = bk;

           numBooks++;

       }

   }

   public void sortBooksRecurse(int startIndex) {

       // import java.util.Array

       Arrays.sort(books, new SortBybookID);

       // This will sort all the books, but there might be some empty elements in the array, to sort elemtns which really exists use "Arrays.sort(books, new SortBybookID, startIndex, numBooks)"

   }

}

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