-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.java
26 lines (21 loc) · 883 Bytes
/
Main.java
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
import java.io.Console;
import state.*;
import vendingmachine.*;
public class Main {
public static void main(String[] args) {
Console console = System.console();
int quantity = Integer.parseInt(console.readLine("Enter product quantity: "));
int price = Integer.parseInt(console.readLine("Enter product price: "));
VendingMachine vendingMachine = new VendingMachine(quantity, price);
String prompt = "\n\nPay amount(press 'q' to quit):";
while (true) {
String input = console.readLine(prompt);
if (input.equalsIgnoreCase("q") && (vendingMachine.getState() instanceof InitialState
|| vendingMachine.getState() instanceof StockoutState)) {
break;
}
int amount = Integer.parseInt(input);
vendingMachine.pay(amount);
}
}
}