package lab03;

public class PeanutButter {
	private int jars;
	private int openJarServings;
	private static final int SERVINGS_PER_JAR = 9;
	
	public PeanutButter() {
		jars=0;
		openJarServings=0;
	}
	
	public boolean haveTwoServings() {
		return (openJarServings + (SERVINGS_PER_JAR * jars)) >= 2;
	}
	
	public void storeGroceries(int numPB) {
		jars +=numPB;
		if (jars>50) {
			System.out.println("Ran out of storage on the peanut butter shelf, " + 
					(jars-50) + " jars dropped and broke.");
			jars=50;
		}
	}
	
	public boolean getTwoServings() {
		while (openJarServings<2) {
			if (jars<=0) return false;
			openJarServings+=SERVINGS_PER_JAR;
			jars--;
		}
		openJarServings -=2;
		return true;
	}

	/**
	 * @return the jars
	 */
	public int getJars() { return jars; }
	
	
		

}
