2008 AP CSA FRQ 1: Trip - Solution

2008 AP CSA FRQ 1: Trip

Topic: ArrayList & Time Calculations

Skills: ArrayList traversal, object interaction, time arithmetic, accumulator pattern

Unit: Unit 4 (Data Collections) (2025-2026 AP CSA)

Points: 9 | Time: ~22 minutes

Part (a)

Write the getDuration method that calculates the total time from departure to arrival.

Try First! Attempt before viewing solution.

Solution

public int getDuration()
{
    return arrTime.minutesFrom(depTime);
}

Part (b)

Write the getTotalTime method that calculates the total travel time for all flights in a trip.

Solution

public int getTotalTime()
{
    int total = 0;
    for (Flight f : flights)
    {
        total += f.getDuration();
    }
    return total;
}

Part (c)

Write the getWaitTime method that returns the total layover time between flights.

Solution

public int getWaitTime()
{
    int wait = 0;
    for (int i = 0; i < flights.size() - 1; i++)
    {
        Time arrivalTime = flights.get(i).getArrivalTime();
        Time nextDeparture = flights.get(i + 1).getDepartureTime();
        wait += nextDeparture.minutesFrom(arrivalTime);
    }
    return wait;
}

Key Concepts

✓ Use enhanced for loop for simple traversal
✓ Access helper methods like minutesFrom when provided
✓ Adjacent element comparison requires index-based loop
✓ Accumulator pattern for summing values

Common Mistakes

Off-by-one error in wait time loop (stop at size-1)
Not using provided helper methods
Using wrong Time objects for comparison
Integer overflow (not an issue for this scale)
Practice Similar: 2019 FRQ 3 | 2021 FRQ 3 | 2023 FRQ 3

Official Resources

Author: Tanner Crow - AP CS Teacher, 11+ years

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

[email protected]

📚

Courses

AP CSA, CSP, & Cybersecurity

Response Time

Within 24 hours

Prefer email? Reach me directly at [email protected]