-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathController.java
More file actions
78 lines (70 loc) · 2.45 KB
/
Copy pathController.java
File metadata and controls
78 lines (70 loc) · 2.45 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package controller;
import dto.HoldingSumRequestDto;
import dto.MoneyRequestDto;
import dto.ProductNameRequestDto;
import dto.ProductsRequestDto;
import service.VendingMachineService;
import view.InputView;
import view.OutputView;
public class Controller {
private final InputView inputView = new InputView();
private final OutputView outputView = new OutputView();
private final VendingMachineService vendingMachineService = new VendingMachineService();
public void control() {
initHoldingSum();
saveProductsInfo();
inputMoney();
buyProduct();
}
private void initHoldingSum() {
while (true) {
try {
HoldingSumRequestDto holdingSumRequestDto = inputView.readHolingSum();
outputView.printCoins(vendingMachineService.changeHoldingSumToCoins(holdingSumRequestDto));
return;
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
private void saveProductsInfo() {
while (true) {
try {
ProductsRequestDto productsRequestDto = inputView.readProducts();
vendingMachineService.saveProductsInfo(productsRequestDto);
return;
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
private void inputMoney() {
while (true) {
try {
MoneyRequestDto moneyRequestDto = inputView.readMoney();
vendingMachineService.saveMoney(moneyRequestDto);
return;
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
private void buyProduct() {
while (!vendingMachineService.isEnd()) {
inputProductName();
}
outputView.printEnd(vendingMachineService.conveyCurrentMoney(), vendingMachineService.calculateChange());
}
private void inputProductName() {
while (true) {
try {
ProductNameRequestDto productNameRequestDto = inputView.readProductName(
vendingMachineService.conveyCurrentMoney());
vendingMachineService.purchaseProduct(productNameRequestDto);
return;
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
}
}
}
}