Fiveable
💻AP Computer Science A
​

💻AP Computer Science A

FRQ 1 – Methods and Control Structures
​
Unit 1: Using Objects and Methods
​
AP CS A FRQ Types & Units

Each FRQ type tests specific skills taught in particular units. Here's why certain units appear for each question type:

FRQFocusUnitsWhy
FRQ 1Methods and Control Structures1-2Tests method writing, loops, conditionals - foundational programming from Units 1-2
FRQ 2Class Design3Tests class design, constructors, instance variables - all Unit 3 OOP content
FRQ 3Data Analysis with ArrayList4Tests using, analyzing, and manipulating data in an ArrayList - Unit 4 content
FRQ 42D Array4Tests 2D array traversal and manipulation - Unit 4 content

This mapping reflects College Board's exam structure - each FRQ type tests specific skills that are taught in particular units.

Practice FRQ 1 of 191/19

1. This question involves simulating an archaeological dig using the ArtifactDig class. The class tracks the artifacts found during a digging session. You will write a constructor and a method in the ArtifactDig class.

</>Java
public class ArtifactDig
{
    /** A string containing the names of found artifacts, separated by spaces */
    private String excavatedItems; // To be initialized in part (a)

    /** The total number of artifacts found */
    private int itemsFound; // To be initialized in part (a)

    /**
     * Simulates digging in a specific location for a given number of layers.
     * Updates excavatedItems and itemsFound as described in part (a)
     * Precondition: layers > 0
     */
    public ArtifactDig(int layers)
    { /* to be implemented in part (a) */ }

    /**
     * Returns the artifact found in the current layer, or null if nothing is found.
     */
    public String digLayer()
    { /* implementation not shown */ }

    /**
     * Returns true if the artifact target appears in excavatedItems
     * at least quantity times; otherwise, returns false.
     * Precondition: excavatedItems contains words separated by single spaces.
     *               target is a single word with no spaces.
     */
    public boolean checkCollection(String target, int quantity)
    { /* to be implemented in part (b) */ }
}
a.

Write the ArtifactDig constructor, which initializes the instance variables and simulates a dig of the specified number of layers. The constructor should initialize excavatedItems to an empty string and itemsFound to 0. It should then call the helper method digLayer exactly layers times. If digLayer returns a non-null value (representing an artifact), that artifact name should be appended to excavatedItems followed by a single space, and itemsFound should be incremented.

The helper method digLayer returns a String representing the name of an artifact found in the current layer, or null if the layer contains no artifact.

Example 1

Consider the following calls to digLayer made within the constructor.
Method CallReturn Value
digLayer()"mask"
digLayer()null
digLayer()"pottery"
digLayer()"mask"
digLayer()null
Based on these return values, a call to new ArtifactDig(5) should set excavatedItems to "mask pottery mask " (note the trailing space) and itemsFound to 3.
Complete the ArtifactDig constructor.
/**
 * Simulates digging in a specific location for a given number of layers.
 * Updates excavatedItems and itemsFound as described in part (a)
 * Precondition: layers > 0
 */
public ArtifactDig(int layers)
b.

Write the checkCollection method, which returns true if the specified target artifact appears in excavatedItems at least quantity times, and false otherwise. You may assume that target is not a substring of any other artifact name (e.g., if target is "pot", it will not match "pottery").

Example 1

Assume excavatedItems is "mask pottery mask " and itemsFound is 3.
Method CallReturn Value
checkCollection("mask", 2)true
checkCollection("pottery", 2)false
checkCollection("bone", 1)false
In the first call, "mask" appears 2 times, which is at least 2, so it returns true. In the second call, "pottery" appears 1 time, which is not at least 2, so it returns false.
Complete the checkCollection method. You must use String methods appropriately to receive full credit.
/**
 * Returns true if the artifact target appears in excavatedItems
 * at least quantity times; otherwise, returns false.
 * Precondition: excavatedItems contains words separated by single spaces.
 *               target is a single word with no spaces.
 */
public boolean checkCollection(String target, int quantity)
Timed

00:00

Response auto-saves






Pep

essential ap study content awaits..

Features
Testimonials
Testimonials
start studying →
FRQ Directions
Free Response Question Practice

This practice environment simulates the AP AP Computer Science A Free Response Questions section. Here are some guidelines:

  • Read each question carefullybefore responding. Pay attention to command verbs like "identify," "explain," "analyze," or "evaluate."
  • Use the timer to practice time management. You can pause, restart, or hide the timer as needed.
  • Mark for Review if you want to come back to a question later.
  • Your responses are saved automatically as you type. You can also use the drawing tool for questions that require diagrams or graphs.
  • Use the toolbar for formatting options like bold, italic, subscript, and superscript.
  • Navigate between questions using the Previous and Next buttons at the bottom of the screen.

Tip: Answer all parts of each question. Partial credit is often available, so even if you are unsure, provide what you know.