AP® Computer Science A FRQ Practice: Free-Response Questions with Solutions
Work through AP Computer Science A free-response questions unit by unit, then check each answer against a worked solution.
Free · no sign-up Open questions need no account. Sign up or log in to open the rest.
Question 82
Question 83
Question 84
Question 85
Question 86
Question 87
Question 88
Question 89
The Riverside Bridge Authority operates an automated toll collection system. Vehicles crossing the bridge are charged based on the number of axles and the time of day. A standard 2-axle vehicle pays a base toll of $2.50. For each axle beyond two, an additional $1.25 is added to the base. During peak hours — defined as hours 7 through 9 and hours 16 through 18, inclusive, using a 24-hour clock — the total toll is multiplied by 1.5. During all other hours, no multiplier is applied.
PART A
Write the method public double calculateToll(int axles, int hour) that returns the toll as described above.
For example, calculateToll(2, 8) returns 3.75 (base 2.50 \(\times\) peak 1.5). calculateToll(5, 12) returns 6.25 (\(2.50 + 3 \times 1.25 = 6.25\), off-peak). calculateToll(3, 17) returns 5.625 (\((2.50 + 1.25) \times 1.5\)).
public double calculateToll(int axles, int hour) {PART B
Write the method public int peakVehicleCount(ArrayList<Integer> hours) that counts how many entries fall within peak hours (7–9 or 16–18 inclusive).
For example, if hours is [6, 8, 12, 17, 18, 22, 7], the method returns 4 (entries 8, 17, 18, 7 are peak).
public int peakVehicleCount(ArrayList<Integer> hours) {Main Solution
PART A — calculateToll
Algorithm:
- Compute the base toll: start with 2.50, then add 1.25 for each axle beyond 2, i.e.,
2.50 + (axles - 2) * 1.25. - Determine whether the hour is a peak hour: peak if
(hour >= 7 && hour <= 9) || (hour >= 16 && hour <= 18). - If peak, multiply the base toll by 1.5; otherwise return the base toll unchanged.
public double calculateToll(int axles, int hour) {
double baseToll = 2.50 + (axles - 2) * 1.25;
if ((hour >= 7 && hour <= 9) || (hour >= 16 && hour <= 18)) {
return baseToll * 1.5;
}
return baseToll;
}Verification with given examples:
calculateToll(2, 8): base = 2.50 + 0 = 2.50; peak (hour 8 ∈ [7,9]); 2.50 × 1.5 = 3.75 ✓calculateToll(5, 12): base = 2.50 + 3 × 1.25 = 6.25; not peak; 6.25 ✓calculateToll(3, 17): base = 2.50 + 1 × 1.25 = 3.75; peak (hour 17 ∈ [16,18]); 3.75 × 1.5 = 5.625 ✓
PART B — peakVehicleCount
Algorithm:
- Initialize a counter to 0.
- Iterate through every element in the
hoursArrayList. - For each element, check if it is a peak hour using the same condition as Part A.
- If it is peak, increment the counter.
- Return the counter.
public int peakVehicleCount(ArrayList<Integer> hours) {
int count = 0;
for (int hour : hours) {
if ((hour >= 7 && hour <= 9) || (hour >= 16 && hour <= 18)) {
count++;
}
}
return count;
}Verification with given example:
List: [6, 8, 12, 17, 18, 22, 7]
- 6 → not peak
- 8 → peak (count = 1)
- 12 → not peak
- 17 → peak (count = 2)
- 18 → peak (count = 3)
- 22 → not peak
- 7 → peak (count = 4)
Returns 4 ✓
Teacher Explanation
Part A tests the student's ability to compute a value using arithmetic and apply a conditional multiplier. Key skills: integer arithmetic with doubles, compound boolean conditions using && and ||, and returning a computed value.
Part B tests ArrayList traversal with a counter pattern. Students must correctly reuse the peak-hour logic and iterate over all elements. The enhanced for-loop is the cleanest approach, though a standard indexed loop is equally acceptable.
Both parts reward students who correctly identify the inclusive boundary conditions (7–9 and 16–18) and avoid off-by-one errors.
Education Coach Advice
AP Exam Strategy:
- Always trace through the provided examples by hand before writing code — they are your built-in test cases and will catch off-by-one errors immediately.
- For compound range checks, write them as
x >= low && x <= high— this is the clearest and least error-prone form. - In Part B, the counter pattern (initialize → loop → increment → return) is a standard AP CSA pattern. Practice it until it is automatic.
- If you use
calculateTolllogic in Part B, you can call your Part A method or simply duplicate the condition — either is acceptable, but calling your own method shows good design. - Write clean, readable code. AP readers award points for correct logic, not style, but readable code helps you avoid mistakes.
Traps
Common pitfalls:
- Off-by-one on axles: Writing
(axles - 1) * 1.25instead of(axles - 2) * 1.25— the base already covers 2 axles, so extra charge starts at axle 3. - Incorrect peak condition: Using
hour > 7instead ofhour >= 7, orhour < 18instead ofhour <= 18, missing the inclusive endpoints. - Integer division: If students write
2.50as250 / 100or use integer literals carelessly, they may get integer division truncation. - Part B — not using Integer unboxing: Forgetting that
ArrayList<Integer>auto-unboxes tointin comparisons is usually fine in Java, but students may confuseIntegerwithintin the loop variable declaration. - Part B — returning inside the loop: Prematurely returning
countinside the loop body instead of after it.
Question 90
AP® and Advanced Placement® are registered trademarks of the College Board, which is not affiliated with, and does not endorse, Verityprep. Names are used for identification purposes only.

