forked from Joyykim/java-vendingmachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConsole.java
44 lines (35 loc) · 1.39 KB
/
Console.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package vendingmachine.view;
import vendingmachine.domain.coin.Coin;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.Collectors;
public class Console {
private static final Scanner scanner = new Scanner(System.in);
public static int askVendingMachineAmount() {
System.out.println("자판기가 보유하고 있는 금액을 입력해 주세요.");
return scanner.nextInt();
}
public static String askProducts() {
System.out.println("\n상품명과 수량, 금액을 입력해 주세요.");
// Scanners.nextLine();
return scanner.next();
}
public static int askAmount() {
System.out.println("\n투입 금액을 입력해 주세요.");
return scanner.nextInt();
}
public static String askProduct() {
System.out.println("구매할 상품명을 입력해 주세요.");
return scanner.next();
}
public static void printBalance(final int balance) {
System.out.println(String.format("\n남은 금액: %d원", balance));
}
public static void printChanges(final Map<Coin, Integer> changes) {
System.out.println("잔돈");
final String result = changes.entrySet().stream()
.map(it -> String.format("%d원 - %d개", it.getKey().getAmount(), it.getValue()))
.collect(Collectors.joining("\n"));
System.out.println(result);
}
}