package lab03;

public class Jelly {
	private int jars;
	private int openJarServings;
	private static final int SERVINGS_PER_JAR = 14;

	public Jelly() {
		jars=0;
		openJarServings=0;
	}
	
	public boolean haveServing() {
		return (openJarServings + (SERVINGS_PER_JAR * jars)) >= 1;
	}
	
	public void storeGroceries(int numJelly) {
		jars +=numJelly;
		if (jars>75) {
			System.out.println("Ran out of storage on the jelly shelf, " + 
					(jars-75) + " jars dropped and broke.");
			jars=50;
		}
	}
	
	public boolean getServing() {
		while (openJarServings<1) {
			if (jars<=0) return false;
			openJarServings+=SERVINGS_PER_JAR;
			jars--;
		}
		openJarServings --;
		return true;
	}

	/**
	 * @return the jars
	 */
	public int getJars() { return jars; }
	
	
}
