Home

drink machine

A drink machine has a CoinBox class connected to these buttons:

Fill in the CoinBox class outline below to get the following behavior:

When any button is pressed, CoinBox resets and begins waiting for coins of the proper amount. When coins are inserted, CoinBox keeps a total and, depending on the total and the price of the product selected, waits for more coins or makes coffee and returns any change due.

If coins are inserted when no product is selected, CoinBox returns the coins immediately and the total of inserted coins goes back to zero.

When CoinBox resets, it checks to see if it is holding coins that never got used for coffee and returns the amount.

The makeCoffee() function should use these supplied functions:

  • addSugar()

  • addCreamerPowder()

  • addCoffeePowder()

  • addHotWater() – do this last for best mixing of ingredients

When CoinBox needs to return money, call the supplied function returnMoney( int amount ).



Extra Credit: When you tested a prototype drink machine with people that didn’t know how the CoinBox class works, they asked for another button to do something the CoinBox already does. What did they call the button, and why did they think they needed it?


public class CoinBox {
	// class variables to remember what product, price, how much paid so far





	CoinBox() { // constructor should initialize the CoinBox



	}
	public void reset() {



	}
	public void pressCoffee() {


	}
	public void pressCoffeeSugar() {


	}
	public void pressCoffeeCream() {


	}
	public void pressCoffeeCreamSugar() {


	}
	public void makeCoffee() {





	}
	public void insertCoin( int amount /* 5, 10, 25 */ ) {






	}
}