Question 4: 2D Array
Mirroring a picture left to right
- Unit 4
- 6 points
- About 22 minutes
You write one method that traverses, analyzes or changes data in a 2D array, often of objects, using the classes described in the question. New since the course was revised for 2025–26 (first tested in May 2026): it's worth 6 points instead of 9, and points are no longer taken off as penalties. On the exam: Question 4 of 4, 6 points. Section II has 4 free-response questions in 90 minutes (45% of the score), all assessing Practice 2 (Develop Code). The exam is fully digital in Bluebook: you type your Java, and the Java Quick Reference is provided. No calculator. Suggested time is our split of the 90 minutes by points; College Board gives no per-question timing.
The question and its sources
A drawing app stores a black-and-white picture as a two-dimensional array of brightness values from 0 (black) to 255 (white). The Picture class holds the array. When an element of a two-dimensional array is accessed, the first index is the row and the second index is the column.
The Picture class
public class Picture
{
/**
* The brightness of each pixel. pixels has at least one row and at
* least one column, and every row has the same length.
*/
private int[][] pixels;
/**
* Flips the picture left to right, as described in the question.
*/
public void mirror()
{ /* to be implemented */ }
// There may be instance variables, constructors, and methods that are not shown.
}Example: pixels before the call mirror()
| Row | Column 0 | Column 1 | Column 2 | Column 3 | Column 4 |
|---|---|---|---|---|---|
| 0 | 10 | 20 | 30 | 40 | 50 |
| 1 | 0 | 0 | 255 | 255 | 255 |
| 2 | 7 | 8 | 9 | 8 | 0 |
Source: Hypothetical example
The same pixels after the call
| Row | Column 0 | Column 1 | Column 2 | Column 3 | Column 4 |
|---|---|---|---|---|---|
| 0 | 50 | 40 | 30 | 20 | 10 |
| 1 | 255 | 255 | 255 | 0 | 0 |
| 2 | 0 | 8 | 9 | 8 | 7 |
Source: Hypothetical example
Suggested time: 22 minutes
Your answers are saved in this browser as you type.
Part (a)
6 pointsWrite the Picture method mirror, which changes pixels so the picture is flipped left to right: in every row, the value that was in column 0 ends up in the last column, the value in column 1 ends up in the second-to-last column, and so on. The rows stay in the same order. The method must work for pictures with an odd or an even number of columns.
Complete method mirror.public void mirror()
Tab indents. Press Esc, then Tab, to move on.
0 lines · 0 / 2,500 characters
Checking scoring…
Scoring it yourself shows you the rubric, examples and a model answer. Try writing your answer first.