Learn AP Comp Sci

Problem of the Day

Friday, January 2, 2026


Problem:

The Card class describes a card used in playing a pattern-matching game. A card is characterized by three attributes:

A series of corresponding accessor methods are available in the Card class:

Which of the following boolean expressions will correctly evaluate as true only for cards that are "red", with a value of 2 or 3, and that are not striped, where c is a Card object?

  1. c.getColor().equals("red") && c.getValue() > 1 && !(c.getTexture().equals("striped"))
  2. !(c.getColor().equals("red") || c.getValue() > 1 || !(c.getTexture().equals("striped")))
  3. c.getColor().equals("red") || c.getValue() >= 1 || !(c.getTexture().equals("striped"))
  4. c.getColor().equals("red") || c.getValue() >= 1 || c.getTexture().equals("striped")

Show solution:

The correct answer is a. Although expressions (a), (c), and (d) all evaluate to true for a given red card with a value greater than 1 and that is not striped, (c) and (d) will also evaluate to as true for some cards that don't fit that description. Answer (a) is the one that works correctly for all cards.