Skip to main content

Question 2: Class Design

Party guest list

  • Units 3 and 4
  • 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 GuestList class, which you will write, keeps the names of the people invited to a party, in the order they were invited.

A GuestList object is created with an int parameter, the most guests the party can hold. Assume it is greater than 0. A new guest list is empty.

The class has two methods.

- invite has a String parameter, a name. If that exact name is not already on the list and the list holds fewer names than the party can hold, the name is added to the end of the list and the method returns true. Otherwise the list doesn't change and the method returns false.

- getCount has no parameters and returns the number of names on the list.

The class must store the names in an ArrayList<String>.

The table shows a sample sequence of statements and their results. The statements are in a class other than GuestList.

Sample statements and results

StatementValue returned (— if none)Explanation
GuestList party = new GuestList(3);—A party for at most 3 guests.
party.invite("Kai")trueThe list is Kai.
party.invite("Mia")trueThe list is Kai, Mia.
party.invite("Kai")falseKai is already on the list.
party.getCount()2Two names.
party.invite("Leo")trueThe list is Kai, Mia, Leo.
party.invite("Zoe")falseThe party is full.
party.getCount()3Still three names.

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 GuestList 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.