Java Prac
Java Prac
1. Problem Statement
The Department of Highways of a particular county is installing a toll collection system on one of its major
roads. Trucks pulling up to a tollbooth are required to pay a toll of $5 per axle plus $10 per half-ton of the
truck's total weight. A display in the booth shows the toll receipts and the number of truck arrivals since the
last collection.
You will design an object oriented program in Java that simulates the operation of the tollbooth.
Sample Scenario
To aid understand the problem statement let us imagine how such a toll collection system might work. A
toll agent sits in a tollbooth that is equipped with a computer screen and a bar code reader. When a truck
arrives at the booth, the agent scans a bar code on the windshield of the truck; it contains information about
the truck, including its number of axles. The weight of the truck is obtained by scanning a bar code
contained on the bill of lading presented by the driver. The truck information and toll due are then
displayed on the computer screen:
When a button on the side of the screen is pressed, the booth's totals are displayed:
When the cash drawer is removed from its cradle, the following is displayed on the screen. The totals are
displayed and then reset to zero:
This scenario will be simulated by the object oriented system that you will build.
3. Create a class that implements the specified interface TollBooth. For example: AlleghenyTollBooth
This class keeps track of a) the total number of trucks that have gone through the tollbooth and b) total
receipts since collection.
The methods of your class specified in the interface will at least perform the following:
a) display the booth's totals simply by printing those values to System.out and b) display the totals
maintained by the booth and then reset them to zero because receipts and truck. Remember that totals
are maintained only since the most recent collection. This corresponds to the supervisor of the
tollbooth, emptying the cash box in the booth and resetting the meters.
Use the class names that you have defined for your implementations of the truck interface. Also, the
method names on your tollbooth may be called differently. You may also have different types of
constructors depending on how much initialization of variables you choose when instantiating a class.
Class TestTollBooth {
Public static void main(String [] args){
TollBooth booth = new AlleghenyTollBooth();
booth.calculateToll(ford);
booth.displayData();
booth.calculateToll(nissan);
}
}
*
**
***
****
*****
****
***
**
*