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;

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 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();

}

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)"

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!