FileDocCategorySizeDatePackage
BuildingManagement.javaAPI DocExample1267Sat Apr 28 10:22:46 BST 2001None

BuildingManagement

public class BuildingManagement extends Object
BuildingManagement - control an energy-saving building. This class shows how we might control the objects in an office that can safely be powered off at nighttime to save energy - lots of it, when applied to a large office!

Fields Summary
Asset[]
things
int
numItems
Constructors Summary
Methods Summary
public voidadd(Asset thing)
Add a Asset to this building

	
		System.out.println("Adding " + thing);
		things[numItems++] = thing;
	
public voidgoodNight()
goodNight is called from a timer Thread at 2200, or when we get the "shutdown" command from the security guard.


	                    	 
	   
		for (int i=0; i<things.length; i++)
			if (things[i] instanceof PowerSwitchable)
				((PowerSwitchable)things[i]).powerDown();
	
public static voidmain(java.lang.String[] av)
The main program

		BuildingManagement b1 = new BuildingManagement();
		b1.add(new RoomLights(101));	// control lights in room 101
		b1.add(new EmergencyLight(101));	// and emerg. lights.
		// add the computer on desk#4 in room 101
		b1.add(new ComputerCPU(10104));
		// and its monitor
		b1.add(new ComputerMonitor(10104));

		// time passes, and the sun sets...
		b1.goodNight();