Learn AP Comp Sci

Problem of the Day

Tuesday, February 3, 2026


Problem:

Every instance of the class MiniPizza is a small pizza with crust, sauce, cheese, and a single, optional topping that can be specified during the construction of the pizza. MiniPizza objects without a topping have null for their topping, but have the sauce and cheese that all MiniPizzas have. Additionally, each pizza is cut into 8 slices during construction, with the number of slices changing as the pizza is consumed.

Which of the following fields (instance variables) would be appropriate for a MiniPizza class?

  1. int slices, String topping
  2. int slices, String topping, double diameter
  3. int slices, double diameter, boolean gluten-free
  4. String topping, boolean gluten-free, double calories
  5. String topping, boolean gluten-free, boolean isHot

Show solution:

The correct answer is a. The topping and the number of slices are the only items mentioned in the description that might vary. Other qualities—the size of the pizza, the other ingredients—don't change, and therefore probably don't need to be saved in a variable. Additional qualities such as being gluten-free or being hot aren't mentioned in the statement, and therefore shouldn't be included in this abstraction of a pizza.