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

🚀 2단계 - 로또(자동) #532

Open
wants to merge 19 commits into
base: shinseongsu
Choose a base branch
from

Conversation

shinseongsu
Copy link

멘토님 안녕하세요 오랜만에 PR 보내서 죄송합니다.

기능 구현


  • 로또 구입 금액을 입력하면 구입 금액에 해당하는 로또를 발급해야 한다.
    • 1~45 숫자중에 6가지를 선택하여 가져온다.
    • 로또 1장의 가격은 1000원이다.
  • 당첨 로또는 직접 입력받는다.
  • 당첨금에 대한 수익률을 출력한다.
  • 당첨 통계를 나타낸다.

구현하면서 생각한점


Controller 에서 입력과 출력이 의존되게 구현하였으며, 결과 통계를 class에 담아서 출력하였습니다.

Copy link
Member

@Hyeon9mak Hyeon9mak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

안녕하세요 성수님! 죄송하시다뇨! 아닙니다 😅 빨리 리뷰 못드린 제가 죄송하지요.

너무 완성도 높게 미션 진행해주셔서 감탄 코멘트만 반복한거 같네요.
사소한 부분 몇가지 코멘트 남겼으니 확인해주시면 바로 approve 하도록 하겠습니다.
나머지 로또 미션도 화이팅입니다! 💪

궁금하신 점 언제든지 코멘트 남겨주세요 🙇‍♂️

Comment on lines +10 to +14
companion object {
const val LOTTO_START_NUMBER = 1
const val LOTTO_END_NUMBER = 45
const val LOTTO_NUMBERS_SIZE = 6
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RandomNumberGenerator 내부에서만 사용되는 상수들이라면 private 으로 가려줄 수 있을거 같아요!

Comment on lines +4 to +8
override fun generate(): List<Int> {
val range = LOTTO_START_NUMBER..LOTTO_END_NUMBER
val shuffled = range.shuffled()
return shuffled.subList(0, LOTTO_NUMBERS_SIZE).sorted()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1~45 사이 6개 난수 발생로직 깔끔하네요 👍 👍
난수가 잘 발생되는지 테스트 코드 작성이 가능할까요?
(혹시나 테스트 코드 작성에 어려움이 느껴지신다면 코멘트 남겨주세요!)

}

fun validateNotBlank(string: String) {
require(!string.isBlank()) { "값이 비어 있습니다." }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isNotBlank() 로도 대체할 수 있겠네요! 👍

Comment on lines +9 to +11
private fun String.isNumeric(): Boolean {
return this.toCharArray().all { it in '0'..'9' }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow 😮 👍

Comment on lines +7 to +8
const val INPUT_PAYMENT_GUIDE = "# 구입금액을 입력해주세요."
const val INPUT_LUCKY_NUMBERS_GUIDE = "# 지난 주 당첨 번호를 입력해 주세요."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

역시나 내부에서만 사용된다면 private 으로 😉

Comment on lines +3 to +18
class LottoShop(
private val lottoGenerator: LottoGenerator
) {

fun buy(inputPayment: Int): List<Lotto> {
val lottoCount = calculateLottoCount(inputPayment)
return lottoGenerator.generate(lottoCount)
}

private fun calculateLottoCount(payment: Int): Int {
return payment / LOTTO_PRICE
}

companion object {
private const val LOTTO_PRICE = 1000
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

책임의 분리가 굉장히 훌륭하네요 😮 👍 👍
덕분에 테스트 코드도 깔끔한거 같아요!!!!

Comment on lines +7 to +9
fun generate(size: Int): List<Lotto> {
return List(size) { Lotto(numberGenerator.generate()) }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정말정말 깔끔하고 좋으네요 😆
(제 취향이므로 반영 안하셔도 됩니다!) 네이밍을 통해 '1~45 사이의 로또 번호를 발급' 한다는 걸 더 티내기 위해 LottoNumberGenerator 와 같이 조금 더 적나라한 네이밍을 쓰는걸 선호합니다 😄

Comment on lines +21 to +22
val luckNumbers = InputView.inputLuckyNumbers()
val statistics = lottoStatisticsService.statistics(luckNumbers, lottoList, inputPayment)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

입력된 당첨 번호가 1~45 사이 숫자가 아닐수도 있겠네요 😄

Comment on lines +12 to +17
return NumberUtil.floor(totalRate, EARING_RATE_DECIMAL_PLACE)
}

companion object {
private const val EARING_RATE_DECIMAL_PLACE = 2
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

소숫점 둘째자리까지 '표현'한다는 것은 다른 녀석에게 더 어울리는 책임이겠죠? 😄

Comment on lines +29 to +34
winLottoStatisticsResult.forEach {
val hitCount = it.winLottoPrize.hitCount
val prizeMoney = it.winLottoPrize.prizeMoney
val winLottoCount = it.winLottoCount
println("${hitCount}개 일치 (${prizeMoney}원) - ${winLottoCount}개")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와 👍 👍 👍 👍 👍 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants