OnJava8-Examples/innerclasses/GreenhouseController.java

58 lines
1.4 KiB
Java
Raw Normal View History

2015-09-07 11:44:36 -06:00
// innerclasses/GreenhouseController.java
2015-12-15 11:47:04 -08:00
// (c)2016 MindView LLC: see Copyright.txt
2015-11-15 15:51:35 -08:00
// We make no guarantees that this code is fit for any purpose.
// Visit http://mindviewinc.com/Books/OnJava/ for more book information.
2016-01-25 18:05:55 -08:00
// Configure and execute the greenhouse system
2015-06-15 17:47:35 -07:00
// {Args: 5000}
import innerclasses.controller.*;
public class GreenhouseController {
public static void main(String[] args) {
GreenhouseControls gc = new GreenhouseControls();
2016-01-25 18:05:55 -08:00
// Instead of using code, you could parse
// configuration information from a text file:
2015-06-15 17:47:35 -07:00
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));
if(args.length == 1)
gc.addEvent(
new GreenhouseControls.Terminate(
new Integer(args[0])));
gc.run();
}
2015-09-07 11:44:36 -06:00
}
/* Output:
2016-07-22 14:45:35 -06:00
Thermostat on night setting
Light is on
Light is off
Greenhouse water is on
Greenhouse water is off
Bing!
Thermostat on day setting
2015-06-15 17:47:35 -07:00
Bing!
2016-07-22 14:45:35 -06:00
Restarting system
2015-06-15 17:47:35 -07:00
Thermostat on night setting
Light is on
Light is off
Greenhouse water is on
2016-07-22 14:45:35 -06:00
Bing!
2015-06-15 17:47:35 -07:00
Greenhouse water is off
Thermostat on day setting
2016-07-22 14:45:35 -06:00
Bing!
2015-06-15 17:47:35 -07:00
Restarting system
2016-07-22 14:45:35 -06:00
Thermostat on night setting
Light is on
Light is off
Bing!
Greenhouse water is on
Greenhouse water is off
2015-06-15 17:47:35 -07:00
Terminating
2015-09-07 11:44:36 -06:00
*/