AP Computer Science A 2025 FRQ Question 1 — Complete Dog Walker Solution & Scoring Guide
AP Computer Science A 2025 – Question 1 (Dog Walker) Solution
Overview
This question involves writing two methods for the DogWalker class: walkDogs (part a) and dogWalkShift (part b). The methods use the helper functions numAvailableDogs and updateDogs from the DogWalkCompany class.
The walkDogs method determines how many dogs the walker can walk at a given hour, updates the company’s data, and returns the number walked. The dogWalkShift method computes the total pay for a full shift from startHour to endHour, inclusive.
Part (a) – walkDogs
Requirements:
- Retrieve the number of available dogs for the given hour.
- Walk no more than
maxDogs. - Walk no more than the number of dogs the company has available.
- Use
updateDogsto report the number of dogs walked. - Return the number of dogs actually walked.
Canonical Solution:
public int walkDogs(int hour) {
int dogsToWalk = company.numAvailableDogs(hour);
if (dogsToWalk > maxDogs) {
dogsToWalk = maxDogs;
}
company.updateDogs(hour, dogsToWalk);
return dogsToWalk;
}
Why This Earns All 4 Points
-
Point 1: Calls company methods correctly (
company.numAvailableDogs(hour),company.updateDogs(hour, dogsToWalk)). -
Point 2: Correctly compares available dogs with
maxDogs. - Point 3: Uses correct parameters for both company method calls and implements correct algorithm.
- Point 4: Returns the computed number of dogs walked.
Part (b) – dogWalkShift
Requirements:
- Loop from
startHourtoendHour, inclusive. - Call
walkDogsonce per hour. - Base pay: $5 per dog walked.
- Bonus: $3 if the walker either:
- walks
maxDogsdogs, or - the hour is a peak hour (9 to 17 inclusive)
- Accumulate and return total pay.
Canonical Solution:
public int dogWalkShift(int startHour, int endHour) {
int totalPay = 0;
for (int hour = startHour; hour <= endHour; hour++) {
int dogs = walkDogs(hour);
int hourPay = 5 * dogs;
if (dogs == maxDogs || (hour >= 9 && hour <= 17)) {
hourPay += 3;
}
totalPay += hourPay;
}
return totalPay;
}
Why This Earns All 5 Points
- Point 5: Correct loop bounds (inclusive).
-
Point 6: Calls
walkDogswith the correct parameter inside the loop. -
Point 7: Correct base pay calculation (
5 * dogs). - Point 8: Correct bonus calculation (only once, proper conditions).
- Point 9: Accumulates pay inside the loop and returns total pay.
Key Takeaways
- Always call helper methods exactly as specified.
- Follow algorithmic constraints (loop bounds, conditional rules).
- Separate base and bonus logic clearly.
- Return the correct computed value for each method.