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:
- its
color(a String "red", "green", or "blue") - its
value(anintfrom 1 to 3) - its
Texture(a String "solid", "striped", or "dotted")
A series of corresponding accessor methods are available in the Card class:
public String getColor()public int getValue()public String getTexture()
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?
c.getColor().equals("red") && c.getValue() > 1 && !(c.getTexture().equals("striped"))!(c.getColor().equals("red") || c.getValue() > 1 || !(c.getTexture().equals("striped")))c.getColor().equals("red") || c.getValue() >= 1 || !(c.getTexture().equals("striped"))c.getColor().equals("red") || c.getValue() >= 1 || c.getTexture().equals("striped")
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.