Skip to main content

Question 2: Class Design

Library cards with numbers in order

  • Unit 3
  • 7 points
  • About 25 minutes

You write a whole class from a description and a table of example calls and results: the class header, private instance variables, a constructor and the required method. New since the course was revised for 2025–26 (first tested in May 2026): it's worth 7 points instead of 9, and points are no longer taken off as penalties. On the exam: Question 2 of 4, 7 points. Section II has 4 free-response questions in 90 minutes (45% of the score), all assessing Practice 2 (Develop Code). The exam is fully digital in Bluebook: you type your Java, and the Java Quick Reference is provided. No calculator. Suggested time is our split of the 90 minutes by points; College Board gives no per-question timing.

The question and its sources

The LibraryCard class, which you will write, represents a library card.

A LibraryCard object is created with a String parameter, the owner's name. Every card gets a card number when it is created. The first card created gets number 1001, the next gets 1002, and so on, with each new card getting the next number. A new card has no books checked out.

The class has two methods.

- getCardNumber has no parameters and returns the card's number as an int.

- checkOut has no parameters. A card may have at most 5 books checked out at a time. If the card has fewer than 5 books checked out, checkOut adds one to the number of books checked out on that card and returns true. Otherwise it changes nothing and returns false.

The table shows a sample sequence of statements and their results. The statements are in a class other than LibraryCard, and these are the first cards created.

Sample statements and results

StatementValue returned (— if none)Explanation
LibraryCard a = new LibraryCard("Ana");—The first card created.
a.getCardNumber()1001The first card gets 1001.
LibraryCard b = new LibraryCard("Ben");—The second card created.
b.getCardNumber()1002The next number.
a.getCardNumber()1001Creating b doesn't change a's number.
a.checkOut() (called 5 times)true each timea now has 5 books checked out.
a.checkOut()falsea already has 5 books checked out.
b.checkOut()trueb has its own count, which was 0.

Source: Hypothetical example

Suggested time: 25 minutes

Your answers are saved in this browser as you type.

Something wrong with this question?

What's wrong?

Please don't include personal details.

Part (a)

7 points

Write the complete LibraryCard class. Your implementation must meet all specifications and conform to the examples shown in the table.

Tab indents. Press Esc, then Tab, to move on.

0 lines · 0 / 2,500 characters

Checking scoring…

Scoring it yourself shows you the rubric, examples and a model answer. Try writing your answer first.