2006 AP CSA FRQ 4: Customer
Topic: Comparable & String Operations
Skills Tested: compareTo logic, String comparison, multi-field comparison, return value conventions
Curriculum Alignment: Unit 2 (Selection/Iteration) (2025-2026 AP CSA)
Points: 9 | Time Estimate: ~22 minutes
Part (a)
Write the compareCustomer method that compares customers first by name, then by ID if names are equal.
Solution
public int compareCustomer(Customer other)
{
if (getName().equals(other.getName()))
return getID() - other.getID();
return getName().compareTo(other.getName());
}
Part (b)
Alternative implementation using nested conditionals for clarity.
Solution
// Alternative implementation:
public int compareCustomer(Customer other)
{
int nameCompare = getName().compareTo(other.getName());
if (nameCompare != 0)
return nameCompare;
return getID() - other.getID();
}
Key Concepts
Common Mistakes to Avoid
Official College Board Resources
About the Author: Tanner Crow is a certified AP Computer Science teacher with 11+ years of experience.
Last updated: January 2026