Complete Aircraft Engine Simulation Code Listing


Running The Aircraft Engine Simulation Program

To run the aircraft engine simulation you’ll need to create a test driver program. My version of the test driver program is a class named EngineTester and is shown in example 10-8. The result of running this program is shown in figure 10-14.

image from book
Figure 10-14: Result of Running Example 10.8

Referring to example 10.8 — line 3 starts the program by creating an Engine object. As noted above this line kicks off the sequence of events illustrated in figure 10-13. All the Engine’s part objects are initially created with WORKING part status. The startEngine() method call on line 4 initiates a checkEngineStatus() method call. (Refer to the Engine class code listing in the next section.) If all goes well the engine reports that it is running.

On line 5 a fault is introduced to the engine’s compressor component. This causes the engine to shut down. Attempts on lines 6 and 7 to start the engine fail due to the failed compressor. When the compressor fault is removed the engine starts fine. This sequence of events can be traced through the source code and by carefully reading the program’s output shown in figure 10-14.

Quick Review

The Engine class is a composite aggregate. Its behavior is dictated by the behavior of its contained part class objects. Its part classes include Compressor, FuelPump, OilPump, OxygenSensor, and TemperatureSensor.

All the classes in the aircraft simulation use the functionality of the PartStatus class. The PartStatus class employs the typesafe enumeration design pattern. Use the typesafe enumeration pattern when you want the compiler to perform state-value assignment validation.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net