-
Notifications
You must be signed in to change notification settings - Fork 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
[Step4] 로또(2등) #1676
Merged
Merged
[Step4] 로또(2등) #1676
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7fc89fa
docs: 구현해야할 기능 목록 정의
LenKIM 728cfb1
feat: 2등에게 주어지는 보너스볼 기능 추가
LenKIM 3fd2490
refactor: WinningTicket 도메인 추가
LenKIM 0243810
refactor: 사용되지 않는 getter 제거 및 메소드 위치 변경
LenKIM b196404
refactor: WinningTicket 을 생성자를 통해 생성하도록 수정
LenKIM fb32db9
bug: Null 체크 로직 추가, 예외 메세지 변수화
LenKIM File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package lottery; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public class WinningTicket { | ||
|
||
private final Ticket ticket; | ||
private final int bonus; | ||
|
||
public WinningTicket(Ticket ticket, int bonus) { | ||
this.ticket = ticket; | ||
this.bonus = bonus; | ||
} | ||
|
||
public Ticket getTicket() { | ||
return ticket; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (!(o instanceof WinningTicket)) | ||
return false; | ||
WinningTicket that = (WinningTicket)o; | ||
return bonus == that.bonus && Objects.equals(ticket, that.ticket); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(ticket, bonus); | ||
} | ||
|
||
public LotteryMatchType getMatchTypeWith(Ticket targetTicket) { | ||
LinkedHashSet<Integer> targetNumbers = new LinkedHashSet<>(targetTicket.numbers()); | ||
targetNumbers.removeAll(this.ticket.numbers()); | ||
|
||
LotteryMatchType matchType = LotteryMatchType.fromInteger(Ticket.SIZE_OF_TICKET - targetNumbers.size()); | ||
if (isBonusMatchCount(bonus, matchType, targetNumbers)) { | ||
return LotteryMatchType.FIVE_MATCH_WITH_BONUS; | ||
} | ||
return matchType; | ||
} | ||
|
||
private boolean isBonusMatchCount(int bonus, | ||
LotteryMatchType matchType, | ||
Set<Integer> winningTicketNumbers) { | ||
return matchType == LotteryMatchType.FIVE_MATCH && winningTicketNumbers.contains(bonus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,45 @@ | ||
package lottery.view; | ||
|
||
import java.util.Arrays; | ||
import java.util.Map; | ||
|
||
import lottery.LotteryMatchType; | ||
import lottery.Result; | ||
|
||
public class ResultView { | ||
|
||
public void printResult(Result result, float yield) { | ||
System.out.println("당첨 통계"); | ||
System.out.println("-----------"); | ||
result.getResultMap() | ||
.forEach( | ||
(matchType, count) -> System.out.printf("%d개 일치 (%d원) - %d개\n", matchType.matchCount(), matchType.money().amount(), count) | ||
); | ||
System.out.printf("총 수익률은 %.2f 입니다.(기준이 1이기 때문에 결과적으로 손해라는 의미임)\n", yield); | ||
|
||
print("당첨 통계"); | ||
print("-----------"); | ||
final Map<LotteryMatchType, Integer> resultMap = result.getResultMap(); | ||
Arrays.stream(LotteryMatchType.values()) | ||
.filter(matchType -> matchType != LotteryMatchType.MISS_MATCH) | ||
.forEachOrdered( | ||
matchType -> { | ||
if (resultMap.containsKey(matchType)) { | ||
makeMatchStringTemplate(matchType, resultMap.get(matchType)); | ||
} | ||
makeMatchStringTemplate(matchType, 0); | ||
} | ||
); | ||
System.out.printf("총 수익률은 %.2f입니다.(기준이 1이기 때문에 결과적으로 손해라는 의미임)\n", yield); | ||
} | ||
|
||
private void makeMatchStringTemplate(LotteryMatchType matchType, Integer count) { | ||
StringBuilder sb = new StringBuilder(); | ||
StringBuilder append = sb.append(matchType.matchCount()) | ||
.append("개 일치"); | ||
if (matchType == LotteryMatchType.FIVE_MATCH_WITH_BONUS) { | ||
append.append(", 보너스 볼 일치"); | ||
} | ||
append.append(" (") | ||
.append(matchType.money().amount()) | ||
.append("원)- " + count + "개"); | ||
System.out.println(append); | ||
} | ||
|
||
private void print(String 당첨_통계) { | ||
System.out.println(당첨_통계); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
WinningTicket
을 정의해주셨네요 👍