-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Step3 - 로또(2등) #3199
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
Step3 - 로또(2등) #3199
Changes from 2 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 |
|---|---|---|
|
|
@@ -29,11 +29,16 @@ public boolean isContain(Integer number) { | |
| return this.lottoTicket.contains(number); | ||
| } | ||
|
|
||
| public PrizeMoney countMatchingNumbers(LottoTicket compareTarget) { | ||
| public Rank checkLottoTicket(LottoTicket compareTarget, int bonusNumber) { | ||
| int count = (int) lottoTicket.stream() | ||
| .filter(i -> compareTarget.isContain(i)) | ||
| .count(); | ||
| return PrizeMoney.toPrizeMoney(count); | ||
|
|
||
| if(count == 5 && compareTarget.isContain(bonusNumber)) { | ||
| return Rank.SECOND; | ||
| } | ||
|
||
|
|
||
| return Rank.toPrizeMoney(count); | ||
| } | ||
|
|
||
| public String printTicket() { | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package step2.domain; | ||
|
|
||
| import java.security.InvalidParameterException; | ||
| import java.util.Arrays; | ||
|
|
||
| public enum Rank { | ||
| MISS(0, 0, "0개 일치 (0)"), | ||
| FIFTH(3, 5_000, "3개 일치 (5000)"), | ||
| FOURTH(4, 50_000, "4개 일치 (50000)"), | ||
| THIRD(5, 1_500_000, "5개 일치 (1500000)"), | ||
| SECOND(5, 30_000_000, "5개 일치, 보너스 볼 일치(30000000원)"), | ||
| FIRST(6, 2_000_000_000, "6개 일치 (2000000000)"); | ||
|
|
||
| private static final int THIRD_COUNT = 5; | ||
|
|
||
| private int matchCount; | ||
| private long prizeMoney; | ||
|
|
||
| private String message; | ||
|
|
||
| Rank(int matchCount, long rank, String message) { | ||
| this.matchCount = matchCount; | ||
| this.prizeMoney = rank; | ||
| this.message = message; | ||
| } | ||
|
|
||
| public static Rank toPrizeMoney(int matchCount) { | ||
| if (matchCount == THIRD_COUNT) { | ||
| return Rank.THIRD; | ||
| } | ||
|
|
||
| return Arrays.stream(values()) | ||
| .filter(prizeMoney -> prizeMoney.matchCount == matchCount) | ||
| .findAny() | ||
| .orElse(Rank.MISS); | ||
| } | ||
|
|
||
| public int matchCount() { | ||
| return this.matchCount; | ||
| } | ||
|
|
||
| public long prizeMoney() { | ||
| return this.prizeMoney; | ||
| } | ||
|
|
||
| public String message() { | ||
| return this.message; | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.