-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathLottoMachine.java
More file actions
68 lines (57 loc) · 3.23 KB
/
LottoMachine.java
File metadata and controls
68 lines (57 loc) · 3.23 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
57
58
59
60
61
62
63
64
65
66
67
68
package domain;
import domain.lastweekwinninglotto.LastWeekWinningBonusBall;
import domain.lastweekwinninglotto.LastWeekWinningLotto;
import domain.lottoticket.LottoTicket;
import domain.lottoticket.Lottos;
import domain.lottoticket.NumberOfLottoTicket;
import domain.lottowinningresult.LottoWinningBonusBallResult;
import domain.lottowinningresult.LottoWinningResult;
import java.util.ArrayList;
import java.util.List;
public class LottoMachine {
EnumWinningStatus enumWinningStatus = new EnumWinningStatus();
ArrayList<Integer> lottoWinningResults = new ArrayList<>();
ArrayList<Boolean> lottoWinningBonusBallResults = new ArrayList<>();
public ArrayList<WinningStatus> Discriminator(
Lottos lottos,
LastWeekWinningLotto lastWeekWinningLotto,
LastWeekWinningBonusBall lastWeekWinningBonusBall,
NumberOfLottoTicket numberOfLottoTicket
){
for (LottoTicket lotto : lottos.getLottos())
{
List<Boolean> lottoMatchedResult = getMatchLottoNumber(lotto, lastWeekWinningLotto);
Boolean lottoMatchedBonusBallResult = getMatchLottoBonusBallNumber(lotto, lastWeekWinningBonusBall);
int matchLottoNumberCount = getMatchLottoNumberCount(lottoMatchedResult);
lottoWinningResults.add(matchLottoNumberCount);
lottoWinningBonusBallResults.add(lottoMatchedBonusBallResult);
}
LottoFactory lottoFactory = createLottoFactory(lottoWinningResults, lottoWinningBonusBallResults);
return enumWinningStatus.getLottoPrices(lottoFactory, numberOfLottoTicket);
}
private LottoFactory createLottoFactory(ArrayList<Integer> lottoWinningResults, ArrayList<Boolean> lottoWinningBonusBallResults) {
LottoWinningBonusBallResult lottoWinningBonusBallResult = new LottoWinningBonusBallResult(lottoWinningBonusBallResults);
LottoWinningResult winningResult = new LottoWinningResult(lottoWinningResults);
LottoFactory lottoFactory = new LottoFactory(winningResult, lottoWinningBonusBallResult);
return lottoFactory;
}
private int getMatchLottoNumberCount(List<Boolean> lottoMatchedResult){
return (int)lottoMatchedResult.stream().filter(index-> (index)).count();
}
private List<Boolean> getMatchLottoNumber(LottoTicket lotto, LastWeekWinningLotto lastWeekWinningLotto){
List<Integer> lottoList = lotto.getLotto();
List<Integer> lastWeekWinningLottos = lastWeekWinningLotto.getLotto();
ArrayList<Boolean> lottoMatchedResult = new ArrayList<>();
for (int winningLottoNumber = 0; winningLottoNumber < lastWeekWinningLottos.size(); winningLottoNumber++) {
Boolean isMatchLottoNumber = lottoList.contains(lastWeekWinningLottos.get(winningLottoNumber));
lottoMatchedResult.add(isMatchLottoNumber);
}
return lottoMatchedResult;
}
private Boolean getMatchLottoBonusBallNumber(LottoTicket lotto, LastWeekWinningBonusBall lastWeekWinningBonusBall) {
List<Integer> lottoBonusBalls = lotto.getLotto();
int lastWeekWinningBonusBalls = lastWeekWinningBonusBall.getLastWeekWinningBonusBall();
Boolean isMatchLottoNumber = lottoBonusBalls.contains(lastWeekWinningBonusBalls);
return isMatchLottoNumber;
}
}