-
Notifications
You must be signed in to change notification settings - Fork 358
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λ¨κ³ - λ‘λ(2λ±) #792
base: goyounggyeong
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -23,8 +23,9 @@ fun main() { | |
printLottoNumber(purchasedLottos) | ||
|
||
val lastWeekWinningString = LottoVendor.readLastWeekWinningString() | ||
val lastWeekBonusNumber = LottoVendor.readLastWeekBonusBallNumber() | ||
val lastWeekWinningNumbers: List<Int> = toIntList(lastWeekWinningString) | ||
purchasedLottos.forEach { it.setLottoPrize(lastWeekWinningNumbers) } | ||
purchasedLottos.forEach { it.setLottoPrize(lastWeekWinningNumbers, lastWeekBonusNumber) } | ||
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. νμ¬λ lastWeekWinningNumbersλ₯Ό Listλ‘ λκ²¨μ£Όκ³ μμ§λ§, ν΄λΉ λ³μλ νλμ Lottoκ°μ²΄λ‘ λ§λ€μ΄λ³΄λ©΄ μ΄λ¨κΉμ?? |
||
val winningRatio = LottoPlayResultAnalysis.getWinningRatio(purchaseAmount, purchasedLottos) | ||
LottoPlayer.printResult(purchasedLottos, winningRatio) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,23 @@ class Lotto { | |
var lottoPrize: LottoPrize = LottoPrize.NONE_PRIZE | ||
val purchasedLottoNumbers: List<Int> = LOTTO_NUMBERS.shuffled().take(LOTTO_NUMBER_COUNT).sorted() | ||
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. μ§λμ£Ό 리뷰μμ LottoNumberλ₯Ό κ°κ°μ²΄λ‘ wrappingνλ μμλ₯Ό 보μ¬μ€¬λλ°μ! μ΄λ²μ κ°κ°μ²΄λ₯Ό λ§λ€μ΄λ³΄μλ©΄ μ΄λ¨κΉμ? |
||
|
||
fun setLottoPrize(lastWeekWinningNumbers: List<Int>): LottoPrize { | ||
private fun match(lastWeekWinningNumbers: List<Int>): Int { | ||
val matchingNumbers = purchasedLottoNumbers.intersect(lastWeekWinningNumbers.toSet()).size | ||
lottoPrize = LottoPrize.getLottoPrize(matchingNumbers) | ||
return matchingNumbers | ||
} | ||
|
||
fun setLottoPrize(lastWeekWinningNumbers: List<Int>, lastWeekBonusNumber: Int): LottoPrize { | ||
val matchingNumbers = match(lastWeekWinningNumbers) | ||
val bonusBallMatching: Int = | ||
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.
|
||
if (purchasedLottoNumbers.contains(lastWeekBonusNumber)) CONTAIN_BALL else NOT_CONTAIN_BALL | ||
lottoPrize = LottoPrize.getLottoPrize(matchingNumbers, bonusBallMatching) | ||
return lottoPrize | ||
} | ||
|
||
companion object { | ||
private val LOTTO_NUMBERS: List<Int> = (1..45).toList() | ||
private const val LOTTO_NUMBER_COUNT = 6 | ||
private const val CONTAIN_BALL = 1 | ||
private const val NOT_CONTAIN_BALL = 0 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,28 @@ | ||
package lotto.model | ||
|
||
enum class LottoPrize(val matchingCount: Int, val prizeAmount: Long) { | ||
FIRST(6, 2000000000), | ||
SECOND(5, 1500000), | ||
THIRD(4, 50000), | ||
FOURTH(3, 5000), | ||
NONE_PRIZE(0, 0); | ||
enum class LottoPrize(val matchingCount: Int, val bonusMatching: Int = 0, val prizeAmount: Long) { | ||
FIRST(6, 0, 2000000000), | ||
BONUS(5, 1, 30000000), | ||
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. λ³΄ν΅ λ‘λμμ 2λ±μ 5κ° μΌμΉ + 보λμ€ μΌμΉλ‘ μ΄μΌκΈ°νλλ°μ! ν΄λΉ enumμ κ°μ΄ BONUSκ° λμ΄μΌνμ§ μμκΉμ? |
||
SECOND(5, 0, 1500000), | ||
THIRD(4, 0, 50000), | ||
FOURTH(3, 0, 5000), | ||
NONE_PRIZE(0, 0, 0); | ||
|
||
companion object { | ||
private const val PRIZING_CONT = 3 | ||
fun getLottoPrize(matchingCount: Int): LottoPrize { | ||
if(matchingCount >= PRIZING_CONT) { return NONE_PRIZE } | ||
return values().find { it.matchingCount == matchingCount }!! | ||
private const val SECOND_PRIZE_MATCHING_COUNT = 5 | ||
fun getLottoPrize(matchingCount: Int, lastWeekBonusNumber: Int): LottoPrize { | ||
if (matchingCount < PRIZING_CONT) { | ||
return NONE_PRIZE | ||
} | ||
|
||
val prize = values().find { it.matchingCount == matchingCount } ?: return NONE_PRIZE | ||
|
||
if (matchingCount == SECOND_PRIZE_MATCHING_COUNT) { | ||
if ( lastWeekBonusNumber > 0) return BONUS | ||
else return SECOND | ||
} | ||
return prize | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package lotto.service | ||
|
||
object LottoTicketCountCalculator { | ||
|
||
private const val LOTTO_PRICE = 1000 | ||
|
||
fun getCount(purchaseAmount: Int) : Int = purchaseAmount / LOTTO_PRICE | ||
|
||
} |
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.
μ μ κ° 2λ¨κ³μμ νΌλλ°± λλ¦¬μ§ λͺ»νλΆλΆμ΄ μμ΄μ μκΈ°μ λ¨κΈΈκ²μ!!