-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3단계 구현 #3973
base: byh0923
Are you sure you want to change the base?
3단계 구현 #3973
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,10 +25,13 @@ public List<Integer> getMatchingCounts(Lotto winningLotto) { | |
.collect(Collectors.toList()); | ||
} | ||
|
||
public Map<PrizePolicy, Integer> calculateWinLottoTicket(List<Integer> matchingLottoTickets) { | ||
public Map<PrizePolicy, Integer> calculateWinLottoTicket(List<Integer> matchingLottoTickets, LottoNumber bonusBall) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
뒤의 인자는 입력한 보너스볼인데 앞의 인자는 입력한 로또 숫자가아니네요! |
||
Map<PrizePolicy, Integer> winLottoTicket = new HashMap<>(); | ||
for (Integer matchCount : matchingLottoTickets) { | ||
inputWinLottoTicket(winLottoTicket, matchCount); | ||
for (int i = 0; i < matchingLottoTickets.size(); i++) { | ||
int matchCount = matchingLottoTickets.get(i); | ||
Lotto lottoTicket = values.get(i); | ||
PrizePolicy prizePolicy = PrizePolicy.fromMatchCountAndBonus(matchCount, lottoTicket.containsBonusBall(bonusBall)); | ||
winLottoTicket.put(prizePolicy, winLottoTicket.getOrDefault(prizePolicy, 0) + 1); | ||
} | ||
return winLottoTicket; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,13 @@ | |
import java.util.Arrays; | ||
|
||
public enum PrizePolicy { | ||
ZERO(0, 0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 당첨이 아닌 0,1,2 개 에 대해서 관리할필요가 있을까요? 🤔 |
||
ONE(1, 0), | ||
TWO(2, 0), | ||
THREE(3, 5_000), | ||
FOUR(4, 50_000), | ||
FIVE(5, 1_500_000), | ||
FIVE_BONUS(5, 30_000_000), | ||
SIX(6, 2_000_000_000); | ||
|
||
private final int matchCount; | ||
|
@@ -34,4 +38,11 @@ public static PrizePolicy fromMatchCount(int matchCount) { | |
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("유효하지 않은 매칭 숫자: " + matchCount)); | ||
} | ||
|
||
public static PrizePolicy fromMatchCountAndBonus(int matchCount, boolean bonusMatch) { | ||
if (matchCount == 5 && bonusMatch) { | ||
return FIVE_BONUS; | ||
} | ||
return fromMatchCount(matchCount); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전에 드린 코멘트와 같이 컨트롤러는 도메인을 상태로 관리하지 않아야합니다.
현재 LottoDisplay 가 컨트롤러의 역할처럼 보이네요!
현재 Lottos 를 통해 로직이 모두 처리되므로 옮겨보시는것도 좋을것 같아요.
추가로 checkMatchingNumber 의 반환값이 winningResult 로 반드시 전달 된다면
메서드를 분리하지 않는것이 명확하지 않을까요?