ACSA Exam Prep
← All free-response questions
Question 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.

StatementValue returnedExplanation
LibraryCard c = new LibraryCard("Ravi", 2);Ravi can have up to 2 items out.
c.checkOut()true1 item out.
c.checkOut()true2 items out.
c.checkOut()falseLimit 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()true1 item out.
c.getStatus()"Ravi: 1/2"

Write the complete LibraryCard class.

Your class

7 points

Your 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