package SimkitOpenDis7Examples;

import simkit.Entity;

/**
 * Model a ship that arrives at a pier for crane servicing
 * @author abuss@nps.edu
 */
public class Ship extends Entity {

    /**
     * Remaining time to unload ship at unit rate
     */
    protected double remainingUnloadingTime;

    /**
     * Model constructor
     * @throws IllegalArgumentException if remainingUnloadingTime ≤ 0.0
     * @param remainingUnloadingTime Given initial unloading time
     */
    public Ship(double remainingUnloadingTime) {
        super("Ship");
        if (remainingUnloadingTime <= 0.0) {
            throw new IllegalArgumentException(
                    "remainingUnloadingTime must be > 0.0: "
                    + remainingUnloadingTime);
        }
        this.remainingUnloadingTime = remainingUnloadingTime;
    }

    /**
     * Decrement remainingUnloadingTime by the elapsed time at the given rate
     *
     * @param rate Given rate of unloading
     */
    public void work(double rate) {
        remainingUnloadingTime -= getElapsedTime() * rate;
    }

    /**
     * accessor method to get a state variable
     * @return The remainingUnloadingTime
     */
    public double getRemainingUnloadingTime() {
        return remainingUnloadingTime;
    }

    @Override
    public String toString() {
        return super.toString() + String.format(" %.3f", getRemainingUnloadingTime());
    }
}