-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathPurchaseController.java
More file actions
36 lines (29 loc) · 1.06 KB
/
PurchaseController.java
File metadata and controls
36 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package vendingmachine.controller;
import java.util.Map;
import vendingmachine.VendingMachine;
import vendingmachine.coin.Coin;
import vendingmachine.exception.RetryExceptionHandler;
import vendingmachine.view.InputView;
import vendingmachine.view.OutputView;
public class PurchaseController {
public void purchase(VendingMachine machine) {
while (machine.isSellable()) {
RetryExceptionHandler.run(() ->purchaseMenu(machine));
}
printResult(machine);
}
private void printResult(VendingMachine machine) {
printRemainMoney(machine);
Map<Coin, Integer> coinIntegerMap = machine.giveChange();
OutputView.printChange(coinIntegerMap);
}
private static void purchaseMenu(VendingMachine machine) {
printRemainMoney(machine);
String menuName = InputView.getMenuName();
machine.purchase(menuName);
}
private static void printRemainMoney(VendingMachine machine) {
int remainMoney = machine.getRemainMoney();
OutputView.printRemainMoney(remainMoney);
}
}