/* * Code by Curt Clifton, Rose-Hulman Institute of Technology. * April 29, 2009. * * Specification by YOUR_NAME_HERE. */ /** * This class models a lift. */ public class Lift { /* You don't need to specify anything about these constants. */ public static final int UP = 1; public static final int STOP = 0; public static final int DOWN = -1; /* TODO: add JML annotations to the instance fields */ private int location; private boolean[] floorRequestLight; private boolean upArrowLight; private boolean downArrowLight; private int nextDirection; private boolean doorsOpen; /* TODO: add a class invariant */ /* TODO: add a specification to this constructor */ public Lift(int numberOfFloors) { this.location = 0; this.floorRequestLight = new boolean[numberOfFloors]; this.upArrowLight = false; this.downArrowLight = false; this.nextDirection = STOP; this.doorsOpen = false; } /* TODO: add a specification to this method */ public void buttonPressed(int floor) { this.floorRequestLight[floor - 1] = true; } /* TODO: add a specification to this method */ public void movedUp() { this.location++; } /* TODO: add a specification to this method */ public void movedDown() { this.location--; } /* TODO: add a specification to this method */ public void doorsOpened(int newDirection) { this.doorsOpen = true; this.nextDirection = newDirection; if (newDirection == UP) { this.upArrowLight = true; this.downArrowLight = false; } else if (newDirection == DOWN) { this.downArrowLight = true; this.upArrowLight = false; } else { this.downArrowLight = false; this.upArrowLight = false; } this.floorRequestLight[this.location] = false; } /* TODO: add a specification to this method */ public void doorsClosed() { this.doorsOpen = false; this.downArrowLight = false; this.upArrowLight = false; } /* TODO: add a specification to this method */ public int getFloor() { return this.location + 1; } /* TODO: add a specification to this method */ public boolean isFloorRequestLit(int floor) { return this.floorRequestLight[floor - 1]; } /* TODO: add a specification to this method */ public boolean isDownArrowLit() { return this.downArrowLight; } /* TODO: add a specification to this method */ public boolean isUpArrowLit() { return this.upArrowLight; } }