Unit 4: Data Collections
CS A · Unit 4 · Paper 2

Data Collections unit test

A test on this unit alone, marked as a percentage and a letter grade — for the test your class is actually sitting, rather than for May. Answer everything, then submit once: seeing the answer to question 3 before attempting question 4 makes the final percentage meaningless.

Each paper is built from this unit’s 63 terms and is the same for everyone, so a teacher can assign “Unit 4, Paper 2” and every student sits the identical test. Multiple choice is marked objectively; the written sections you mark yourself against the model answer and rubric.
Suggested time 33 min 30 points0/17 attempted
1

2D array element assignment

2

2D array

3

Standard algorithm: sum of a 2D array

4

Comparing objects in a collection

5

Array vs ArrayList

6

Choosing an array or an ArrayList

7

set(index, obj)

8

ArrayList of objects

9

Array

10

Initializing an ArrayList with values

11

Array of Strings and .length confusion

12

Total iterations over a 2D array

Short answer 1. Define or explain: Nested collection traversal cost

3 pts

Short answer 2. Define or explain: Enhanced for loop with objects

3 pts

Short answer 3. Define or explain: Standard algorithm: count elements meeting a condition

3 pts

Short answer 4. Define or explain: Row and column length

3 pts

Free response

6 pts

This course has no free-response prompt tagged to this unit, so one from elsewhere in the course is used. It is still worth writing — the skill transfers.

A 2D int array grid represents daily rainfall readings; each row is one week and each column is one day. Write two static methods. (a) public static int rowTotal(int[][] grid, int row) — returns the sum of the values in the given row. (b) public static int driestWeek(int[][] grid) — returns the index of the row with the smallest total. If two rows tie, return the lower index. Assume grid has at least one row and that all rows have the same length. Method (b) should call method (a).