-
Notifications
You must be signed in to change notification settings - Fork 322
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] 4단계 - 로또(수동) PR 요청드립니다. #552
base: dajeong
Are you sure you want to change the base?
Changes from all commits
9edc1be
f528f8b
401a85d
e093e7d
f9d9dca
d9d7cae
56aba68
77605aa
89e133d
3291402
6a205a9
0db5155
76bd302
17716c8
51f1799
0f56910
431d97a
8a3e35b
533f5fb
c0e7831
01d85e4
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 |
---|---|---|
@@ -1,27 +1,35 @@ | ||
package lotto.application | ||
|
||
import lotto.domain.Lotto | ||
import lotto.domain.LottoGenerator | ||
import lotto.domain.LottoNumber | ||
import lotto.domain.LottoResultService | ||
import lotto.domain.LottoShop | ||
import lotto.domain.LuckyNumbers | ||
import lotto.util.RandomNumberGenerator | ||
import lotto.view.InputView | ||
import lotto.view.ResultView | ||
|
||
class Application { | ||
private val inputView = InputView() | ||
private val resultView = ResultView() | ||
private val lottoShop = LottoShop(LottoGenerator(RandomNumberGenerator())) | ||
private val lottoGenerator = LottoGenerator(RandomNumberGenerator()) | ||
|
||
fun run() { | ||
val inputPayment = inputView.inputPayment() | ||
val lottoList = lottoShop.buyLotto(inputPayment) | ||
resultView.printLotto(lottoList) | ||
val manualLottoCount = inputView.inputManualLottoCount() | ||
val manualNumberList = inputView.inputManualLottoNumbers(manualLottoCount) | ||
|
||
val lottoShop = LottoShop(lottoGenerator, inputPayment) | ||
|
||
val manualLottoList = lottoShop.buyManualLotto(manualNumberList) | ||
val autoLottoList = lottoShop.buyAutoLotto() | ||
resultView.printLottoList(manualLottoList, autoLottoList) | ||
Comment on lines
+24
to
+26
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. 개인적으로 수동 로또를 구매하고, 자동로또를 구매하는 로직은 |
||
|
||
val lottoList = manualLottoList + autoLottoList | ||
val inputLuckyNumbers = inputView.inputLuckyNumbers() | ||
val inputBonusNumber = inputView.inputBonusNumber() | ||
|
||
val lottoResultService = LottoResultService(LuckyNumbers(inputLuckyNumbers, inputBonusNumber)) | ||
val lottoResultService = LottoResultService(Lotto(inputLuckyNumbers.integerNumberList.map { LottoNumber(it) }), LottoNumber(inputBonusNumber)) | ||
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. 죄송합니다 🙏 이전 미션 코멘트에서
LuckyNumbers 클래스가 아닌, LuckyNumbers객체의 List인 luckyNumbers 컬렉션을 의미하는 코멘트였습니다 ㅠㅠ 이전처럼 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. 아하 넵 ㅠㅠ 이해했습니다 |
||
val statistics = lottoResultService.inquireStatistics(inputPayment, lottoList) | ||
resultView.printLottoStatistics(statistics) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package lotto.common | ||
|
||
class IntegerNumberList( | ||
val integerNumberList: List<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. 수동 로또 구매를 위한 컬렉션이라면,
|
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package lotto.common | ||
|
||
class NumberString( | ||
private val string: String | ||
) { | ||
init { | ||
require(string.isNotBlank()) { "값이 비어있습니다." } | ||
require(isNumber()) { "숫자가 아닙니다. (입력값:$string)" } | ||
} | ||
|
||
private fun isNumber(): Boolean { | ||
return string.toCharArray().all { it in '0'..'9' } | ||
} | ||
|
||
fun toIntegerNumber(): Int { | ||
return string.toInt() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package lotto.common | ||
|
||
class NumberStringList( | ||
string: String | ||
) { | ||
val list = string.split(",").map { NumberString(it.trim()) } | ||
|
||
fun toIntegerNumberList(): List<Int> { | ||
return list.map { it.toIntegerNumber() } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package lotto.domain | ||
|
||
data class LottoNumber( | ||
val number: Int | ||
) { | ||
dajeong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
init { | ||
require(number in LOTTO_MIN_NUMBER..LOTTO_MAX_NUMBER) { "로또 번호는 ${LOTTO_MIN_NUMBER}와 $LOTTO_MAX_NUMBER 사이 값 이여야 합니다." } | ||
} | ||
|
||
companion object { | ||
const val LOTTO_MIN_NUMBER = 1 | ||
const val LOTTO_MAX_NUMBER = 45 | ||
} | ||
|
||
override fun toString(): String { | ||
return "$number" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
package lotto.domain | ||
|
||
class LottoResultService( | ||
private val luckyNumbers: LuckyNumbers, | ||
private val luckyLotto: Lotto, | ||
private val bonusNumber: LottoNumber | ||
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. LottoResultService 라는 이름에 맞게 |
||
) { | ||
fun inquireStatistics(payment: Int, lottoList: List<Lotto>): LottoStatisticsTotal { | ||
val lottoWinner = LottoWinner(luckyNumbers) | ||
val winLottoList = lottoWinner.findWinLottoList(lottoList) | ||
fun inquireStatistics(payment: Payment, lottoList: List<Lotto>): LottoStatisticsTotal { | ||
val winLottoList = findWinLottoList(lottoList) | ||
val lottoStatisticsService = LottoStatisticsService(payment, winLottoList) | ||
return lottoStatisticsService.statistics() | ||
} | ||
|
||
private fun findWinLottoList(lottoList: List<Lotto>): List<LottoRank> { | ||
return lottoList | ||
.map { rank(it, bonusNumber) } | ||
.filter { hasPrize(it) } | ||
} | ||
|
||
private fun rank(lotto: Lotto, bonusNumber: LottoNumber): LottoRank { | ||
val hitCount = lotto.countHitNumbers(luckyLotto) | ||
val hasBonusNumber = lotto.hasBonusNumber(bonusNumber) | ||
return LottoRank.from(hitCount, hasBonusNumber) | ||
} | ||
|
||
private fun hasPrize(lottoRank: LottoRank) = lottoRank.prizeMoney.isPositive() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,10 @@ import lotto.util.NumberUtil | |
class LottoStatistics( | ||
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. LottoStatistics 클래스는 List의 일급컬렉션이라과 봐도될거같아요! |
||
private val winLottoList: List<LottoRank> | ||
) { | ||
private val prizeList: List<Int> = winLottoList.map { it.prizeMoney } | ||
private val totalPrize: Int = prizeList.sum() | ||
private val totalPrize: Int = winLottoList.sumOf { it.prizeMoney.amount } | ||
|
||
fun earningRate(inputPayment: Int): Double { | ||
val earningRate = totalPrize.toDouble() / inputPayment.toDouble() | ||
fun earningRate(inputPayment: Payment): Double { | ||
val earningRate = totalPrize.toDouble() / inputPayment.amount.toDouble() | ||
return NumberUtil.floor(earningRate, EARNING_RATE_DECIMAL_PLACE) | ||
} | ||
|
||
|
@@ -25,6 +24,6 @@ class LottoStatistics( | |
} | ||
|
||
companion object { | ||
private const val EARNING_RATE_DECIMAL_PLACE = 2 | ||
private const val EARNING_RATE_DECIMAL_PLACE = 2.0 | ||
} | ||
} |
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.
run함수가 비대해진거 같아요!
로또 구매, 로또확인, 결과출력 과 같이 함수로 분리해보면 어떨까요?