-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathInputManager.java
More file actions
83 lines (75 loc) · 2.47 KB
/
Copy pathInputManager.java
File metadata and controls
83 lines (75 loc) · 2.47 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
79
80
81
82
83
package vendingmachine.controller;
import java.util.ArrayList;
import java.util.List;
import vendingmachine.domain.Machine;
import vendingmachine.domain.Product;
import vendingmachine.utils.Parser;
import vendingmachine.validator.InputMoneyValidator;
import vendingmachine.view.InputView;
import vendingmachine.view.OutputView;
public class InputManager {
private final InputView inputView;
private final OutputView outputView;
public InputManager(InputView inputView, OutputView outputView) {
this.inputView = inputView;
this.outputView = outputView;
}
public int inputMachineMoney() {
boolean flag = false;
String money = "";
while (!flag) {
try {
money = inputView.inputMachineMoney();
InputMoneyValidator.validateInputMoney(money);
flag = true;
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e);
}
}
return Parser.inputMoneyParser(money);
}
public List<Product> inputMachineProduct() {
boolean flag = false;
List<Product> machineProducts = new ArrayList<>();
while (!flag) {
try {
String products = inputView.inputMachineProduct();
machineProducts = Parser.productsParser(products);
flag = true;
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e);
}
}
return machineProducts;
}
public int inputUserAmount() {
boolean flag = false;
String money = "";
while (!flag) {
try {
money = inputView.inputUserAmount();
;
InputMoneyValidator.validateInputMoney(money);
flag = true;
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e);
}
}
return Parser.inputMoneyParser(money);
}
public String inputBuyProduct(Machine machine) {
boolean flag = false;
String product = "";
while (!flag) {
try {
product = inputView.inputBuyProduct();
machine.isExistsProduct(product);
machine.isExistsQuantity(product);
flag = true;
} catch (IllegalArgumentException e) {
outputView.printErrorMessage(e);
}
}
return product;
}
}