Problem of the Day
Friday, November 20, 2026
Problem:
A partial listing of the Cookie class is given here.
public class Cookie
{
private String type;
public Cookie(String type)
{
this.type = type;
}
public String getType()
{
return type;
}
}
A separate Runner class contains the following static method.
public static int unknown(ArrayList<Cookie> cookies, String type)
{
int c = 0;
for (Cookie cookie : cookies)
if (cookie.getType().equals(type))
c++;
return cookies.size() - c;
}
What does this static method unknown do?
- identifies how many cookies of the indicated
typethere are - identifies how many cookies in the array are not of the indicated
type - removes all cookies that are not of the specified
typefrom the ArrayListcookies - removes all of the cookies of the indicated
typefrom the ArrayListcookies
The correct answer is b. The method unknown initializes a counter variable c and uses a loop to work through all of the cookies in the ArrayList, incrementing c whenever one of the indicated type is found. This number is subtracted from the total number of cookies and returned, identifying the number of cookies that are not of the specified type.