All pastes #424088 Raw Edit

Myst/Elevator

public java v1 · immutable
·published 2007-04-04 15:55 UTC
rendered paste body
/*          Problem Statement   This class simulates an elevator in an eight story building.     Its state is the number of the current floor and the number of persons       currently on the elevator.   Its behavior includes the ability to move to a given floor and to load and       unload passengers.*/public class Elevator {  private int initialFloorNum;    private int initialLoad;    private int currentFloor;    private int currentLoad;      //-------------------------------------------------------------------------  //  Constructor: Sets the initial floor and number of occupants of the  //  elevator.  //-------------------------------------------------------------------------  public Elevator( int initialFloorNum, int initialLoad )    {       initialFloorNum = 1;     initialLoad = 0;  }     //-------------------------------------------------------------------------  //  Move the elevator to the specified floor.  //-------------------------------------------------------------------------      public void toFloor( int floorNum )  {      currentFloor = floorNum;  }        //-------------------------------------------------------------------------  //  Load additional persons onto the elevator.  //-------------------------------------------------------------------------  public void load( int numPersons )  {      currentLoad = initialLoad + numPersons;  }    //-------------------------------------------------------------------------  //  Unload persons from the elevator.  //-------------------------------------------------------------------------  public void unload( int numPersons )  {      currentLoad = currentLoad - numPersons;  }    //-------------------------------------------------------------------------  //  Return the number of the current floor.  //-------------------------------------------------------------------------  public int currentFloor()  {      return currentFloor;    }    //-------------------------------------------------------------------------  //  Return the number of passengers currently on the elevator.  //-------------------------------------------------------------------------  public int currentLoad()  {          return currentLoad;  }    //-------------------------------------------------------------------------  //  Return the current load and floor of the elevator.  //-------------------------------------------------------------------------  public String toString()  {      String result = ("Current load is: " + Integer.toString(currentLoad)                       + "  Current floor is: "+Integer.toString(currentFloor));      return result;  }          }