package lab03;

public class Kitchen {
	private int sandwichesServed;
	private int sandwichesRefused;
	private Bread bread;
	private PeanutButter pb;
	private Jelly jelly;
	private Budget budget;
	private int numJarsPB;
	private int numJarsJelly;
	private int numLoaves;
	boolean moreBread,morePB,moreJ;


	public Kitchen() {
		bread = new Bread();
		pb = new PeanutButter();
		jelly = new Jelly();
		budget=new Budget();
		numJarsPB=3;
		numJarsJelly=4;
		numLoaves=1;
		moreBread=morePB=moreJ=false;
		orderSupplies();
	}

	public void orderSupplies() {
		/* if (getCustomerSatisfaction()<0.8) {
			if (moreBread) numLoaves++;
			if (morePB) numJarsPB++;
			if (moreJ) numJarsJelly++;
		}
		if (bread.getLoaves()<numLoaves)
			budget.orderBread(numLoaves - bread.getLoaves(),bread);
		if (pb.getJars()<numJarsPB)
			budget.orderPeanutButter(numJarsPB - pb.getJars(),pb);
		if (jelly.getJars()<numJarsJelly)
			budget.orderJelly(numJarsJelly - jelly.getJars(),jelly);

		moreBread=morePB=moreJ=false; */
		budget.orderBread(1,bread);
		budget.orderPeanutButter(3,pb);
		budget.orderJelly(3,jelly);
	}



	public boolean makeSandwich() {
		if (!bread.haveTwoSlices() ||
				!pb.haveTwoServings() ||
				!jelly.haveServing() ) {
			sandwichesRefused++;
			// System.out.println("Sorry... no PB&J today.");
			if (!bread.haveTwoSlices()) moreBread=true;
			if (!pb.haveTwoServings()) morePB=true;
			if (!jelly.haveServing()) moreJ=true;
			return false;
		}
		bread.getTwoSlices();
		pb.getTwoServings();
		jelly.getServing();
		budget.sellSandwich();
		sandwichesServed++;
		// System.out.println("Enjoy your gourmet PB&J sandwich!");
		return true;
	}

	/**
	 * @return the budget
	 */
	public Money getBudget() { return budget.getCash(); }



	/**
	 * @return the sandwichesServed
	 */
	public int getSandwichesServed() { return sandwichesServed; }

	/**
	 * @return the sandwichesRefused
	 */
	public int getSandwichesRefused() { return sandwichesRefused; }

	public void resetSandwichStats() {
		sandwichesServed=sandwichesRefused=0;
	}

	public double getCustomerSatisfaction() {
		return sandwichesServed / (sandwichesServed + 2.0 * sandwichesRefused);
	}

}
