proj2
Class SnackMachine

java.lang.Object
  extended by proj2.SnackMachine

public class SnackMachine
extends java.lang.Object

The SnackMachine class implements a basic snack machine that provides several operations.


Constructor Summary
SnackMachine()
          The sole constructor that creates a SnackMachine instance.
 
Method Summary
 boolean addCookies(CookieFlavors flavor, int numberCookies)
          Adds the specified number of cookies of the given flavor.
 boolean addMints(java.awt.Color color, int numberMints)
          Adds the specified number of mints of the given color.
 Cookies buyCookies(Money money)
          Purchases Cookies with the specified money.
 Mints buyMints(Money money)
          Purchases Mints with the specified money.
 int getNumberCookies()
          Gets the number of Cookies in the snack machine.
 int getNumberMints()
          Gets the number of Mints in the snack machine.
 Money getTotalMoney()
          Gets the amount of Money in the snack machine.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SnackMachine

public SnackMachine()
The sole constructor that creates a SnackMachine instance. Creates an empty SnackMachine devoid of any Cookies, Mints and Money.

Method Detail

buyMints

public Mints buyMints(Money money)
Purchases Mints with the specified money.

Parameters:
money - the money for purchasing the Mints.
Returns:
the oldest Mints from machine, or null if an error occurs.

buyCookies

public Cookies buyCookies(Money money)
Purchases Cookies with the specified money.

Parameters:
money - the money for purchasing the Cookies.
Returns:
the oldest Cookies from machine, or null if an error occurs.

addCookies

public boolean addCookies(CookieFlavors flavor,
                          int numberCookies)
Adds the specified number of cookies of the given flavor. If any error occurs, then none of the cookies are added.

Parameters:
flavor - the flavor of cookies to add.
numberCookies - the number of cookies to add.
Returns:
true if the addition was successful, false if not (e.g. the number of cookies being added would put the SnackMachine over the limit).

addMints

public boolean addMints(java.awt.Color color,
                        int numberMints)
Adds the specified number of mints of the given color. If any error occurs, then none of the mints are added.

Parameters:
color - the color of mints to add.
numberMints - the number of mints to add.
Returns:
true if the addition was successful, false if not (e.g. the number of mints being added would put the SnackMachine over the limit).

getNumberMints

public int getNumberMints()
Gets the number of Mints in the snack machine.

Returns:
the number of Mints.

getNumberCookies

public int getNumberCookies()
Gets the number of Cookies in the snack machine.

Returns:
the number of Cookies.

getTotalMoney

public Money getTotalMoney()
Gets the amount of Money in the snack machine.

Returns:
the amount of Money.