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 SensorSystem class is used to monitor a network of sensors arranged in a grid. A partial declaration of the Sensor class is shown below.

</>Java
public class Sensor
{
    /**
     * Returns the current integer reading of the sensor
     */
    public int getReading()
    { /* implementation not shown */ }

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

    /**
     * Returns the index of the row containing the most sensors
     * with a reading greater than the parameter threshold.
     * If multiple rows have the same maximum number of such sensors,
     * the method returns the smallest index among those rows.
     *
     * Preconditions: sensors is not null and no elements
     *                of sensors are null.
     *                sensors has at least one row and at
     *                least one column.
     */
    public int rowWithMostAlerts(int threshold)
    { /* to be implemented */}

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

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

Write the SensorSystem method rowWithMostAlerts. The method should return the index of the row in the sensors array that contains the greatest number of sensors with a reading strictly greater than the parameter threshold. In the event of a tie, return the smallest row index.

Suppose sensors has the following contents. The value shown in each cell is the result of calling getReading() on the Sensor object at that position.

Row

0

1

2

0

10

15

12

1

55

60

20

2

80

90

75

3

50

50

10

  • Call: rowWithMostAlerts(40)

  • Expected Return: should return 2

  • Explanation: because row 2 has 3 values greater than 40 (80, 90, 75), which is more than any other row.

  • Call: rowWithMostAlerts(100)

  • Expected Return: should return 0

  • Explanation: because no values in the grid exceed 100, so all rows have 0 alerts. Row 0 is returned as it is the first row with the maximum count (0).

  • Call: rowWithMostAlerts(18)

  • Expected Return: should return 1

  • Explanation: because row 1 and row 2 both have 3 values greater than 18. Since 1 is the smaller index, 1 is returned.

Complete method rowWithMostAlerts.

</>Java
/**
 * Returns the index of the row containing the most sensors
 * with a reading greater than the parameter threshold.
 * If multiple rows have the same maximum number of such sensors,
 * the method returns the smallest index among those rows.
 *
 * Preconditions: sensors is not null and no elements
 *                of sensors are null.
 *                sensors has at least one row and at
 *                least one column.
 */
public int rowWithMostAlerts(int threshold)
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.

public class Sensor
{
    /**
     * Returns the current integer reading of the sensor
     */
    public int getReading()
    { /* implementation not shown */ }

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}
public class SensorSystem
{
    private Sensor[][] sensors;

    /**
     * Returns the index of the row containing the most sensors
     * with a reading greater than the parameter threshold.
     * If multiple rows have the same maximum number of such sensors,
     * the method returns the smallest index among those rows.
     *
     * Preconditions: sensors is not null and no elements
     *                of sensors are null.
     *                sensors has at least one row and at
     *                least one column.
     */
    public int rowWithMostAlerts(int threshold)
    { /* to be implemented */}

    /* There may be instance variables, constructors, and methods
       that are not shown. */
}
/**
 * Returns the index of the row containing the most sensors
 * with a reading greater than the parameter threshold.
 * If multiple rows have the same maximum number of such sensors,
 * the method returns the smallest index among those rows.
 *
 * Preconditions: sensors is not null and no elements
 *                of sensors are null.
 *                sensors has at least one row and at
 *                least one column.
 */
public int rowWithMostAlerts(int threshold)