        // A customer of the gas station.
class Driver {
    public Driver(GasStation s){
        station = s;
    }

        // Try to fill up. Return how much can be delivered.
    public long fillUp() throws Pump.FuelTypeNotAvailable {
        Pump p = getPump();
        return p.deliver(getFuelType(),getAmount());
    }

    public GasStation getStation(){
        return station;
    }

    public void addEvent(Event e){
        getEventList().add(e);
    }

        // A free pump has been found. Delivery is about to start.
    public void setPump(Pump p){
        pump = p;
    }

        // A free cashier has been found. Payment is about to start.
    public void setCashier(Cashier c){
        cashier = c;
    }

    public FuelType getFuelType(){
        return fuelType;
    }

    public PaymentMethod getPaymentMethod(){
        return payment;
    }

    public Event[] getEvents(){
        // Return the queue of events into an array for calculation
        // of statistics.
        Queue eventQueue = getEventList();
        Event[] events = new Event[eventQueue.size()];
        eventQueue.toArray(events);
        return events;
    }

    public long getAmount(){
        return amount;
    }

    public Pump getPump(){
        return pump;
    }

    public Cashier getCashier(){
        return cashier;
    }

    protected Queue getEventList(){
        return eventList;
    }

    // Have access to a FuelFactory, for generating random
    // instances of a FuelType. This is a singleton so may be
    // shared by all Drivers.
    private static final FuelFactory fuelFactory = FuelFactory.getInstance();
    // Request a random fuel type.
    private final FuelType fuelType = fuelFactory.randomFuelType();
    // Request a random amount of fuel.
    private final long amount = fuelType.randomAmount();
    // Obtain a random payment method from the singleton
    // payment factory method.
    private final PaymentMethod payment =
                PaymentFactory.getInstance().randomPaymentMethod();

    private final GasStation station;
    // The pump and cashier will be allocated when free.
    private Pump pump = null;
    private Cashier cashier = null;
    // Keep track of the events that occurred for this driver.
    private Queue eventList = new Queue();
}
