Question: 1. (i) Write a generic class definition for class LibraryBook that stores books that can be borrowed from the library. It creates LibrayBook objects that

1. (i) Write a generic class definition for class LibraryBook that stores books that can be borrowed from the library. It creates LibrayBook objects that use title as identifiers (which would have type String), or ISBN (type integer). Provide onLoan method which takes the book ID - either title, or ISBN, and returns if the book is available in the library or not - expressed as a boolean - or some indication that the book is not found; addBook which takes the book ID, makes it available by default and stores it, and returns the indication of success or failure (e.g., if the library book capacity is reached); removeBook which removes the specified book from the library, and returns false if book is not in library. While the LibraryBook object;s can be created to have either of the above two types of book IDs, the same object can't mix and match these ID types. In other words, when you create an object, you should be able to specify which ID type this object will be handling. (12 points) Note: You can't allocate (using the "new" operator) an object or an array of objects of a generic type. So, in your constructor for LibraryBook class, you can't allocate the "books" array using a statement like this AnyTypel| books new AnyType[100]; To avoid this, you could also try to use a workaround like this inside the constructor: books (AnyType|) new Object[100]; but, depending on your Java version, it may generate warnings or not work at all. If the above workaround does not work, you may have to allocate this array, as an array of concrete types strings or integers - outside the constructor and pass this array to the constructor as an argument, so that the constructor signature becomes "LibraryBook(AnyTypel] array)" and then assign "books -array" within the constructor (ii) Write the main method that (a) creates two LibraryBook objects, one for using title as IDs and the other for using ISBN as IDs; (b) adds one entry into each LibrayBook; (c) tries to find a book in each library book and prints out the result. Compile, run, and provide the printout. (6 points) (iii) Write the main method that, again, creates two LibraryBook objects as above (one for each type of book ID), and then attempts to insert a book with ISBN as ID into the LibraryBook object that is supposed to use titles. Compile, run, and provide the printout. (6 points)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
