Exemplo n.º 1
0
  /**
   * Returns an integer indicating the maximum number of coins available of a specific type.
   *
   * @param difference Amount between the money provided and the product price.
   * @param coin Current coin in the Map<Coin,Integer>
   * @param changeLimits Indicated whether there is an unlimited supply of change in the machine or
   *     not.
   * @return Integer indicating the maximum amount of coins available for distribution.
   */
  private int getCap(int difference, Coin coin, boolean changeLimits) {

    int capExact = difference / coin.getValueAsInt();

    if (changeLimits) {
      int capMachine = availableChangeMachine.get(coin);
      if (capExact >= capMachine) {
        return capMachine;
      }
    }

    return capExact;
  }
Exemplo n.º 2
0
 /**
  * Checks if the current coin in the Map<Coin,Integer> needs to be added to the changeInProgress.
  *
  * @param coin Current coin in the Map<Coin,Integer>
  * @param difference Amount between the money provided and the product price.
  * @return True if the current coin fits the criteria for the return change.
  */
 private boolean isCoinTypeNeeded(Coin coin, int difference) {
   return difference / coin.getValueAsInt() > 0;
 }