Shared web hosting - 1430 Elevator Model (on CD) Appendix H 7
1430 Elevator Model (on CD) Appendix H 7 8 // Deitel packages 9 import com.deitel.jhtp4.elevator.event.*; 10 11 public class Person extends Thread implements DoorListener { 12 13 // identification number 14 private int ID = -1; 15 16 // represents whether Person is moving or waiting 17 private boolean moving; 18 19 // reference to Location (either on Floor or in Elevator) 20 private Location location; 21 22 // listener object for PersonMoveEvents 23 private PersonMoveListener personMoveListener; 24 25 // time in milliseconds to walk to Button on Floor 26 private static final int TIME_TO_WALK = 3000; 27 28 // maximum time Person will wait for Elevator (10 minutes) 29 private static final int TIME_WAITING = 10 * 60 * 1000; 30 31 // types of messages Person may send 32 public static final int PERSON_CREATED = 1; 33 public static final int PERSON_ARRIVED = 2; 34 public static final int PERSON_ENTERING_ELEVATOR = 3; 35 public static final int PERSON_PRESSING_BUTTON = 4; 36 public static final int PERSON_EXITING_ELEVATOR = 5; 37 public static final int PERSON_EXITED = 6; 38 39 // Person constructor set initial location 40 public Person( int identifier, Location initialLocation ) 41 { 42 super(); 43 44 ID = identifier; // assign unique identifier 45 location = initialLocation; // set Floor Location 46 moving = true; // start moving toward Button on Floor 47 } 48 49 // set listener for PersonMoveEvents 50 public void setPersonMoveListener( 51 PersonMoveListener listener ) 52 { 53 personMoveListener = listener; 54 } 55 56 // invoked when Door has opened 57 public void doorOpened( DoorEvent doorEvent ) 58 { Fig. H.13 Class Personrepresents the Personthat rides the Elevator. The Personoperates asynchronously with other objects (part 2 of 7).
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.