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.
Dot operator
Random integer in a range
double
Primitive vs reference types
substring(a, b)
Autoboxing and unboxing
boolean
Math.random
Passing a reference to a method
void method
Instantiation
null
Short answer 1. Define or explain: Integer Division
3 ptsShort answer 2. Define or explain: equals vs == for Strings
3 ptsShort answer 3. Define or explain: indexOf
3 ptsShort answer 4. Define or explain: Class vs object
3 ptsFree response
9 ptsMETHODS 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.