/****************************************************
 Program:          Die Hard III Water Jug Puzzle

 Author:           Mark Rich
 Collaborators:    Mike Wade

 Completion Date:  2/11/2000
 Updated:          2/8/2001

 Course:           CS 302

 Platform:         Unix
*****************************************************/

/**
 * You have two jugs, A and B, and an infinite supply of water. There are 
 * three types of actions that you can use: (1) you can fill a jug, (2) you 
 * can empty a jug, and (3) you can pour from one jug to the other. 
 * Pouring from one jug to the other stops when the first jug is empty 
 * or the second jug is full, whichever comes first. For example, if A 
 * has 5 gallons and B has 6 gallons and a capacity of 8, then pouring 
 * from A to B leaves B full and 3 gallons in A. 
 *
 * Bugs: None known
 **/
class DieHardIII {
    
    /**
     * For this particular implementation, we will assume we have two
     * jugs, one holding three gallons, one holding four gallons.  Our
     * goal is to get 2 gallons of water into the four gallon WaterJug.
     **/
    public static void main (String[] args) {
	
	final int CAPACITY_A = 4,    // constants for the capacity  
	          CAPACITY_B = 3;    // of WaterJug a and b

	// Create the two Jugs with capacities CAPACITY_A and CAPACITY_B
	// as well as a temporary variable to keep track of the overflow
	WaterJug a = new WaterJug(CAPACITY_A);
	WaterJug b = new WaterJug(CAPACITY_B);

	System.out.println("WaterJug A:");
	a.print();
	System.out.println("WaterJug B:");
	b.print();
	
	System.out.println("Filling up A..");

	a.fill(CAPACITY_A);

	System.out.print("A = " + a.getContents() + "\t");
	System.out.println("B = " + b.getContents() + "\n");
      	System.out.println("Pouring from A to B..");

	a.fill(b.fill(a.empty()));

	System.out.print("A = " + a.getContents() + "\t");
	System.out.println("B = " + b.getContents() + "\n");
	System.out.println("Emptying B..");

	b.empty();

	System.out.print("A = " + a.getContents() + "\t");
	System.out.println("B = " + b.getContents() + "\n");
	System.out.println("Pouring from A to B..");

	b.fill(a.empty());

	System.out.print("A = " + a.getContents() + "\t");
	System.out.println("B = " + b.getContents() + "\n");
	System.out.println("Filling up A..");

	a.fill(CAPACITY_A);

	System.out.print("A = " + a.getContents() + "\t");
	System.out.println("B = " + b.getContents() + "\n");
	System.out.println("Pouring from A to B..");

	a.fill(b.fill(a.empty()));

	System.out.print("A = " + a.getContents() + "\t");
	System.out.println("B = " + b.getContents() + "\n");

    }
}





