Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Dougnkong committed Dec 20, 2020
2 parents 6999cfe + 2d3e1c3 commit d12de99
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 25 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 3 additions & 4 deletions src/main/java/common/CoinValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ public enum CoinValue {

private final int coinValue;

CoinValue(int value) {
this.coinValue = value;
}

public int getValue() {
return this.coinValue;
}

CoinValue(int value) {
this.coinValue = value;
}
}
42 changes: 21 additions & 21 deletions src/main/java/model/DrinkMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ public DrinkMachine(HashMap<String, Compartment> compartments) {
this.compartments = compartments;
}

private int getCoinSum(final List<Coin> coins) {
int sumCoin = 0;

for (Coin coin : coins) {
sumCoin += coin.getCoinValue().getValue();
}

return sumCoin;
}

/**
* @param drink
* @param coins
* @return Price bigger than given coins (=true) false else.
*/
private boolean isNotEnoughCoinsGiven(Drink drink, final List<Coin> coins) {

return drink.getPrice() * 100 > getCoinSum(coins);

}

/**
* This method manages the purchase process and in the best case returns
* an object containing the order and the exchange coin.
Expand Down Expand Up @@ -284,4 +263,25 @@ private CoinAndQuantity getCoinAndQuantityByType(final CoinValue coinValue) {
}
return null;
}

private int getCoinSum(final List<Coin> coins) {
int sumCoin = 0;

for (Coin coin : coins) {
sumCoin += coin.getCoinValue().getValue();
}

return sumCoin;
}

/**
* @param drink
* @param coins
* @return Price bigger than given coins (=true) false else.
*/
private boolean isNotEnoughCoinsGiven(Drink drink, final List<Coin> coins) {

return drink.getPrice() * 100 > getCoinSum(coins);

}
}

0 comments on commit d12de99

Please sign in to comment.