/* 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 floorNum; private int load; private int currentFloor; private int currentLoad; //------------------------------------------------------------------------- // Constructor: Sets the initial floor and number of occupants of the // elevator. //------------------------------------------------------------------------- public Elevator( int initialFloorNum, int initialLoad ) { floorNum = initialFloorNum; currentLoad = initialLoad; } //------------------------------------------------------------------------- // 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 = currentLoad + 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 toString = ("Current load is: " + Integer.toString(currentLoad) + " Current floor is: "+Integer.toString(currentFloor)); return toString; } }