Web hosting billing - 1420 Elevator Model (on CD) Appendix H According
1420 Elevator Model (on CD) Appendix H According to Fig. 15.21, class Bell does not contain attributes, because the Bell does not change state. However, Fig. 15.21 specifies that class Bell contains method ringBell (lines 14 19), which rings the Bell by invoking method bellRang of the BellListener bellListener (line 11). In our simulation, the Elevator is the bellListener the Elevatorreceives event from the Bell, then sends the event to the ElevatorShaft, which sends the event to the ElevatorModel, which sends the event to the ElevatorView. The ElevatorView then plays an audio clip of a bell ringing. The Elevator uses method setBellListener (lines 22 24) to register for BellEvents from the Bell. According to Fig. H.2, class Bellimplements interface ElevatorMoveListener. Line 28 and lines 31 34 list methods elevatorDeparted and elevatorArrived, respectively. In our simulation, the Bellrings when the Elevatorhas arrived. H.8 Class Elevator Class Elevator (Fig. H.12) represents the elevator car that travels between the two Floors in the ElevatorShaftwhile carrying a Person. According to the class diagram of Fig. 15.21, class Elevator contains one object each of classes Button, Door and Bell lines 37 39 declare objects elevatorButton, elevatorDoor and bell. As discussed in Section 9.23, class Elevatorextends superclass Location, because the Elevatoris a location that the Personcan occupy. Class Elevatorimplements methods getButton (lines 232 235) and getDoor(lines 238 241) provided by class Location. Method getButton returns the elevatorButton and method getDoor returns the elevatorDoor. According to Fig. 15.21, we also must include two Location objects one named currentFloor (line 22), which represents the current Floor being serviced, and the other named destinationFloor (line 25), which represents the Floor at which the Elevator will arrive. In addition, Fig. 15.21 specifies that class Elevator requires booleanvariable moving(line 19), which describes whether the Elevator is moving or idle, and boolean variable summoned (line 28), which describes whether the Elevatorhas been summoned. Also, class Elevatoruses intconstant TRAVEL_TIME(line 44), which indicates the five second travel time between Floors. 1 // Elevator.java 2 // Travels between Floors in the ElevatorShaft 3 package com.deitel.jhtp4.elevator.model; 4 5 // Java core packages 6 import java.util.*; 7 8 // Deitel packages 9 import com.deitel.jhtp4.elevator.event.*; 10 import com.deitel.jhtp4.elevator.ElevatorConstants; 11 12 public class Elevator extends Location implements Runnable, 13 BellListener, ElevatorConstants { Fig. H.12 Class Elevatorrepresents the Elevatortraveling between two Floors, operating asynchronously with other objects (part 1 of 9).
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.