-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathMachineController.java
More file actions
37 lines (30 loc) · 1.1 KB
/
Copy pathMachineController.java
File metadata and controls
37 lines (30 loc) · 1.1 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
package vendingmachine.controller;
import vendingmachine.domain.Change;
import vendingmachine.domain.Product;
import vendingmachine.domain.Shelf;
import vendingmachine.domain.VendingMachine;
import vendingmachine.view.View;
import java.util.List;
public class MachineController {
View view = new View();
public void play(){
Change change = view.inputChange();
view.printChange(change.startChangePrint());
setProduct(change);
}
private void setProduct(Change change) {
List<Product> products = view.inputProducts();
createVendingMachine(change, products);
}
private void createVendingMachine(Change change, List<Product> products) {
int amount = view.inputAmount();
VendingMachine vendingMachine = new VendingMachine(change, new Shelf(products), amount);
untilEnd(vendingMachine, change);
}
private void untilEnd(VendingMachine vendingMachine, Change change) {
while(!vendingMachine.isEndSate()){
view.inputBuyProduct(vendingMachine);
}
view.printChange(change.leftChangePrint());
}
}