models
Class StupidController

java.lang.Object
  extended by models.StupidController
All Implemented Interfaces:
ControllerForElevator
Direct Known Subclasses:
ImprovedStupidController

public class StupidController
extends java.lang.Object
implements ControllerForElevator

The stupid controller ensures that the elevator moves from bottom to top to bottom ... stopping at every floor.

Version:
1
Author:
J Paul Gibson

Constructor Summary
StupidController(ElevatorForController elevator)
           
 
Method Summary
 void bindToElevator(ElevatorForController elevator)
          Ensure that the controller is controlling only a single elevator
 Direction calculateDirection()
          If the elevator is on the top floor then set the direction to down
If the elevator is on the bottom floor then set the direction to up
If the elevator is moving up then keep moving up until it reaches the top floor
If the elevator is moving down then keep moving down until it reaches the top floor
If the elevator is not moving then start it moving down towards the bottom floor
 boolean stopAtNextFloor()
          Always stop at the next floor
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StupidController

public StupidController(ElevatorForController elevator)
                 throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException
Method Detail

bindToElevator

public void bindToElevator(ElevatorForController elevator)
                    throws java.lang.IllegalArgumentException
Description copied from interface: ControllerForElevator
Ensure that the controller is controlling only a single elevator

Specified by:
bindToElevator in interface ControllerForElevator
Parameters:
elevator - is the unique elevator to which the controller is now connected
Throws:
java.lang.IllegalArgumentException - if the elevator being connected is null

calculateDirection

public Direction calculateDirection()
If the elevator is on the top floor then set the direction to down
If the elevator is on the bottom floor then set the direction to up
If the elevator is moving up then keep moving up until it reaches the top floor
If the elevator is moving down then keep moving down until it reaches the top floor
If the elevator is not moving then start it moving down towards the bottom floor

Specified by:
calculateDirection in interface ControllerForElevator
Returns:
the direction in which the lift should next move

stopAtNextFloor

public boolean stopAtNextFloor()
Always stop at the next floor

Specified by:
stopAtNextFloor in interface ControllerForElevator
Returns:
whether the lift should stop at the next floor after it has completed its move

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object