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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started