2013 AP CSA FRQ 3: Skyview
Topic: 2D Arrays & Data Reconstruction
Skills: 1D to 2D conversion, row-column mapping, constructor logic
Unit: Unit 4 (Data Collections) (2025-2026 AP CSA)
Points: 9 | Time: ~22 minutes
Part (a)
Write the Skyview constructor that fills a 2D array from 1D data.
Solution
public Skyview(int numRows, int numCols, double[] scanned)
{
view = new double[numRows][numCols];
int index = 0;
for (int r = 0; r < numRows; r++)
{
if (r % 2 == 0)
{
for (int c = 0; c < numCols; c++)
{
view[r][c] = scanned[index];
index++;
}
}
else
{
for (int c = numCols - 1; c >= 0; c--)
{
view[r][c] = scanned[index];
index++;
}
}
}
}Part (b)
Write the getAverage method for a rectangular region.
Solution
public double getAverage(int startRow, int endRow, int startCol, int endCol)
{
double sum = 0;
int count = 0;
for (int r = startRow; r <= endRow; r++)
{
for (int c = startCol; c <= endCol; c++)
{
sum += view[r][c];
count++;
}
}
return sum / count;
}Key Concepts
Common Mistakes
Official Resources
Author: Tanner Crow - AP CS Teacher, 11+ years