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단계] 모찌 미션 제출합니다. #150

Open
wants to merge 32 commits into
base: wondroid-world
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
def0f8a
Start step2 from step1
wondroid-world Feb 26, 2025
26230de
feat : 로또 수동 생성 클래스와 로또 자동 생성 클래스 구현
wondroid-world Feb 26, 2025
83f588f
feat: 로또 전체를 발행하는 로직 생성
wondroid-world Feb 27, 2025
b34d365
feat: 로또 티켓 가짜 생성자 구현
wondroid-world Feb 27, 2025
146fcb7
feat: 금액 계산해주는 캐셔 구현
wondroid-world Feb 27, 2025
18d8dce
feat: 금액 계산해주는 캐셔 구현
wondroid-world Feb 27, 2025
7f6c24b
feat: 로또 티켓 count 관리자 구현
wondroid-world Feb 27, 2025
68fbc17
refactor: 입력금액이 천원단위인지 검증하는 로직 삭제
wondroid-world Feb 27, 2025
056b99a
feat: 수동 로또 번호 입력 로직 구현
wondroid-world Feb 27, 2025
29dec2f
feat: 수동을 로또 번호 입력하는 부분 구현
wondroid-world Feb 27, 2025
ceaeb6a
feat: 수동 로또 개수와 자동 로또 개수 계산하는 클래스 구현
wondroid-world Feb 27, 2025
87d9363
refactor: 로또 점원의 역할 세분화
wondroid-world Feb 27, 2025
493bab9
refactor: 자동과 수동 로또 계산과 발행해주는 매니저로 역할 부여
wondroid-world Feb 27, 2025
fe1edd5
refactor: 로또 함수명 변경
wondroid-world Feb 27, 2025
334aebc
refactor: 로또 수동 번호 생성자로 받음
wondroid-world Feb 27, 2025
0d3eb9f
refactor: 로또 생성하는 클래스 함수 정리
wondroid-world Feb 27, 2025
81e54d7
refactor: 로또 생성하는 클래스 함수 파라미터 변경
wondroid-world Feb 27, 2025
3699b71
refactor: winningLotto class가 당첨 결과만 반환하도록 역할 축소
wondroid-world Feb 27, 2025
f8094a5
refactor: controller 순서 변경
wondroid-world Feb 27, 2025
38eef1b
fix: 로또 정렬 순서 변경
wondroid-world Feb 27, 2025
aeaeb8d
refactor: 문장마다 띄어쓰기 변경
wondroid-world Feb 27, 2025
63062df
feat: 논리 오륲일 때 예외 출력
wondroid-world Feb 27, 2025
74b1eb1
feat: 논리적 오류일때 예외 출력
wondroid-world Feb 27, 2025
468054d
Merge branch 'wondroid-world' into step2
wondroid-world Feb 27, 2025
0f60f16
refactor: klintFormat에 맞게 수정
wondroid-world Mar 3, 2025
ea357f9
feat: 로또 타입 출력
wondroid-world Mar 3, 2025
eba7611
refactor: 변수명 변경
wondroid-world Mar 3, 2025
d2499d4
refactor: 문자열 상수화
wondroid-world Mar 3, 2025
8941fd9
fix: 로또 test 로직 수정
wondroid-world Mar 3, 2025
9eec7d8
fix: 수동 로또 발행 개수는 0이상이면 가능
wondroid-world Mar 3, 2025
0174611
fix: 로또 자동 발행 개수 반환
wondroid-world Mar 3, 2025
6484553
feat: 사용자의 입력이 잘 못될 때, 재입력 받도록 구현
wondroid-world Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 43 additions & 14 deletions src/main/kotlin/lotto/controller/LottoController.kt
Original file line number Diff line number Diff line change
@@ -1,39 +1,68 @@
package lotto.controller

import lotto.contants.LottoRuleConstants
import lotto.model.LottoMachine
import lotto.model.LottoIssueType
import lotto.model.LottoResult
import lotto.model.LottoStoreCashier
import lotto.model.LottoTicket
import lotto.model.LottoTicketIssueManager
import lotto.model.WinningLotto
import lotto.view.UserInterface

class LottoController(
private val userInterface: UserInterface = UserInterface(),
) {
Comment on lines 11 to 13
Copy link
Member

Choose a reason for hiding this comment

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

45 이상의 숫자를 입력하면 앱이 죽도록 되어 있군요~
이부분은 요구사항에 없긴 한데, 한번 고민해보면 좋을 것 같은 내용인 것 같아서 코멘트 남겨두었습니다!
재 입력을 받도록 해볼 수도 있겠다는 생각도 드는군요!💪

(수정이 이루어져야 하는 것은 아니고 어떻게 하면 해당 기능을 구현할 수 있을지 모찌의 의견을 남겨주셔도 좋을 것 같습니다)

fun run() {
val lottoTickets = generateLottoTickets()
val possibleToLottoTicketCount = meetLottoStoreCashier()
val lottoTickets = getLottoTickets(possibleToLottoTicketCount)
val winningLotto = getWinningLotto()
val lottoResult = winningLotto.getResult(lottoTickets)
getResult(lottoResult)
getResult(lottoTickets, winningLotto)
}

private fun generateLottoTickets(): List<LottoTicket> {
val amount = userInterface.inputPurchaseAmount()
val count = calculatePurchaseCount(amount)
val lottoTickets = LottoMachine().purchase(count)
userInterface.printLottoTickets(lottoTickets)
return lottoTickets
private fun meetLottoStoreCashier(): Int {
val money = userInterface.inputPurchaseAmount()
val lottoStoreCashier = LottoStoreCashier(money)
val possibleToLottoTicketCount = lottoStoreCashier.calculatePossibleToBuyLottoTicketCount()
val customerAnswer = userInterface.printLottoCount(possibleToLottoTicketCount)
if (customerAnswer) {
val change = lottoStoreCashier.calculateChange(possibleToLottoTicketCount)
userInterface.printChange(change)
}
return possibleToLottoTicketCount
}

private fun calculatePurchaseCount(amount: Int) = amount / LottoRuleConstants.LOTTO_AMOUNT.value
private fun getLottoTickets(possibleToLottoTicketCount: Int): List<LottoTicket> {
val customerWantToBuyManualLottoTicketCount = userInterface.getManualLottoCount()
val manualLottoNumbers =
if (customerWantToBuyManualLottoTicketCount != 0) {
userInterface.getManualLottoNumbers(customerWantToBuyManualLottoTicketCount)
} else {
emptyList()
}
val lottoTicketIssueManager =
LottoTicketIssueManager(
possibleToLottoTicketCount,
customerWantToBuyManualLottoTicketCount,
manualLottoNumbers,
)
val lottoTickets = lottoTicketIssueManager.getLottoTickets(manualLottoNumbers)
val autoLottoTicketCount = lottoTicketIssueManager.getCustomerWantToBuyManualLottoTicketCount()
userInterface.printLottoTickets(customerWantToBuyManualLottoTicketCount, autoLottoTicketCount, lottoTickets)
return lottoTickets
}

private fun getWinningLotto(): WinningLotto {
val winningNumbers = userInterface.getWinningNumbers()
val bonusNumber = userInterface.getBonusNumber()
return WinningLotto(winningNumbers, bonusNumber)
val winningLottoTicket = LottoTicket(LottoIssueType.WINNING, winningNumbers)
return WinningLotto(winningLottoTicket, bonusNumber)
}

private fun getResult(lottoResult: LottoResult) {
private fun getResult(
lottoTickets: List<LottoTicket>,
winningLotto: WinningLotto,
) {
val ranks = winningLotto.getRanks(lottoTickets)
val lottoResult = LottoResult(ranks)
val winningStatus = lottoResult.getWinningStatus()
val profit = lottoResult.calculateProfit()
userInterface.printResult(winningStatus)
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/lotto/model/AutoLottoTicketGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package lotto.model

import lotto.contants.LottoRuleConstants

class AutoLottoTicketGenerator : LottoTicketGenerator {
override val type: LottoIssueType = LottoIssueType.AUTO

Comment on lines +5 to +7
Copy link
Member

Choose a reason for hiding this comment

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

Generator는 생성자인데, model 에 있는것이 좋을까 싶긴 합니다!
다른 패키지로 옮긴다면 어떤 패키지로 옮겨볼 수 있을까요?🤔

override fun generateLottoTicket(): LottoTicket {
val lottoNumbers =
(LottoRuleConstants.MINIMUM_NUMBER.value..LottoRuleConstants.MAXIMUM_NUMBER.value)
.shuffled()
.take(LottoRuleConstants.LOTTO_PICK_COUNT.value)
.sorted()
.map(::LottoNumber)
return LottoTicket(LottoIssueType.AUTO, lottoNumbers)
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/lotto/model/LottoIssueType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package lotto.model

enum class LottoIssueType(
val issueType: String,
) {
AUTO("자동"),
MANUAL("수동"),
WINNING("당첨"),
}
21 changes: 20 additions & 1 deletion src/main/kotlin/lotto/model/LottoMachine.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
package lotto.model

// 로또 발행하는 머신
class LottoMachine {
fun purchase(count: Int): List<LottoTicket> = List(count) { LottoTicket() }
Copy link
Member

Choose a reason for hiding this comment

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

LottoMachine을 통해서 로또를 생성하는군요!
LottoMachine을 통해서 수동 로또 / 자동 로또가 재대로 생성되는지에 대한 테스트를 해볼 수 있겠군요💪

// 로또 티켓을 발행한다.
Comment on lines 4 to +5
Copy link
Member

Choose a reason for hiding this comment

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

class외에 object라는 키워드가 있는데, 이둘은 어떤 차이점이 있을까요?🤔
모찌의 생각을 남겨주세요!
각 두개의 키워드는 어떤 경우에 사용하면 좋을까요?

fun issueLottoTickets(
customerWantToBuyAutoLottoTicketCount: LottoTicketCount,
manualLottoNumbers: List<List<Int>>,
): List<LottoTicket> = purchaseManualLottoTickets(manualLottoNumbers) + purchaseAutoLottoTickets(customerWantToBuyAutoLottoTicketCount)

// 자동 로또를 발행
private fun purchaseAutoLottoTickets(customerWantToBuyAutoLottoTicketCount: LottoTicketCount): List<LottoTicket> {
val autoLottoGenerator = AutoLottoTicketGenerator()
val autoLottoTickets =
List(customerWantToBuyAutoLottoTicketCount.toInt()) { autoLottoGenerator.generateLottoTicket() }
return autoLottoTickets
}

// 수동 로또를 발행
private fun purchaseManualLottoTickets(manualLottoNumbers: List<List<Int>>): List<LottoTicket> {
val manualLottoTickets = manualLottoNumbers.map { ManualLottoTicketGenerator(it).generateLottoTicket() }
return manualLottoTickets
}
Comment on lines +11 to +23
Copy link
Member

Choose a reason for hiding this comment

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

타입별 로또 티켓에 대한 생성자 좋습니다~👍

}
29 changes: 29 additions & 0 deletions src/main/kotlin/lotto/model/LottoStoreCashier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package lotto.model

import lotto.contants.LottoRuleConstants

// 돈 계산을 해주는 클래스
class LottoStoreCashier(
Comment on lines +5 to +6
Copy link
Member

Choose a reason for hiding this comment

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

주석을 이렇게 추가하신 이유가 있을까요??
어떤 부분에는 있고 어떤 부분에는 없어서요~

Copy link
Author

Choose a reason for hiding this comment

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

개인적으로 이번 미션에서 목표가 객체지향적인 설계에 대해서 생각해보고 적용해보는 것입니다. 책에서 객체 하나당 한 역할을 하는 유기체라고 생각하라는 문구를 보았습니다. 그래서, 스스로 이 클래스는 무슨 역할을 한다고 정의하고 싶어서 주석을 추가했습니다. 😆

Copy link
Member

Choose a reason for hiding this comment

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

그래서 주석이 있는 객체가 존재하고 없는 객체가 존재했군요~

private val customerMoney: Int,
) {
private val possibleToLottoTicketCount = calculatePossibleToBuyLottoTicketCount()

// 로또의 가격은 천원이다. 로또를 구매할려면 천원이상 넣어야한다.
init {
require(customerMoney >= LottoRuleConstants.LOTTO_AMOUNT.value) { INSUFFICIENT_MONEY_FOR_LOTTO_PURCHASE }
}

// 고객이 준 돈에서 몇장을 살 수 있는 지 계산한다.
fun calculatePossibleToBuyLottoTicketCount(): Int = customerMoney / LottoRuleConstants.LOTTO_AMOUNT.value

// 고객이 몇장을 사고 싶다고 이야기를 하면 가능한지 계산한다.
fun isPossibleToBuy(customerWantBuyLottoTicketCount: Int): Boolean = possibleToLottoTicketCount >= customerWantBuyLottoTicketCount

// 고객에게 전달할 잔돈을 계산한다.
fun calculateChange(customerWantBuyLottoTicketCount: Int): Int =
customerMoney - (LottoRuleConstants.LOTTO_AMOUNT.value * possibleToLottoTicketCount)

companion object {
private const val INSUFFICIENT_MONEY_FOR_LOTTO_PURCHASE = "로또는 천원이상 넣어야지 구매 가능합니다."
}
Comment on lines +11 to +28
Copy link
Member

Choose a reason for hiding this comment

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

이전 코멘트
해당 코멘트를 통해서 주석을 남겨주신 이유에 대해서는 너무 잘 이해를 했습니다!

다만, 한가지 고민을 해보면 좋을 것 같아서 코멘트를 남겨두었습니다~
복잡한 로직에 대해서는 주석을 남겨두면 어떤 로직인지에 대한 이해가 잘되도록 돕습니다.
그러나, 함수명 or 구현된 코드를 보고도 유추할 수 있는 모든 내용들에 주석이 존재한다면 오히려 구현을 이해하는데 혼동을 줄 수도 있기는 해서 추후 개발을 하면서 어떤 부분에 남겨야할지 모찌만의 기준을 잘 잡으셨으면 좋겠습니다💪

}
35 changes: 21 additions & 14 deletions src/main/kotlin/lotto/model/LottoTicket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,35 @@ package lotto.model
import lotto.contants.LottoRuleConstants

class LottoTicket(
private val numbers: Set<LottoNumber> = generateLotto(),
val lottoIssueType: LottoIssueType,
private val numbers: List<LottoNumber>,
) {
private val lottoNumbers: Set<LottoNumber> = numbers.toSet()

init {
require(numbers.size == LottoRuleConstants.LOTTO_PICK_COUNT.value)
{ ERROR_NUMBERS_COUNT }
require(numbers.size == LottoRuleConstants.LOTTO_PICK_COUNT.value) { ERROR_NUMBERS_COUNT }
}

fun getSize() = lottoNumbers.size

fun containsNumber(number: LottoNumber): Boolean {
return lottoNumbers.contains(number)
}

fun getSize() = numbers.size
fun getNumbers(): Set<LottoNumber> {
return lottoNumbers
}

fun getNumbers() = numbers
fun matchNumbersSize(lottoTicket: LottoTicket) = numbers.intersect(lottoTicket.getNumbers()).size
Comment on lines -15 to +25
Copy link
Member

Choose a reason for hiding this comment

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

로또가 몇개가 맞는지에 대한 로직이 LottoTicket 내로 이동을 한 이유가 궁금합니다~🤔

Copy link
Author

Choose a reason for hiding this comment

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

로또 번호가 몇 개 맞는지에 대한 로직이 LottoTicket으로 이동한 이유는 책임의 분리(SRP) 원칙을 따르기 위해서입니다.

WinningLotto 클래스는 "당첨된 로또 티켓과 다른 로또 티켓들을 비교"하는 책임을 가집니다. 이 클래스는 당첨 결과를 확인하는 역할에 집중해야 하며, 실제로 번호를 맞추는 로직은 LottoTicket 객체가 처리해야 할 일이라고 생각했습니다.

LottoTicket 클래스는 로또 번호를 담고 있는 객체로, 자신에게 맞는 번호가 몇 개인지 확인하는 역할을 맡는 것이 자연스럽다고 생각했습니다.

WinningLotto의 관심사는 "당첨된 로또 티켓과 비교하여 몇 등인지 확인하는 것"이지, 어떻게 번호가 맞는지를 구현하는 것은 LottoTicket의 책임이라고 생각햅니다. 각 객체는 자신의 책임에만 집중해야 하기 위해서, LottoTicket 내로 함수를 이동시켰습니다.

Copy link
Member

Choose a reason for hiding this comment

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

WinningLotto는 로또의 당첨 번호만을 관리하고 LottoTicket 에서 내 번호가 당첨됐는지를 판별하도록 하셨군요~
모찌의 생각을 잘 알 수 있어서 좋네요!👍


companion object {
private const val ERROR_NUMBERS_COUNT = "로또 번호의 개수는 6개입니다."

private fun generateLotto(): Set<LottoNumber> =
(LottoRuleConstants.MINIMUM_NUMBER.value..LottoRuleConstants.MAXIMUM_NUMBER.value)
.shuffled()
.take(LottoRuleConstants.LOTTO_PICK_COUNT.value)
.sorted()
.map { LottoNumber(it) }
.toSet()

fun create(vararg lottoNumbers: LottoNumber): LottoTicket = LottoTicket(lottoNumbers.toSet())
fun create(
lottoIssueType: LottoIssueType,
vararg lottoNumbers: Int,
): LottoTicket {
return LottoTicket(lottoIssueType, lottoNumbers.map { LottoNumber(it) })
}
}
}
17 changes: 17 additions & 0 deletions src/main/kotlin/lotto/model/LottoTicketCount.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package lotto.model

import lotto.contants.LottoRuleConstants

class LottoTicketCount(
private val count: Int,
) {
init {
require(count >= LottoRuleConstants.ZERO.value) { LOTTO_TICKET_COUNT_NOT_NEGATIVE }
}

fun toInt() = count

Comment on lines +12 to +13
Copy link
Member

Choose a reason for hiding this comment

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

toInt()로 표현을 하면, 어떤 것을 나타내는지에 대해서 불명확해질 수도 있겠다는 생각도 들긴 하네요!
다른 객체들에서 적용한 것처럼 해당 함수의 네이밍을 유의미하게 변경해볼 수 있겠다는 생각이 듭니다💪

companion object {
private const val LOTTO_TICKET_COUNT_NOT_NEGATIVE = "로또 구매 장 수는 음수가 될수 없습니다."
}
}
7 changes: 7 additions & 0 deletions src/main/kotlin/lotto/model/LottoTicketGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lotto.model

interface LottoTicketGenerator {
val type: LottoIssueType

fun generateLottoTicket(): LottoTicket
}
29 changes: 29 additions & 0 deletions src/main/kotlin/lotto/model/LottoTicketIssueManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package lotto.model

// 수동이랑 자동 로또 계산해주는 매니저, 로또 티켓까지 주는 역할 담당
class LottoTicketIssueManager(
totalCount: Int,
manualCount: Int,
manualLottoNumbers: List<List<Int>>,
) {
private val manualLottoTicketCount = LottoTicketCount(manualCount)
private val autoLottoTicketCount =
LottoTicketCount(totalCount - manualCount)

// 발행가능한 개수보다 수동으로 로또 발행받고 싶은 개수가 크면 안된다.
init {
require(totalCount >= manualCount) { EXCEEDED_MANUAL_LOTTO_COUNT }
require(manualCount == manualLottoNumbers.size) { LOTTO_COUNT_NOT_MATCH_LOTTO_NUMBERS }
}

// 로또를 발행해서 준다.
fun getLottoTickets(manualLottoNumbers: List<List<Int>>): List<LottoTicket> =
LottoMachine().issueLottoTickets(autoLottoTicketCount, manualLottoNumbers)

fun getCustomerWantToBuyManualLottoTicketCount(): Int = autoLottoTicketCount.toInt()

Comment on lines +23 to +24
Copy link
Member

Choose a reason for hiding this comment

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

해당 함수의 네이밍을 아래와 같이 수정을 할수도 있을 것 같은데, 모찌의 생각에는 어떤 네이밍이 좋을 것 같나요🤔
물론 정답은 없습니다~
getAutoLottoTicketCount()

companion object {
private const val LOTTO_COUNT_NOT_MATCH_LOTTO_NUMBERS = "수동 구매 개수와 수동 번호 입력 개수가 일치하지 않습니다."
private const val EXCEEDED_MANUAL_LOTTO_COUNT = "전체 발행 가능한 로또 개수보다 수동로또 발행 개수가 더 많습니다."
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/lotto/model/ManualLottoTicketGenerator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package lotto.model

class ManualLottoTicketGenerator(
private val numbers: List<Int>,
) : LottoTicketGenerator {
override val type: LottoIssueType = LottoIssueType.MANUAL

override fun generateLottoTicket(): LottoTicket = LottoTicket(LottoIssueType.MANUAL, numbers.map(::LottoNumber))
}
32 changes: 17 additions & 15 deletions src/main/kotlin/lotto/model/WinningLotto.kt
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
package lotto.model

import lotto.contants.LottoRuleConstants.LOTTO_PICK_COUNT

// 당첨 번호 확인하는 로직
class WinningLotto(
private val winningNumbers: Set<LottoNumber>,
private val winningLottoTicket: LottoTicket,
private val bonusNumber: LottoNumber,
) {
init {
require(winningNumbers.size == LOTTO_PICK_COUNT.value) { ERROR_NUMBERS_COUNT }
require(!winningNumbers.contains(bonusNumber)) { ERROR_LOTTO_NUMBERS_NOT_CONTAIN_BONUS_NUMBER }
require(!winningLottoTicket.containsNumber(bonusNumber)) { ERROR_LOTTO_NUMBERS_NOT_CONTAIN_BONUS_NUMBER }
}

fun getResult(lottoTickets: List<LottoTicket>): LottoResult {
val result = lottoTickets.map { getRank(it) }
return LottoResult(result)
}
// 전체 당첨 확인 결과 반환
fun getRanks(lottoTickets: List<LottoTicket>): List<Rank> = lottoTickets.map { getRank(it) }

fun getRank(lottoTicket: LottoTicket): Rank {
// 몇 등에 당첨 되었는 지 확인
private fun getRank(lottoTicket: LottoTicket): Rank {
val countOfMatch: Int = getCountOfMatch(lottoTicket)
val matchBonus: Boolean = getMatchBonus(lottoTicket)
return Rank.valueOf(countOfMatch, matchBonus)
}

private fun getCountOfMatch(lottoTicket: LottoTicket): Int = winningNumbers.intersect(lottoTicket.getNumbers()).size
// 몇 개 맞는 지 확인
private fun getCountOfMatch(lottoTicket: LottoTicket): Int = winningLottoTicket.matchNumbersSize(lottoTicket)

private fun getMatchBonus(lottoTicket: LottoTicket): Boolean = lottoTicket.getNumbers().contains(bonusNumber)
// 보너스 번호 확인
private fun getMatchBonus(lottoTicket: LottoTicket): Boolean = lottoTicket.containsNumber(bonusNumber)

companion object {
private const val ERROR_NUMBERS_COUNT = "로또 번호의 개수는 6개입니다."
private const val ERROR_LOTTO_NUMBERS_NOT_CONTAIN_BONUS_NUMBER = "로또 당첨 번호는 보너스 번호를 포함하지 말아야합니다."

fun create(vararg lottoNumbers: LottoNumber, bonusNumber: LottoNumber): WinningLotto {
return WinningLotto(lottoNumbers.toSet(), bonusNumber)
fun create(
vararg lottoNumbers: Int,
bonusNumber: Int,
): WinningLotto {
val winningNumbers = LottoTicket(LottoIssueType.WINNING, lottoNumbers.map { LottoNumber(it) })
return WinningLotto(winningNumbers, LottoNumber(bonusNumber))
}
}
}
8 changes: 1 addition & 7 deletions src/main/kotlin/lotto/view/InputValidator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,10 @@ class InputValidator {

fun validateOverZero(input: String) = require(input.toInt() > LottoRuleConstants.ZERO.value) { ERROR_INVALID_OVER_ZERO }

fun validateAmountUnits1000(input: String) =
require(
input.toInt() % LottoRuleConstants.LOTTO_AMOUNT.value == LottoRuleConstants.ZERO.value,
) {
ERROR_INVALID_DIVISION
}
fun validateNoNegativeNumber(input: String) = require(input.toInt() >= LottoRuleConstants.ZERO.value) { ERROR_INVALID_OVER_ZERO }

companion object {
private const val ERROR_INVALID_INTEGER = "정수를 입력해야 합니다."
private const val ERROR_INVALID_OVER_ZERO = "구입금액은 0보다 커야 합니다."
private const val ERROR_INVALID_DIVISION = "구입금액은 1000의 배수여야 합니다."
}
}
4 changes: 3 additions & 1 deletion src/main/kotlin/lotto/view/OutputView.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package lotto.view

object OutputView {
fun printMessage(msg: Any) = println(msg)
fun printlnMessage(msg: Any) = println(msg)

fun printMessage(msg: Any) = print(msg)
}
Comment on lines 3 to 7
Copy link
Member

Choose a reason for hiding this comment

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

OutputView와 InputView에서 너무 담당을 하는 것이 없다는 생각이 드네요..😅
UserInterface에서 입출력에 대해서 모든 기능을 담당하고 있으므로, 해당 InputView / OutputView의 내용을 UserInterface의 하나의 함수로 만들어 보는 것이 나을 수도 있겠다는 생각이 듭니다!

Loading