Unit 3: Class Creation
CS A · Unit 3 · Paper 1

Class Creation 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 32 terms and is the same for everyone, so a teacher can assign “Unit 3, Paper 1” 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

toString

2

Immutability by design

3

Class definition

4

static method

5

Mutator (setter)

6

Instance variable default values

7

Accessor (getter)

8

Encapsulation

9

Default toString

10

Precondition

11

Constructor

12

Object reference aliasing

Short answer 1. Define or explain: equals for your own class

3 pts

Short answer 2. Define or explain: Writing a class from a specification

3 pts

Short answer 3. Define or explain: Return type of a constructor

3 pts

Short answer 4. Define or explain: Calling one constructor from another

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 class Roster stores student scores in a private field private ArrayList<Integer> scores. Write two methods for Roster.

public double average() — returns the average of all scores as a double, or 0.0 if the list is empty.

public int removeBelow(int cutoff) — removes every score strictly less than cutoff from the list and returns how many scores were removed. The order of the remaining scores must be preserved. Write the two methods. Assume all values in scores are non-null.