Skip to content
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

[Step2] 로또(자동) #705

Open
wants to merge 12 commits into
base: qktlf789456
Choose a base branch
from
Prev Previous commit
Next Next commit
feat: add LottoServiceRound
qktlf789456 committed Jun 19, 2023
commit 2099d6b92d2de92b012f058be8eb13288340948c
23 changes: 23 additions & 0 deletions src/main/kotlin/LottoServiceRound.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Money.Companion.toMoney

class LottoServiceRound {
private val lottoRound = LottoRound(LottoRoundElements())

fun buyLottos(payment: Money): List<Lotto> {
lottoRound.addNewLottos(payment.buyableCount())
return lottoRound.getLottos()
}

fun allPayment(): Money = (lottoRound.getLottos().size * LOTTO_BUY_PRIZE.value).toMoney()

fun lotteryDraw(numbers: List<Int>): LottoRoundStatistics {
val winningLotto = Lotto.of(numbers)
return lottoRound.lotteryDraw(winningLotto)
}

private fun Money.buyableCount(): Int = (value / LOTTO_BUY_PRIZE.value).toInt()

companion object {
private val LOTTO_BUY_PRIZE = 1000L.toMoney()
}
}