Follow these steps to implement the example:
- Create a class named ParkingCounter and specify that it extends the AtomicInteger class:
public class ParkingCounter extends AtomicInteger {
- Declare a private int attribute named maxNumber to store the maximum number of cars admitted into the parking lot:
private final int maxNumber;
- Implement the constructor of the class to initialize its attributes:
public ParkingCounter(int maxNumber){ set(0); this.maxNumber=maxNumber; }
- Implement the carIn() method. This method increments the counter of cars if it has a value smaller than the established maximum value. Construct an infinite loop and get the value of the internal counter using the get() method:
public boolean ...