Sample Handson Exam
Toll Lane Objects
Write a TollLane class (TollLane.java) for the following
program .
A TollLane object represents a typical toll lane in an expressway.
Assume that toll lanes are automated instead of manned.
Cars would pass by a toll lane and deposit money in a slot.
A driver may end up placing more or less than the expected
amount in the slot. Assume that the toll is 10.00 pesos.
If a driver deposits less than this amount, the driver is considered
a violator. If more money than the toll is deposited,
no change is given.
At some point, toll operators would like to find out how
much cash has been collected, how many cars have passed by
a toll lane as well as the number of violators.
For the sample program, this output should result.
Use BlueJ so that you could test your TollLane objects visually.
Include the
TollPlaza program
in the BlueJ project so that you can test and compare
against the expected output
(Create a TollPlaza class, and then cut and paste the code from the link).
You should be able to infer which methods
need to be present in the TollLane class from the
TollPlaza program.
Nevertheless, the methods are:
- letCarPass: method that causes a car to go through;
the argument to this method is a double value representing
the amount deposited by the driver
- getCash: returns the amount the toll lane has collected
so far
- getCars: returns the number of cars that passed through
the toll lane (including the violators)
- getViolators: returns the number of violators that passed through
the toll lane
Hint: you need three attributes for the TollLane class:
cash collected, number of cars, and number of violators
(all start with the value 0).