Sprint View

2025 FRQ 1

7 min read

FRQ 1: Dog Walker Simulation

This question involves reasoning about a time-based simulation where a dog walker interacts with a dog-walking company over multiple hours. The problem focuses on state updates, constraints, and accumulation of results.


Analyze the Problem: Walkthrough

Dog Walking Shift Simulation

Problem Type: Object Interaction + Loop Simulation
Difficulty: Medium

You are given:

  • A dog-walking company that tracks how many dogs are available each hour
  • A dog walker who can only walk up to a fixed number of dogs per hour

The goal is to:

  1. Decide how many dogs the walker can take each hour
  2. Update the company so dogs are not double-booked
  3. Calculate how much money the walker earns over a shift

Core Objects and Responsibilities

DogWalkCompany

  • Owns the data about how many dogs are available per hour
  • Prevents multiple walkers from taking the same dogs
  • Exposes helper methods you must use, not reimplement

DogWalker

  • Has a capacity limit (maxDogs)
  • Works with exactly one company
  • Does not store availability itself, it queries the company

Mental Model

Think of this problem as a controlled resource system over time.

  • Each hour is independent
  • Dogs are a limited shared resource
  • The walker:
    • checks availability
    • takes as many as allowed
    • reports back what was taken

You are simulating real-world constraints:

  • You can’t walk more dogs than exist
  • You can’t exceed your capacity
  • Once dogs are taken, they’re gone for that hour

Part A: Single-Hour Decision Logic

What happens in one hour?

For a given hour:

  • Query how many dogs exist
  • Cap that number using maxDogs
  • Update the company so other walkers can’t take the same dogs
  • Return how many dogs were walked

This part focuses on:

  • Choosing the correct value
  • Updating shared state correctly
  • Avoiding unnecessary assumptions

Part B: Multi-Hour Shift Simulation

Repeat part A over a range of hours and calculate pay.

A shift:

  • Runs from startHour to endHour, inclusive
  • Calls the Part A logic every hour
  • Computes pay using fixed rules:
    • Base pay depends on dogs walked
    • Bonus depends on capacity usage or peak hours

This part focuses on:

  • Correct looping
  • Accumulating totals
  • Applying conditional logic carefully

Key Patterns This FRQ Tests

  • Looping over a range (inclusive bounds)
  • Using helper methods instead of duplicating logic
  • Managing shared mutable state
  • Applying OR conditions correctly
  • Separating single-step logic from repeated simulation

Part A:

Write the walkDogs method, which updates and returns the number of dogs this dog walker walks during the time specified by hour. Values of hour range from 0 to 23, inclusive.

A helper method, numAvailableDogs, has been provided in the DogWalkCompany class. This method returns the number of dogs available to be taken for a walk at a given hour.

The dog walker will always walk as many dogs as possible, subject to two constraints:

  • The number of dogs available from the company at that hour
  • The maximum number of dogs the walker can handle, represented by maxDogs

Another helper method, updateDogs, must be used to update the company once dogs are assigned, ensuring that multiple dog walkers do not walk the same dogs.

The walkDogs method should return the number of dogs walked during the specified hour.


Walkthrough of Part A:

This method models what happens during a single hour of dog walking.

It must:

  • Determine how many dogs are available from the company at the given hour.
  • Limit that number based on the walker’s maximum capacity (maxDogs).
  • Update the company so those dogs are no longer available for that hour.
  • Return the number of dogs actually walked.

The method does not store availability itself. It relies entirely on the company’s helper methods.

Checkpoint:
Before writing walkDogs, ask yourself:

  • What value limits how many dogs can be walked in one hour?
  • How do you prevent other dog walkers from taking the same dogs?
  • Why must the company be updated before returning the result?
  • What single value represents the final answer for the hour?

Part B:

Write the dogWalkShift method, which performs a dog-walking shift for the hours in the range startHour to endHour, inclusive, and returns the total amount earned in dollars.

A dog-walking shift consists of a sequence of one-hour walks. For example, a shift from hour 14 to hour 16 includes walks at hours 14, 15, and 16.

For each hour:

  • The base pay is $5 per dog walked
  • A bonus of $3 is added if at least one of the following conditions is true:
    • The dog walker walks exactly maxDogs dogs during that hour
    • The walk occurs during peak hours, defined as 9 through 17, inclusive

You may assume that the walkDogs method works correctly as specified in Part A and must use it appropriately to receive full credit.


Walkthrough of Part B:

This method simulates an entire dog-walking shift, hour by hour.

It must:

  • Iterate through each hour from startHour to endHour, inclusive.
  • For each hour, determine how many dogs are walked by calling walkDogs.
  • Calculate the earnings for that hour based on the number of dogs walked.
  • Apply a bonus if the walker is at full capacity or the hour falls within peak hours.
  • Accumulate the total earnings across all hours.

The method does not directly manage dog availability. All per-hour logic is delegated to walkDogs.

Checkpoint:
Before writing dogWalkShift, ask yourself:

  • Why must walkDogs be called exactly once per hour?
  • How do you ensure the loop includes both startHour and endHour?
  • When should the bonus be applied, and why is the condition an OR?
  • What variable should store the running total across the shift?

Part B Guidelines

// CODE_RUNNER: Dog Walker Answer Boxz
class DogWalkCompany
{
    private int[] dogsAvailable;
    
    public DogWalkCompany()
    {
        dogsAvailable = new int[24];
        dogsAvailable[7] = 3;
        dogsAvailable[8] = 2;
        dogsAvailable[9] = 2;
        dogsAvailable[10] = 3;
        for (int i = 0; i < 24; i++)
        {
            if (dogsAvailable[i] == 0)
            {
                dogsAvailable[i] = 5;
            }
        }
    }
    
    public int numAvailableDogs(int hour)
    {
        return dogsAvailable[hour];
    }
    
    public void updateDogs(int hour, int numberDogsWalked)
    {
        dogsAvailable[hour] -= numberDogsWalked;
    }
}

class DogWalker
{
    private int maxDogs;
    private DogWalkCompany company;
    
    public DogWalker(int max, DogWalkCompany comp)
    {
        maxDogs = max;
        company = comp;
    }
    
    public int walkDogs(int hour)
    {
        int dogsToWalk = company.numAvailableDogs(hour);
        if (dogsToWalk > maxDogs)
        {
            dogsToWalk = maxDogs;
        }
        company.updateDogs(hour, dogsToWalk);
        return dogsToWalk;
    }
    
    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;
    }
}
// Runner: Do Not Edit

public class Main
{
    public static void main(String[] args)
    {
        System.out.println("Dog Walker test starting...");
        
        DogWalkCompany company = new DogWalkCompany();
        DogWalker walker = new DogWalker(3, company);
        
        int totalEarned = walker.dogWalkShift(7, 10);
        
        System.out.println("Total earned from hours 7-10: $" + totalEarned);
        System.out.println("Expected: $59");
        System.out.println("Test " + (totalEarned == 59 ? "PASSED" : "FAILED"));
    }
}

Scoring Guidelines Part A

Write the walkDogs method, which updates and returns the number of dogs this dog walker walks during the time specified by hour (0–23 inclusive).

The method must:

  • Use company.numAvailableDogs(hour) to find how many dogs are available at that hour.
  • Decide how many dogs the walker will take, based on the walker’s limit maxDogs.
  • Use company.updateDogs(hour, dogsWalked) so those dogs are no longer available for other walkers.
  • Return the number of dogs walked for that hour.

Key idea: dogs walked is the smaller of (available dogs) and (maxDogs).

public int walkDogs(int hour)
{
    int dogsToWalk = company.numAvailableDogs(hour);

    if (dogsToWalk > maxDogs)
    {
        dogsToWalk = maxDogs;
    }

    company.updateDogs(hour, dogsToWalk);
    return dogsToWalk;
}

Guidelines:

Part A Guidelines

Part B: dogWalkShift

Write the dogWalkShift method, which performs a dog-walking shift from startHour to endHour, inclusive, and returns the total amount earned.

For each hour in the shift:

  • Call walkDogs(hour) to get how many dogs were walked that hour.
  • Compute base pay: $5 per dog.
  • Add a $3 bonus if either:
    • maxDogs dogs were walked (full capacity), OR
    • the hour is in peak hours 9 through 17 inclusive.
  • Add that hour’s pay to a running total.

Return the total pay after all hours are processed.

Key idea: loop inclusive from startHour to endHour, and apply the bonus using an OR condition.

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;
}

Guidelines:

Part B Guidelines

Course Timeline