← All free-response questionsQuestion 2 · Class Design · 7 points
Library Card
Write the complete LibraryCard class. A card belongs to an owner and has a limit on how many items can be checked out at once. The table shows how the class is used.
| Statement | Value returned | Explanation |
|---|---|---|
LibraryCard c = new LibraryCard("Ravi", 2); | Ravi can have up to 2 items out. | |
c.checkOut() | true | 1 item out. |
c.checkOut() | true | 2 items out. |
c.checkOut() | false | Limit reached; nothing changes. |
c.returnItem() | 1 item out. | |
c.returnItem() | 0 items out. | |
c.returnItem() | Nothing out; nothing changes. | |
c.getStatus() | "Ravi: 0/2" | Owner, items out, and limit. |
c.checkOut() | true | 1 item out. |
c.getStatus() | "Ravi: 1/2" |
Write the complete LibraryCard class.
Your class
7 pointsYour class must have a constructor and the methods checkOut, returnItem, and getStatus, and must behave as shown. Use private instance variables.
Tab inserts spaces. Drafts save as you type.
Self-score
0 / 7