Follow these steps to implement the example:
- First, create the application without using any synchronization mechanism. Create a class named ParkingCash with an internal constant and an attribute to store the total amount of money earned by providing this parking service:
public class ParkingCash { private static final int cost=2; private long cash; public ParkingCash() { cash=0; }
- Implement a method named vehiclePay() that will be called when a vehicle (a car or motorcycle) leaves the parking area. It will increase the cash attribute:
public void vehiclePay() { cash+=cost; }
- Finally, implement a method named close() that will write the value of the cash attribute in the console and reinitialize it to zero: ...