oop-labs-collection/labs/6/Vent.java

34 lines
862 B
Java
Raw Normal View History

public class Vent extends Appliance {
private float maxPower = 90.0f;
private float rpm = 0.0f;
private final float rotorInertia = 7.0f;
private final float maxRPM = 6500.0f;
public Vent(boolean plugged) {
super(plugged);
}
public void step(float seconds) {
// electric current usage
if (super.getPowerState()) {
rpm += max(min(((int) (maxRPM - rpm) * rotorInertia), maxPower), 0)
* 10 / rotorInertia * seconds;
}
// air drag (always present)
rpm -= (rpm / 200) / rotorInertia;
}
public float getPowerConsumption() {
if (super.getPowerState()) {
return max(min(rotorInertia*(maxRPM - rpm), maxPower), 0);
} else {
return 0f;
}
}
public float getRPM() {
return rpm;
}
}