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?
int slices, String toppingint slices, String topping, double diameterint slices, double diameter, boolean gluten-freeString topping, boolean gluten-free, double caloriesString topping, boolean gluten-free, boolean isHot
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.