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.
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
Common Mistakes
Official Resources
Author: Tanner Crow - AP CS Teacher, 11+ years