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 2Classes3Tests class design, constructors, instance variables - all Unit 3 OOP content
FRQ 3Array/ArrayList4Tests 1D array and ArrayList traversal, manipulation - 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. This question involves managing a classroom seating chart represented by a two-dimensional array of Student objects. The seating chart tracks student attendance, where each Student object maintains a record of their total absences. You will write a method in the SeatingChart class to analyze attendance patterns across the classroom.

</>Java
public class Student
{
    /** Returns the number of times this student has been absent. */
    public int getAbsenceCount()
    { /* implementation not shown */ }

    // There may be instance variables, constructors, and methods that are not shown.
}
</>Java
public class SeatingChart
{
    /** The two-dimensional array of student objects representing the seating chart. */
    private Student[][] seats;

    /**
     * Returns the index of the column with the fewest total absences.
     * If there is a tie, returns the lowest index.
     * Precondition: seats contains at least one row and one column.
     *               seats contains no null references.
     */
    public int columnWithFewestAbsences()
    { /* to be implemented */ }

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

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

Write the columnWithFewestAbsences method, which identifies the column in the seating chart with the lowest total number of absences among all students in that column. The method should traverse the 2D array to calculate the total absences for each column and return the index of the column with the minimum total. If multiple columns have the same minimum total, return the smallest index among them.

Suppose seats has the following contents, where each cell shows the Student name and their absence count in parentheses:

Row

0

1

2

0

Alex (2)

Ben (0)

Cathy (5)

1

Dana (3)

Eva (1)

Fred (0)

2

Gina (1)

Hank (4)

Iris (2)

  • Call: columnWithFewestAbsences()

  • Expected Return: should return 1

  • Explanation: Column 0 total: 2+3+1 = 6. Column 1 total: 0+1+4 = 5. Column 2 total: 5+0+2 = 7. The minimum total is 5, which corresponds to column index 1.

Write the columnWithFewestAbsences method below.

</>Java
/**
 * Returns the index of the column with the fewest total absences.
 * If there is a tie, returns the lowest index.
 * Precondition: seats contains at least one row and one column.
 *               seats contains no null references.
 */
public int columnWithFewestAbsences()






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.