ACSA Exam Prep
← All free-response questions
Question 2 · Class Design · 7 points

Parking Meter

Write the complete ParkingMeter class. A meter holds time in minutes up to a maximum. Each quarter adds 15 minutes, but time never goes above the maximum. The table shows how the class is used.

StatementValue returnedExplanation
ParkingMeter m = new ParkingMeter(60);Maximum 60 minutes; starts with 0 minutes.
m.isExpired()trueNo time on the meter.
m.insertQuarters(2)30Adds 30 minutes; returns the minutes now on the meter.
m.insertQuarters(3)6045 more would be 75, so it stops at 60.
m.pass(25)25 minutes pass: 35 left.
m.isExpired()false
m.pass(50)Time can't go below 0.
m.getMinutes()0
m.isExpired()true

Write the complete ParkingMeter class.

Your class

7 points

Your class must have a constructor and the methods insertQuarters, pass, getMinutes, and isExpired, and must behave as shown. Use private instance variables.

Tab inserts spaces. Drafts save as you type.
Self-score
0 / 7