55 lines
1.3 KiB
Java
55 lines
1.3 KiB
Java
// innerclasses/GreenhouseController.java
|
|
// (c)2020 MindView LLC: see Copyright.txt
|
|
// We make no guarantees that this code is fit for any purpose.
|
|
// Visit http://OnJava8.com for more book information.
|
|
// Configure and execute the greenhouse system
|
|
import innerclasses.controller.*;
|
|
|
|
public class GreenhouseController {
|
|
public static void main(String[] args) {
|
|
GreenhouseControls gc = new GreenhouseControls();
|
|
// Instead of using code, you could parse
|
|
// configuration information from a text file:
|
|
gc.addEvent(gc.new Bell(900));
|
|
Event[] eventList = {
|
|
gc.new ThermostatNight(0),
|
|
gc.new LightOn(200),
|
|
gc.new LightOff(400),
|
|
gc.new WaterOn(600),
|
|
gc.new WaterOff(800),
|
|
gc.new ThermostatDay(1400)
|
|
};
|
|
gc.addEvent(gc.new Restart(2000, eventList));
|
|
gc.addEvent(
|
|
new GreenhouseControls.Terminate(5000));
|
|
gc.run();
|
|
}
|
|
}
|
|
/* Output:
|
|
Thermostat on night setting
|
|
Light is on
|
|
Light is off
|
|
Greenhouse water is on
|
|
Greenhouse water is off
|
|
Bing!
|
|
Thermostat on day setting
|
|
Bing!
|
|
Restarting system
|
|
Thermostat on night setting
|
|
Light is on
|
|
Light is off
|
|
Greenhouse water is on
|
|
Bing!
|
|
Greenhouse water is off
|
|
Thermostat on day setting
|
|
Bing!
|
|
Restarting system
|
|
Thermostat on night setting
|
|
Light is on
|
|
Light is off
|
|
Bing!
|
|
Greenhouse water is on
|
|
Greenhouse water is off
|
|
Terminating
|
|
*/
|