Unit 1: Using Objects and Methods
CS A · Unit 1 · Paper 3

Using Objects and Methods 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 43 terms and is the same for everyone, so a teacher can assign “Unit 1, Paper 3” 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 36 min 33 points0/17 attempted
1

Dot operator

2

Random integer in a range

3

double

4

Primitive vs reference types

5

substring(a, b)

6

Autoboxing and unboxing

7

boolean

8

Math.random

9

Passing a reference to a method

10

void method

11

Instantiation

12

null

Short answer 1. Define or explain: Integer Division

3 pts

Short answer 2. Define or explain: equals vs == for Strings

3 pts

Short answer 3. Define or explain: indexOf

3 pts

Short answer 4. Define or explain: Class vs object

3 pts

Free response

9 pts

METHODS AND CONTROL STRUCTURES (Question 1, 9 points). A parking garage is represented by the ParkingGarage class, which provides two helper methods: int spacesAvailable(int level) returns the number of empty spaces (always ≥ 0) on the given level, and void reserve(int level, int count) decreases the number of empty spaces on that level by count (> 0). A valet is represented by the Valet class, with private instance variables int maxCars (the most cars the valet can park on one level, > 0) and ParkingGarage garage. You will write two Valet methods. public int parkOnLevel(int level) — the valet parks as many cars as the level has empty spaces, capped at maxCars; the method must call reserve to claim those spaces and returns the number of cars parked. (For example, with maxCars 5: 12 spaces available → park 5; 3 spaces available → park 3; 0 spaces available → park 0.) public double sweep(int startLevel, int endLevel) — parks cars on every level from startLevel to endLevel inclusive and returns the total fee earned. Each level pays $4.00 per car parked, plus a $2.00 surcharge for that level if the valet parked maxCars cars on it OR the level number is 1 or 2. (Example: with maxCars 3 and levels 1–4 yielding 3, 2, 2, 3 cars parked, the fee is (12 + 2) + (8 + 2) + 8 + (12 + 2) = $46.00.) Assume parkOnLevel works as specified; you must use it appropriately.

A. Complete method parkOnLevel. You must use spacesAvailable and reserve appropriately to receive full credit.

B. Complete method sweep. Assume parkOnLevel works as specified regardless of your answer to part A; you must use parkOnLevel appropriately to receive full credit.