2018 AP CSA FRQ 1: FrogSimulation Solution
2018 AP CSA FRQ 1: FrogSimulation




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
-
Start at 0 —
int position = 0 -
Loop exactly maxHops times —
for (int hop = 0; hop < maxHops; hop++) -
Add each hop result —
position += hopDistance()(can be negative) - Check negative first — frog behind start is an immediate failure
-
Check goal reached — reaching or passing
goalDistanceis a success -
After the loop — exhausted all hops without reaching goal: return
false
while loop with a separate hop counter earns full credit. Either approach is valid.Part B: runSimulations(int num) — 5 Points
5 pointsWrite 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 |
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
-
Initialize counter —
int successes = 0 -
Loop num times —
for (int i = 0; i < num; i++) - Call simulate() — MUST use the method from Part (a) to earn the point
-
Increment on success —
if (simulate()) successes++ -
Cast before dividing —
(double) successes / numprevents integer truncation
successes / num performs integer division in Java — it always returns 0 when successes < num. Always cast to double first.Common Mistakes to Avoid
goalDistance loses a point.
// Wrong - misses exact landing if (position > goalDistance) return true; // Correct if (position >= goalDistance) return true;
// Wrong - truncates to 0 most of the time return successes / num; // Correct return (double) successes / num;
simulate() loses the dedicated rubric point for method reuse.
// 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
boolean vs double completely changes your structure.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-by-Step Problem DecompositionRead 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.
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.
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.
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.
Message Sent!
Thanks for reaching out. I'll get back to you within 24 hours.
tanner@apcsexamprep.com
Courses
AP CSA, CSP, & Cybersecurity
Response Time
Within 24 hours
Prefer email? Reach me directly at tanner@apcsexamprep.com