Class VendingMachine

java.lang.Object
  extended by VendingMachine

public class VendingMachine
extends java.lang.Object

Represents the Controller and the Model of the Vending Machine program. Allows users and operators to complete transaction with a vending machine.


Constructor Summary
VendingMachine()
          Constructs a new VendingMachine object with a standard inventory and an empty bank
 
Method Summary
 void addToNumCoinsTotal()
          Adds the coins entered by a user to the bank of coins in this VendingMachine
 void decrementProductCount(int index)
          Decrements the quantity of the Product at the given index by one
 java.lang.String dispenseProduct(int index)
          Returns a String representation of the dispensed form of the Product at the given index of 'allProducts'
 Product[] getAllProducts()
          Returns a copy of the data stored in this VendingMachine's 'allProducts' field
 void increaseProductQuantity(int index, int toAdd)
          Increases the quantity of a Product by a given amount
 void incrementNumCoinsEnteredByUser()
          Increments the number of coins entered by a user by one
 boolean matchesOperatorPasscode(int attempt)
          Returns true iff the given number matches the operator passcode
 java.lang.String removeAllCoins()
          Returns a String stating a confirmation of the removal of all the coins in this VendingMachine's bank
 void resetAllCoinsToZero()
          Resets this VendingMachine's bank of coins to zero
 void resetCoinsEnteredByUserToZero()
          Resets the number of coins entered by user to zero
 void resetNumCoinsEnteredByCurrentUser()
          Resets the number of coins entered by the current user to zero
 java.lang.String returnCoinsToUser()
          Returns a String stating a confirmation that the user's coins have been returned
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

VendingMachine

public VendingMachine()
Constructs a new VendingMachine object with a standard inventory and an empty bank

Method Detail

getAllProducts

public Product[] getAllProducts()
Returns a copy of the data stored in this VendingMachine's 'allProducts' field

Returns:
a copy of the data stored in this VendingMachine's 'allProducts' field

decrementProductCount

public void decrementProductCount(int index)
Decrements the quantity of the Product at the given index by one

Parameters:
index - the index of the Product in 'allProducts' to decrement

dispenseProduct

public java.lang.String dispenseProduct(int index)
Returns a String representation of the dispensed form of the Product at the given index of 'allProducts'

Parameters:
index - the index in 'allProducts' of the Product to dispense
Returns:
a String representation of the dispensed form of the Product at the given index of 'allProducts'

incrementNumCoinsEnteredByUser

public void incrementNumCoinsEnteredByUser()
Increments the number of coins entered by a user by one


resetNumCoinsEnteredByCurrentUser

public void resetNumCoinsEnteredByCurrentUser()
Resets the number of coins entered by the current user to zero


addToNumCoinsTotal

public void addToNumCoinsTotal()
Adds the coins entered by a user to the bank of coins in this VendingMachine


increaseProductQuantity

public void increaseProductQuantity(int index,
                                    int toAdd)
Increases the quantity of a Product by a given amount

Parameters:
index - the index of 'allProducts' of the Product to add to
toAdd - the amount to increase the Product's quantity by

removeAllCoins

public java.lang.String removeAllCoins()
Returns a String stating a confirmation of the removal of all the coins in this VendingMachine's bank

Returns:
a String stating a confirmation of the removal of all the coins in this VendingMachine's bank

resetAllCoinsToZero

public void resetAllCoinsToZero()
Resets this VendingMachine's bank of coins to zero


returnCoinsToUser

public java.lang.String returnCoinsToUser()
Returns a String stating a confirmation that the user's coins have been returned

Returns:
a String stating a confirmation that the user's coins have been returned

resetCoinsEnteredByUserToZero

public void resetCoinsEnteredByUserToZero()
Resets the number of coins entered by user to zero


matchesOperatorPasscode

public boolean matchesOperatorPasscode(int attempt)
Returns true iff the given number matches the operator passcode

Parameters:
attempt - the number to test for equality against the operator passcode
Returns:
true iff the given number matches the operator passcode