Fiveable
💻AP Computer Science A
​

💻AP Computer Science A

FRQ 4 – 2D Array
​
Unit 4: Data Collections
​
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 201/20

4. The Item class is used to represent products available in a store. A partial declaration of the Item class is shown.

</>Java
public class Item
{
    /**
     * Returns the category of the item (e.g., "food", "electronics")
     */
    public String getCategory()
    { /* implementation not shown */ }

    /**
     * Returns the price of the item
     */
    public double getPrice()
    { /* implementation not shown */ }

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}
</>Java
public class StoreStock
{
    private Item[][] items;

    /**
     * Returns the index of the row containing the most
     * items with the category indicated by the parameter
     * category.
     * Preconditions: items is not null and no elements
     *                of items are null.
     *                items has at least one row and at
     *                least one column.
     */
    public int rowWithMost(String category)
    { /* to be implemented */}

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

When an element of the two-dimensional array items is accessed, the first index is used to specify the row and the second index is used to specify the column.

Write the StoreStock method rowWithMost. The method should return the index of a row in items that contains the maximum number of occurrences of the parameter category. If there are multiple rows that have the maximum number of occurrences, any of their row indices can be returned.

Suppose items has the following contents. For each element, the first value is the category and the second value is the price.

Row

0

1

2

0

"tech" 50.0

"tech" 20.0

"home" 15.0

1

"home" 10.0

"home" 10.0

"home" 12.0

2

"food" 5.0

"tech" 100.0

"food" 3.0

3

"tech" 80.0

"home" 25.0

"tech" 45.0

  • Call: rowWithMost("tech")

  • Expected Return: should return either 0 or 3

  • Explanation: because "tech" appears two times in row 0, two times in row 3, and fewer times in the other rows.

  • Call: rowWithMost("home")

  • Expected Return: should return 1

  • Explanation: because "home" appears three times in row 1 and fewer times in each of the other rows.

  • Call: rowWithMost("food")

  • Expected Return: should return 2

  • Explanation: because "food" appears two times in row 2 and zero times in the other rows.

Complete method rowWithMost.

</>Java
/**
 * Returns the index of the row containing the most
 * items with the category indicated by the parameter
 * category.
 * Preconditions: items is not null and no elements
 *                of items are null.
 *                items has at least one row and at
 *                least one column.
 */
public int rowWithMost(String category)
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 carefully before 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.