Ipower web hosting - Appendix H Elevator Model (on CD) 1435 267
Friday, November 30th, 2007Appendix H Elevator Model (on CD) 1435 267 break; 269 default: 270 break; 271 } 272 } // end method sendPersonMoveEvent 273 } Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 7 of 7). Class Personis subclass of class Thread. The Personperforms all actions, such as walking across Floors and riding the Elevator, in method run (lines 101 172). Method run represents the lifetime of a Person described in the sequence diagram of Fig. 15.20. Class Personcontains a PersonMoveListenerobject (line 23) to which the Personsends PersonMoveEvents. In our simulation, the ElevatorModeluses method setPersonMoveListener (lines 50 54) to register itself as the Person- MoveListener. The ElevatorModel, upon receiving a PersonMoveEvent, sends the event to the ElevatorView therefore, the ElevatorView knows when a Personhas performed certain actions discussed momentarily. There are several types of actions a Person performs in its lifetime, so there exists several types of PersonMoveEvents that a Person may send to the person- MoveListener. Lines 32 37 define a series of constants in which each constant represents a unique type of PersonMoveEvent. The Person sends events to personMoveListenerwhen the Personhas been created the Personarrives at the Elevator the Personenters the Elevator the Personpresses a Button(either in the Elevatoror on a Floor) the Personexits the Elevator the Personexits the simulation When the Person decides to send an event to its PersonMoveListener, the Personcalls privatemethod sendPersonMoveEventand passes the desired constant as a parameter. This method sends the event associated with the constant. For example, line 124 calls sendPersonMoveEvent( PERSON_PRESSED_BUTTON ); when the Person presses a Button on a Floor. In method run, the Person walks to the Elevator, then sends a personArrivedevent upon arrival at the Elevator. We use the activity diagram of Fig. 5.29 to determine the Person s next action. If the Door on the Floor is closed (line 121), the Person must wait for that Door to open. Specifically, line 128 registers the Person as a DoorListener for that Door, and lines 131 132 allow the Personto press the Buttonon that Floor. The Person waits for the Door to open by calling method sleep (line 135) of the Person s superclass Thread. When the Door opens, that Door informs Person in doorOpened
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.