forked from knh4437/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLottoController.java
More file actions
50 lines (43 loc) · 1.68 KB
/
LottoController.java
File metadata and controls
50 lines (43 loc) · 1.68 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
package lotto.controller;
import camp.nextstep.edu.missionutils.Randoms;
import lotto.model.Lotto;
import lotto.model.LottoRank;
import lotto.model.LottoResult;
import java.util.ArrayList;
import java.util.List;
public class LottoController {
private static final int LOTTO_MIN_NUMBER = 1; // 로또 번호의 최소값
private static final int LOTTO_MAX_NUMBER = 45; // 로또 번호의 최대값
private static final int LOTTO_NUMBER_COUNT = 6; // 로또 번호의 개수
private static final double PERCENTAGE_CONVERSION = 100.0; // 수익률 계산 비율
/**
* 로또 번호 생성
*/
public List<Lotto> generateLottoNumber(int count) {
List<Lotto> result = new ArrayList<>();
for(int i = 0; i < count; i++) {
List<Integer> numbers = Randoms.pickUniqueNumbersInRange(LOTTO_MIN_NUMBER, LOTTO_MAX_NUMBER, LOTTO_NUMBER_COUNT);
result.add(new Lotto(numbers));
}
return result;
}
/**
* 당첨 결과 확인
*/
public LottoResult checkWinningResult(List<Lotto> lottoList, List<Integer> winningNumbers, int bonusNumber) {
LottoResult result = new LottoResult();
for (Lotto lotto : lottoList) {
int matchCount = lotto.matchCount(winningNumbers);
boolean bonusMatch = lotto.contains(bonusNumber);
result.addResult(LottoRank.findMatchingRank(matchCount, bonusMatch));
}
return result;
}
/**
* 수익률 계산
*/
public double calculateProfitRate(int money, LottoResult result) {
long totalPrize = result.getTotalPrize();
return (totalPrize * PERCENTAGE_CONVERSION) / money;
}
}