public class Dishwasher extends Appliance { private float basePower = 160.0f; private float[] powerStates = {400f, 60f, 130f, 350f}; private float nextPowerStateIn = 20f; private int currentState = -1; public Dishwasher(boolean plugged) { super(plugged); } public void step(float seconds, float ventRPM) { if (!super.getPowerState()) { return; } nextPowerStateIn -= seconds; if (nextPowerStateIn <= 0) { nextPowerStateIn += 20f; currentState++; } if (currentState > 3) { unplug(); } } @Override public void plug() { super.plug(); currentState = 0; nextPowerStateIn = 20f; } @Override public void unplug() { super.unplug(); currentState = -1; } public float getPowerConsumption() { if (super.getPowerState()) { return powerStates[currentState]; } else { return 0f; } } }