/*******************************************************************************
Author:				Rebecca Hasti, hasti@cs.wisc.edu
					copyright 2000, all rights reserved
Course:				CS 302, Summer 2000

Compiler:			Metrowerks CodeWarrior (JDK 1.2)
Platform:			Windows NT 4.0 (or Windows 95)
*******************************************************************************/

/**
 * Represents a mug.  A mug has a fixed capacity and can be filled with an
 * amount of liquid (the capacity and amount the mug is currently filled must
 * be integers).
 *
 * Bugs:	none known
 **/
class SimpleMug {

	////////////////////////////////////////
	// Data Members
	////////////////////////////////////////
	
	private int capacity;		// the capacity of the mug (in ounces)
	private int currentVolume;	// the current amount of liquid in the mug
	
	////////////////////////////////////////
	// Constructors
	////////////////////////////////////////
	
	/**
	 * Creates an empty mug with the given capacity.
	 * Note: it is assumed that the capacity given is greater than zero (0).
	 * @param initCapacity the capacity of the mug (in ounces)
	 **/
	public SimpleMug(int initCapacity) {
		capacity = initCapacity;
		currentVolume = 0;
	}
	
	////////////////////////////////////////
	// Public Methods
	////////////////////////////////////////
	
	/**
	 * Returns the capacity of the mug.
	 * @return mug's capacity
	 **/
	public int getCapacity() {
		return capacity;
	}
	
	/**
	 * Returns the current volume of liquid in the mug.
	 * @return mug's current volume of liquid
	 **/
	public int getCurrentVolume() {
		return currentVolume;
	}	
	
	/**
	 * Fills the mug with the given amount of liquid.  If adding the amount of
	 * liquid causes the mug to overflow, the amount of overflow is returned; 
	 * otherwise, 0 is returned.
	 * @param amount the amount of liquid to add to the mug (assumed to be >= 0)
	 * @return the amount of overflow
	 **/
	public int fill(int amount) {
		int newVolume, overflow;
		
		newVolume = currentVolume + amount;
		overflow = Math.max(newVolume - capacity, 0);
		currentVolume = Math.min(newVolume, capacity);
		return overflow;
	}

	/**
	 * Pours the given amount of liquid out of the mug.  The actual amount that 
	 * is poured out is returned.  Note: the actual amount may be different from
	 * the amount passed in to the method since the mug may not currently be
	 * filled with enough liquid to pour out the amount requested.
	 * @param amount the amount of liquid to pour out of the mug 
	 *               (assumed to be >= 0)
	 * @return the amount actually poured out
	 **/
	public int pour(int amount) {
		int newVolume, actualAmount;
		
		newVolume = currentVolume - amount;
		actualAmount = Math.min(currentVolume, amount);
		currentVolume = Math.max(0, newVolume);
		return actualAmount;
	}

}

