-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathManualLottoTicketWriter.java
More file actions
39 lines (28 loc) · 1.15 KB
/
ManualLottoTicketWriter.java
File metadata and controls
39 lines (28 loc) · 1.15 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
package lotto.controller;
import lotto.domain.LottoBall;
import lotto.domain.LottoTicket;
import lotto.view.Input;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class ManualLottoTicketWriter {
public ManualLottoTicketWriter() {}
public static ManualLottoTicketWriter newWriter() {
return new ManualLottoTicketWriter();
}
public List<LottoTicket> write(int manualLottoCount) {
ArrayList<LottoTicket> manualTickets = new ArrayList<>();
for (int i = 0; i < manualLottoCount; i += 1) {
String numberString = Input.getManualLottoNumber();
LottoTicket ticket = convertToLottoTickets(numberString);
manualTickets.add(ticket);
}
return manualTickets;
}
private LottoTicket convertToLottoTickets(String numberString) {
int[] numbers = Arrays.stream(numberString.split(",")).mapToInt(Integer::parseInt).toArray();
List<LottoBall> lottoNumbers = Arrays.stream(numbers).mapToObj(LottoBall::newBall).collect(Collectors.toList());
return LottoTicket.newTicket(lottoNumbers);
}
}