class Vehicle {
    private long VIN;
    private EnergySource source;	// energy source used by this
    private running;			// vehicle is running
    private String ownerName = "<unknown owner>";
    private float speed = 0;
    private float direction = 0;

    public static long nextVIN = 0;

    // ...

    public Vehicle(String name, EnergySource source) {
	this(name);
	this.source = source;
    }

    public boolean start() {
	if (!running && !source.empty())
	    running = true;
	return running;
    }

    // ...
}


abstract class EnergySource {

    public abstract boolean empty();

    // ...
}


class GasTank extends EnergySource {

    private int capacity;	// how many gallons this tank can hold
    private int current;	// how many gallons this tank is holding

    public GasTank(int capacity) {
	this.capacity = capacity;
    }

    public boolean empty() {
	return current == 0;
    }

    public int howMuchGas() {
	return current;
    }

    public int howMuchRoom() {
	return capacity - current;
    }

    public void add(int gallons) {
	current += gallons;
    }

    public void burn(int gallons) {
	current -= gallons;
    }

    // ...
}


class Battery extends EnergySource {

    static final int MAX_CHARGE = 1000;		// maximum battery charge

    private int charge;				// curent battery charge

    public Battery(int initialCharge) {
	charge = initialCharge;
    }

    public boolean empty() {
	return charge == 0;
    }

    public int drain(int desired) {
	if (desired <= charge) {
	    charge -= desired;
	    return desired;
	} else {
	    int left = charge;
	    charge = 0;
	    return left;
	}
    }

    public void recharge(int amount) {
	charge = Math.min(charge + amount, MAX_CHARGE);
    }

    // ...
}
