-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathInputView.java
More file actions
56 lines (42 loc) · 1.76 KB
/
InputView.java
File metadata and controls
56 lines (42 loc) · 1.76 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
package lotto.view;
import lotto.domain.model.lotto.*;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class InputView {
private final Scanner scanner = new Scanner(System.in);
public PurchaseAmount inputPurchaseAmount() {
System.out.println("구입금액을 입력해 주세요.");
return new PurchaseAmount(Integer.parseInt(scanner.nextLine()));
}
public TicketCount inputManualTicketCount() {
System.out.println("수동으로 구매할 로또 수를 입력해 주세요.");
return new TicketCount(Integer.parseInt(scanner.nextLine()));
}
public List<LottoTicket> inputManualTicketNumbers(final TicketCount manualTicketCount) {
System.out.println("수동으로 구매할 번호를 입력해 주세요.");
List<LottoTicket> tickets = new ArrayList<>();
for (int i = 0; i < manualTicketCount.getCount(); i++) {
tickets.add(new LottoTicket(inputLottoNumbers()));
}
return tickets;
}
public BonusNumber inputBonusNumber() {
System.out.println("보너스 볼을 입력해 주세요.");
return new BonusNumber(Integer.parseInt(scanner.nextLine()));
}
public Set<LottoNumber> inputWinningNumbers() {
System.out.println("지난 주 당첨 번호를 입력해 주세요.");
return inputLottoNumbers();
}
private Set<LottoNumber> inputLottoNumbers() {
String[] tokens = scanner.nextLine().split(",");
return Stream.of(tokens)
.map(token -> Integer.parseInt(token.trim()))
.map(LottoNumber::new)
.collect(Collectors.toUnmodifiableSet());
}
public void close() {
scanner.close();
}
}