2018 AP CSA FRQ 1: FrogSimulation Solution

FRQ Archive2018 FRQsFRQ 1 — FrogSimulation

2018 AP CSA FRQ 1: FrogSimulation

Methods & Control Structures 9 Points Total Medium Unit 1 & Unit 2
Practice Timer (22 min recommended) 22:00
Official College Board Question Pages — Click any page to expand
2018 AP CSA FRQ 1 page 1 - FrogSimulation class declaration with goalDistance, maxHops fields and method signatures for hopDistance, simulate, runSimulations
Page 1 of 4
2018 AP CSA FRQ 1 page 2 - simulate() specification with example table of 5 hop sequences and their return values
Page 2 of 4
2018 AP CSA FRQ 1 page 3 - simulate() answer blank and runSimulations() specification
Page 3 of 4
2018 AP CSA FRQ 1 page 4 - runSimulations() answer blank
Page 4 of 4

Click any page to open full size in a new tab.

Part A: simulate() — 4 Points

4 points Write Your Solution:
View Solution & Scoring Rubric

Scoring Rubric

+1 Initializes position variable to 0
+1 Loop runs at most maxHops times; calls hopDistance() and updates position each iteration
+1 Checks for negative position inside loop and returns false
+1 Returns true when position >= goalDistance; returns false after loop ends without success

Solution

public boolean simulate()
{
    int position = 0;

    for (int hop = 0; hop < maxHops; hop++)
    {
        position += hopDistance();

        if (position < 0)
            return false;

        if (position >= goalDistance)
            return true;
    }

    return false; // all hops used, goal not reached
}

Step-by-Step Explanation

  1. Start at 0int position = 0
  2. Loop exactly maxHops timesfor (int hop = 0; hop < maxHops; hop++)
  3. Add each hop resultposition += hopDistance() (can be negative)
  4. Check negative first — frog behind start is an immediate failure
  5. Check goal reached — reaching or passing goalDistance is a success
  6. After the loop — exhausted all hops without reaching goal: return false
Alternative: A while loop with a separate hop counter earns full credit. Either approach is valid.

Part B: runSimulations(int num) — 5 Points

5 points

Write the runSimulations method. Call simulate() exactly num times. Count how many calls return true. Return that count divided by num as a double.

Method signature: public double runSimulations(int num)  |  Precondition: num > 0

Examples

num Successes counted Returns
400 100 0.25
1000 732 0.732
1 0 0.0
Write Your Solution:
View Solution & Scoring Rubric

Scoring Rubric

+1 Initializes a success counter to 0
+1 Loop runs exactly num times
+1 Calls simulate() inside the loop (must use the method — not rewrite logic)
+1 Increments counter only when simulate() returns true
+1 Returns the proportion as a double, avoiding integer division

Solution

public double runSimulations(int num)
{
    int successes = 0;

    for (int i = 0; i < num; i++)
    {
        if (simulate())
            successes++;
    }

    return (double) successes / num;
}

Step-by-Step Explanation

  1. Initialize counterint successes = 0
  2. Loop num timesfor (int i = 0; i < num; i++)
  3. Call simulate() — MUST use the method from Part (a) to earn the point
  4. Increment on successif (simulate()) successes++
  5. Cast before dividing(double) successes / num prevents integer truncation
Integer division trap: successes / num performs integer division in Java — it always returns 0 when successes < num. Always cast to double first.

Common Mistakes to Avoid

Using > instead of >= for the goal check The frog succeeds when it reaches or passes the goal. Missing an exact landing on goalDistance loses a point.
// Wrong - misses exact landing
if (position > goalDistance) return true;

// Correct
if (position >= goalDistance) return true;
Integer division in runSimulations This is one of the most common points lost on this FRQ type.
// Wrong - truncates to 0 most of the time
return successes / num;

// Correct
return (double) successes / num;
Not calling simulate() in Part B Rewriting the simulation logic instead of calling simulate() loses the dedicated rubric point for method reuse.
Off-by-one on the hop loop
// Wrong - runs maxHops+1 times
for (int hop = 0; hop <= maxHops; hop++)

// Correct - exactly maxHops iterations
for (int hop = 0; hop < maxHops; hop++)

Exam Tips

Tip 1: Always call Part (a)'s method inside Part (b). The rubric explicitly rewards this and it saves you from rewriting logic.
Tip 2: Read the return type before writing any code. boolean vs double completely changes your structure.
Tip 3: Check both the negative and goal conditions inside the loop body — not just at the end. Either can trigger mid-hop.

Official College Board Resources

Related FRQs (Same Type)

How to Break Down This FRQ: A Step-by-Step Walkthrough

Already attempted it? Good. Now let's talk through exactly how an experienced AP teacher would read this problem and build the solution from scratch.

Step 1

Read the return type before anything else

The very first thing you should do with any FRQ method is look at the return type. For simulate(), it returns boolean. That immediately tells you: this method ends with either return true or return false. There is no other option. So your entire job is to figure out when to return each one.

For runSimulations(), the return type is double. That's a hint — if everything you're counting is an int, you'll need to force double division or you'll get 0 every time. That's one of the most common integer division traps on the AP exam.

Step 2

Identify your stopping conditions before writing the loop

In simulate(), you have three ways the loop can end: the frog reaches or passes the goal (return true), the frog's position goes negative (return false), or you've used all maxHops hops without success (return false). Write these conditions down on scratch paper before touching the loop structure. Students who jump straight to writing a for loop often forget one of the three exit conditions.

Step 3

Decide between for and while — both work, but know why

Because you know exactly how many hops the frog gets (maxHops), a for loop is a natural fit. Loop from 0 to maxHops (exclusive), accumulate position, and check your stop conditions inside the loop body. A while loop with a separate counter is equally valid and earns full credit — the College Board doesn't care which you use as long as the logic is correct.

Step 4

For Part B, call Part A — don't rewrite it

This is a multi-part FRQ where Part B depends on Part A. The rubric explicitly awards a point for calling simulate() rather than copying its logic. Even if your Part A solution was wrong, you still earn that point in Part B by referencing it correctly. Think of it as: Part B is a manager, Part A is the worker. The manager calls the worker and counts results — it doesn't do the work itself.

Mistake 1: Checking position AFTER accumulating all hops

Some students write the loop, add all hops, then check the result afterward. The problem says to stop as soon as a condition is met. If you wait until the loop finishes, you'll return the wrong value for cases where the frog went negative mid-hop but happened to recover by the end. Check the condition inside the loop after every single hop.

Mistake 2: Integer division in runSimulations()

If you write return successCount / num and both are int, Java returns an int result — that means 3 successes out of 10 attempts gives you 0, not 0.3. You must cast: return (double) successCount / num. The cast only needs to be on one operand, but it must be there. This costs one point on the rubric and is completely avoidable.

Mistake 3: Using hopDistance() as a field instead of a method call

The problem provides private int hopDistance() as a method, not a field. You must call it with parentheses: hopDistance(). Writing hopDistance without the () is a compile error. Students who rush past the class definition miss this and wonder why their code doesn't work.

Know what each point is actually testing

The College Board breaks this FRQ into 9 points total — 4 for Part A, 5 for Part B. In Part A, points are awarded for: initializing position to 0, correctly looping up to maxHops times, accumulating position with hopDistance(), and returning the correct boolean in each case. In Part B, points go to: calling simulate(), tracking the count, looping exactly num times, and returning a double. You can earn most of these points even with minor errors — partial credit is real on FRQs.

A common scoring strategy is to write readable, well-structured code even if you're unsure about one piece. Graders follow an "own-rule" policy — if your Part A has a bug but Part B uses it correctly, Part B can still receive full credit based on how you used your own Part A.

Where this lives in the 2025-2026 curriculum

This FRQ sits squarely in Unit 1 (Primitive Types and Methods) and Unit 2 (Selection and Iteration). The simulate() method tests your understanding of while/for loop control flow and early exit with return — core Unit 2 concepts. The integer division trap in runSimulations() is a Unit 1 concept: understanding how Java handles arithmetic between different primitive types.

The pattern of "call a helper method in a larger computation" — using Part A inside Part B — shows up constantly on AP CSA FRQs and is central to how Unit 1 and Unit 3 teach method design. If you can recognize "this method does one job, and I call it repeatedly," you're thinking like a computer scientist, not just a student.

Get in Touch

Whether you're a student, parent, or teacher — I'd love to hear from you.

Just want free AP CS resources?

Enter your email below and check the subscribe box — no message needed. Students get daily practice questions and study tips. Teachers get curriculum resources and teaching strategies.

Typically responds within 24 hours

Message Sent!

Thanks for reaching out. I'll get back to you within 24 hours.

🏫 Welcome, fellow educator!

I offer curriculum resources, practice materials, and study guides designed for AP CS teachers. Let me know what you're looking for — whether it's classroom materials, a guest speaker, or Teachers Pay Teachers resources.

Email

tanner@apcsexamprep.com

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at tanner@apcsexamprep.com