Loading...
Loading...
A library desk numbers its books from 1 to n and handles issue and return requests. A book cannot be issued twice or returned when it is already on the shelf.
Write a class LibraryBook with fields title and issued and methods boolean issue() and boolean giveBack() that return false when the request is not allowed. Keep the books in an array.
issue k, return k or status.issue: ISSUED title or ALREADY ISSUED title. For return: RETURNED title or NOT ISSUED title. For a k outside 1 to n: NO SUCH BOOK. For status: AVAILABLE a OF n.Example
Input
2 Wings of Fire The Guide 5 issue 1 issue 1 status return 2 return 1
Output
ISSUED Wings of Fire ALREADY ISSUED Wings of Fire AVAILABLE 1 OF 2 NOT ISSUED The Guide RETURNED Wings of Fire
Book 1 cannot be issued twice, and book 2 was never issued.
Try the problem first. Open one hint at a time.
A new object's boolean field starts as false, so every book starts on the shelf.
Book k is at index k - 1; check the range before using it.
For status, count the books whose issued is false.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor