waterjug
Class WaterJugMove

java.lang.Object
  extended by framework.Move
      extended by waterjug.WaterJugMove

public class WaterJugMove
extends Move

This class represents moves in the Water Jug problem. A move object stores its move name and knows how to apply itself to a water jug state to create a new state representing the result of the move. Note that this class extends the abstract class Move and therefore imports framework.Move. This class inherits the getMoveName() method from its parent and thus it should not have an instance field for the move name.


Constructor Summary
WaterJugMove(java.lang.String moveName)
          Constructs a new water jug move object.
 
Method Summary
 State doMove(State otherState)
          Attempts to perform this move on a given water jug state.
 
Methods inherited from class framework.Move
getMoveName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaterJugMove

public WaterJugMove(java.lang.String moveName)
Constructs a new water jug move object. Note that the move name is passed to the parent constructor using super.

Parameters:
moveName - the name of this move. It is an error if the name is not one of the following:
  • "Fill Jug X"
  • "Fill Jug Y"
  • "Empty Jug X"
  • "Empty Jug Y"
  • "Transfer Jug X to Jug Y"
  • "Transfer Jug Y to Jug X"
Method Detail

doMove

public State doMove(State otherState)
Attempts to perform this move on a given water jug state. Note that this method implements the abstract doMove method declared in the parent. Thus the argument of type State must be cast to type WaterJugState before processing. The move to perform is determined by this object's move name. If the move can be performed a new water jug state object is returned that reflects this move. A move cannot be performed if trying to fill or transfer to an already full jug, or if trying to empty or transfer from an empty jug. If the move cannot be performed null is returned.

Specified by:
doMove in class Move
Parameters:
otherState - the water jug state on which this move is to be performed
Returns:
a new water jug state reflecting the move, or null if it cannot be performed