Skip to main content
The new Teacher Workspace is here. Your first 3 assignments are free. Try it →

AP Computer Science A Methods FRQ Practice

41 Methods and Control Structures questions written in the AP format. Pick one, read the full question, and write your Java code.

Your first scored response is included. A plan unlocks unlimited scoring.

New to the Methods FRQ? Read the exam guide

all units
unit 2
unit 3
unit 4

41 questions

sorted by unit

Travel itinerary planning and time calculation

Unit 2: Selection and Iteration

Teacher? Assign this question to a class

start this question

This question involves planning a trip with multiple stops using the TripPlanner class. The TripPlanner class manages a travel itinerary and calculates the total travel time. You will write a constructor and a method in the TripPlanner class.

</>Java
public class TripPlanner
{
    private String itinerary; // To be initialized in part (a)
    private int totalMinutes; // To be initialized in part (a)

    /**
     * Returns the name of the next destination based on the current stop.
     * Returns null if there are no further destinations.
     * Precondition: currentStop is a valid location name.
     */
    public String getNextStop(String currentStop)
    { /* implementation not shown */ }

    /**
     * Returns the travel time in minutes between two locations.
     * Precondition: from and to are valid location names.
     */
    public int getTravelMinutes(String from, String to)
    { /* implementation not shown */ }

    /**
     * Constructs a TripPlanner object.
     * Initializes itinerary with the departure city and totalMinutes to 0.
     * Simulates the trip by repeatedly calling getNextStop until it returns null.
     * Updates itinerary and totalMinutes as described in part (a).
     * Precondition: departure is a non-empty string.
     */
    public TripPlanner(String departure)
    { /* to be implemented in part (a) */ }

    /**
     * Generates and returns a ticket code based on the itinerary.
     * The code consists of the first two letters of each location in the itinerary,
     * converted to uppercase.
     * Precondition: itinerary contains valid locations separated by " -> ".
     *               Each location has at least two characters.
     */
    public String generateCode()
    { /* to be implemented in part (b) */ }

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}
a.

Write the constructor for the TripPlanner class. The constructor initializes the itinerary instance variable to the departure parameter and sets totalMinutes to 0. It then builds the rest of the trip by repeatedly calling the getNextStop method. Each valid next stop returned by getNextStop should be appended to itinerary preceded by " -> ", and the travel time between the current stop and the next stop (obtained by calling getTravelMinutes) should be added to totalMinutes. The process continues until getNextStop returns null.

A helper method, getNextStop, has been provided to determine the next destination. A second helper method, getTravelMinutes, returns the time required to travel between two specific locations. Consecutive calls to getNextStop are guaranteed to eventually return null.

Example 1

Consider the following calls to helper methods made within the TripPlanner constructor.
Method CallReturn Value
getNextStop("Denver")"Chicago"
getTravelMinutes("Denver", "Chicago")120
getNextStop("Chicago")"Boston"
getTravelMinutes("Chicago", "Boston")150
getNextStop("Boston")null
Based on these return values, a call to new TripPlanner("Denver") should set the instance variable itinerary to "Denver -> Chicago -> Boston" and should set the instance variable totalMinutes to 270 (120 + 150).

Example 2

Consider the following calls to helper methods made within the TripPlanner constructor.
Method CallReturn Value
getNextStop("Miami")"Orlando"
getTravelMinutes("Miami", "Orlando")240
getNextStop("Orlando")null
Based on these return values, a call to new TripPlanner("Miami") should set the instance variable itinerary to "Miami -> Orlando" and should set the instance variable totalMinutes to 240.
Complete the TripPlanner constructor. You must use getNextStop and getTravelMinutes appropriately in order to receive full credit.
/**
 * Constructs a TripPlanner object.
 * Initializes itinerary with the departure city and totalMinutes to 0.
 * Simulates the trip by repeatedly calling getNextStop until it returns null.
 * Updates itinerary and totalMinutes as described in part (a).
 * Precondition: departure is a non-empty string.
 */
public TripPlanner(String departure)
b.

Write the generateCode method, which returns a string generated from the itinerary. The code is formed by taking the first two characters of each location in the itinerary, converting them to uppercase, and concatenating them. You may assume that itinerary contains location names separated by " -> " and that every location name has at least two characters.

Example 1

If the value of itinerary is "Denver -> Chicago -> Boston", then generateCode() should return "DECHBO".

Example 2

If the value of itinerary is "Paris -> London", then generateCode() should return "PALO".
Complete the generateCode method.
/**
 * Generates and returns a ticket code based on the itinerary.
 * The code consists of the first two letters of each location in the itinerary,
 * converted to uppercase.
 * Precondition: itinerary contains valid locations separated by " -> ".
 *               Each location has at least two characters.
 */
public String generateCode()

What the Methods FRQ asks

Methods and Control Structures is FRQ 1 on the AP Computer Science A exam. You write two methods, or a constructor and a method, inside a given class, using loops, conditionals, String methods, and calls to other methods in the class.

90 min
for all four FRQs
7 points
4 in part A, 3 in part B
45%
of your score, for all four FRQs
  1. Part A: Loops and method calls

    A method or constructor with loops or conditionals that calls methods in the class

    4 pts

  2. Part B: String methods

    A method or constructor that builds or searches a String

    3 pts

How Methods FRQ practice works

Each question follows the exam’s format, from the full prompt to a score on every part.

  1. Read the full question

    The class, the method headers, and both parts, laid out the way the exam shows them.

  2. Write on a 22-minute timer

    A pace that fits all four questions into the 90-minute section. Pause it or turn it off, and your response saves as you go.

  3. Submit for a score out of 7

    Your response is scored against the scoring guidelines written for that question. Your first score is included.

Feedback on every part

A summary at the top tells you what to work on next. Below it, each part shows whether you earned the point and what the scoring guidelines were looking for.

Detailed Feedback

Part A: 0/1 point

Did not earn the point. You correctly initialized `playlist` to `firstSong`, but you initialized `totalDuration` to `maxMinutes`. To earn this point, you needed to initialize `totalDuration` to the duration of the first song by calling `getDuration(firstSong)`.

Part A: 1/1 point

Earned the point. You correctly updated the `playlist` string by appending the delimiter and the new song, and you updated `totalDuration` by adding the new song's duration inside the loop.

Part B: 1/1 point

Earned the point. You correctly identified and extracted the individual song titles by using the `split` method with the arrow delimiter.

Detailed feedback on a practice Methods FRQ

Questions about the Methods FRQ

How many responses can I get scored?

You can read every question without a plan. Your first scored response is included. A plan unlocks unlimited scoring.

Can I type Java in the editor?

Yes. Type your code the way you would on the digital exam. The Java Quick Reference is available while you write.

How is FRQ 1 different from FRQ 2?

FRQ 1 gives you the class and asks for two methods, or a constructor and a method. FRQ 2 asks you to write a whole class from a specification.

Do small syntax slips cost points?

On the exam, a slip like a missing semicolon usually doesn’t cost a point when your logic is clear. Wrong method calls and wrong comparisons do.

Are these real College Board questions?

No. We wrote them in the AP format, with the same two parts, and wrote scoring guidelines for each one.

More AP Computer Science A practice

Class Design FRQ practice

Class Design questions with the full specification and examples table.

ArrayList FRQ practice

ArrayList questions with the provided classes and the method to write.

2D Array FRQ practice

2D Array questions with the full class and the method to write.

AP Computer Science A FRQs

Every FRQ type for AP Computer Science A, with practice for each.

AP Computer Science A study guides

Unit-by-unit review for the whole course.

Write your first Methods FRQ

Pick one from the list, or let us choose for you.

Teaching AP Computer Science A? Assign these Methods FRQs to your class