waterjug
Class WaterJugProblem

java.lang.Object
  extended by framework.Problem
      extended by waterjug.WaterJugProblem

public class WaterJugProblem
extends Problem

This class represents the Water Jug problem. It provides an introductory message describing the problem, stores the problem's possible moves and current state, and checks for whether the problem has been successfully solved. Note that this class extends the abstract class Problem and therefore imports framework.Problem. This class inherits the setIntroduction(), setCurrentState(), and setMoves() methods from its parent and thus it should not have any instance fields for these attributes.


Constructor Summary
WaterJugProblem()
          Constructs a new water jug problem object.
 
Method Summary
 boolean success()
          Returns whether the current state of this problem is a success.
 
Methods inherited from class framework.Problem
getCurrentState, getIntroduction, getMoves, setCurrentState, setIntroduction, setMoves
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WaterJugProblem

public WaterJugProblem()
Constructs a new water jug problem object. A new water jug state object should be constructed with zero gallons in both jugs. This state should be set as the current state of the problem using the inherited setCurrentState() method. The six valid water jug moves should be created and stored on a list using the inherited setMoves() method. The appropriate introduction string for this problem should be stored using the inherited setIntroduction().

Method Detail

success

public boolean success()
Returns whether the current state of this problem is a success. Note that this method implements the abstract success method declared in the parent. Note also that the current state of the problem must be gotten using the inherited getCurrentState() method. Since that method returns a value of type State, it must be cast to WaterJugState before processing. The current state is a success if either jug has 2 gallons.

Specified by:
success in class Problem
Returns:
true if the current state is a success, false otherwise