Loading...
Loading...
A library keeps its own book records and registers members who exist outside it. A book is issued to at most one member, and a member holds at most 2 books.
Write Book (id, title, the Member holding it or null), Member (name, Book[2], count) and Library. Library.addBook creates books (composition); members are created in main and registered (aggregation). Issuing and returning must update the book and the member.
book ID TITLE, member NAME, issue ID NAME, return ID or show NAME.ADDED ID / DUPLICATE ID; REGISTERED NAME / DUPLICATE NAME; for issue, the first that applies: NO BOOK ID, NO MEMBER NAME, ID ISSUED TO X, LIMIT NAME, else ISSUED ID TO NAME; for return: NO BOOK ID, ID NOT ISSUED or RETURNED ID FROM NAME; for show: NO MEMBER NAME or NAME: T1, T2 in issue order, or NAME: -.Example
Input
9 book B1 Godaan book B2 Gitanjali book B3 Malgudi_Days member Asha issue B1 Asha issue B2 Asha issue B3 Asha return B1 show Asha
Output
ADDED B1 ADDED B2 ADDED B3 REGISTERED Asha ISSUED B1 TO Asha ISSUED B2 TO Asha LIMIT Asha RETURNED B1 FROM Asha Asha: Gitanjali
Asha reaches the limit of 2, returns Godaan, and keeps Gitanjali.
Try the problem first. Open one hint at a time.
Keep Book[] and Member[] arrays with counts in Library, plus findBook(id) and findMember(name) helpers.
Issue: book.setHolder(member) and member.take(book). Return: holder.give(book) and book.setHolder(null).
Check the errors in exactly the order given in the output format.
Member.give removes the book with a left shift so show keeps issue order.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor