124 lines
3.5 KiB
Java
124 lines
3.5 KiB
Java
/*
|
|
* %W% %E% Dymik739
|
|
* Email: dymik739@109.86.70.81
|
|
*
|
|
* Copyright (C) 2023 FIOT Dev Team
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
/**
|
|
* Class which represents the behaviour of a dishwasher.
|
|
*
|
|
* @author Dymik739
|
|
* @since 0.3
|
|
*/
|
|
public class Dishwasher extends Appliance {
|
|
/** Defines power usage at different stages of washing dishes. */
|
|
private float[] powerStates = {400f, 60f, 130f, 350f};
|
|
|
|
/** Shows how much time should pass before switching to the next stage */
|
|
private float nextPowerStateIn = 20f;
|
|
|
|
/** Shows current stage the dishwasher is performing, -1 for none */
|
|
private int currentState = -1;
|
|
|
|
/**
|
|
* Constructor for this class.
|
|
*
|
|
* @param plugged sets the starting power state of this device
|
|
*/
|
|
public Dishwasher(boolean plugged) {
|
|
super(plugged);
|
|
super.setType("Dishwasher");
|
|
}
|
|
|
|
/**
|
|
* Method for simulating the devices' behaviour.
|
|
* Once started, it goes through every stage until it finishes washing
|
|
* the dishes (every stage has it's own power usage level. After that,
|
|
* it resets the device and turns it off automatically.
|
|
*
|
|
* @param seconds delta time to simulate for
|
|
* @param ventRPM air flow created by the vent
|
|
*/
|
|
public void step(float seconds, float ventRPM) {
|
|
if (!super.getPowerState()) {
|
|
return;
|
|
}
|
|
|
|
nextPowerStateIn -= seconds;
|
|
|
|
if (nextPowerStateIn <= 0) {
|
|
nextPowerStateIn += 20f;
|
|
currentState++;
|
|
}
|
|
|
|
if (currentState > 3) {
|
|
unplug();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Overridden method for turning on this device.
|
|
* It automatically sets it to the correct stage and delay.
|
|
*/
|
|
@Override
|
|
public void plug() {
|
|
super.plug();
|
|
|
|
currentState = 0;
|
|
nextPowerStateIn = 20f;
|
|
}
|
|
|
|
/**
|
|
* Overridden method for turning this device off.
|
|
* It automatically resets the current washing stage to -1.
|
|
*/
|
|
@Override
|
|
public void unplug() {
|
|
super.unplug();
|
|
|
|
currentState = -1;
|
|
}
|
|
|
|
/**
|
|
* Method for calculating the power consumption of this device.
|
|
* Power usage depends on the current washing stage.
|
|
*
|
|
* @return float showing current power consumption
|
|
*/
|
|
public float getPowerConsumption() {
|
|
if (super.getPowerState()) {
|
|
return powerStates[currentState];
|
|
} else {
|
|
return 0f;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Method for printing this devices' object in a nice way.
|
|
*
|
|
* @return String containing text description of this devices' state
|
|
*/
|
|
@Override
|
|
public String toString() {
|
|
return String.format("Dishwasher(%s, %4.1fW, %2.1fs)",
|
|
super.getPowerState() ? "on" : "off", getPowerConsumption(),
|
|
super.getPowerState()
|
|
? (3 - currentState) * 20 + nextPowerStateIn
|
|
: 0f);
|
|
}
|
|
}
|