-
Notifications
You must be signed in to change notification settings - Fork 357
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 수동 로또 #1134
base: goodbyeyo
Are you sure you want to change the base?
Step4 수동 로또 #1134
Changes from all commits
99369f0
005d6e4
e7da511
bce5ce9
89f9d1c
d978556
847f352
86bc2a4
86f6958
caac3eb
6f6d991
57f7cea
b0d50ff
2eedaa5
74cdcd6
262e88d
e9abd55
6677340
e2fddbb
a115791
cfee66b
c6f4996
3e9cf86
84a5ddf
07bd5fb
08c5320
69535ed
82770fe
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,14 +1,7 @@ | ||
package lotto | ||
|
||
import lotto.controller.LottoController | ||
import lotto.view.InputView | ||
import lotto.view.OutputView | ||
|
||
fun main() { | ||
val amount = InputView.getUserAmount() | ||
val lottoTickets = LottoController.purchaseLotto(amount) | ||
OutputView.printPurchaseResult(lottoTickets) | ||
val winningLotto = InputView.getUserWinningLotto() | ||
val lottoResults = LottoController.calculateLottoRank(lottoTickets, winningLotto) | ||
OutputView.printResults(lottoResults, amount) | ||
LottoController.startLottoGame() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
package lotto.controller | ||
|
||
import lotto.domain.LottoResults | ||
import lotto.domain.LottoTickets | ||
import lotto.domain.WinningLotto | ||
import lotto.view.InputView | ||
import lotto.view.OutputView | ||
|
||
object LottoController { | ||
fun purchaseLotto(amount: Int): LottoTickets { | ||
return LottoTickets.purchase(amount) | ||
} | ||
|
||
fun calculateLottoRank( | ||
lottoTickets: LottoTickets, | ||
winningLotto: WinningLotto, | ||
): LottoResults { | ||
return lottoTickets.calculateLottoRank(winningLotto) | ||
fun startLottoGame() { | ||
val purchasedDetail = InputView.getPurchaseDetail() | ||
val autoLottoTickets = LottoTickets.generateAutoLottoTickets(purchasedDetail.autoLottoQuantity) | ||
val lottoTickets = LottoTickets(purchasedDetail.manualLottoTickets + autoLottoTickets) | ||
OutputView.printPurchaseResult(lottoTickets, purchasedDetail) | ||
val winningLotto = InputView.getUserWinningLotto() | ||
val lottoResults = lottoTickets.calculateLottoRank(winningLotto) | ||
OutputView.printResults(lottoResults, purchasedDetail.purchaseAmount) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package lotto.domain | ||
|
||
class Money(money: String) { | ||
val amount: Int = money.toIntOrNull() ?: throw IllegalArgumentException("구입 금액이 유효하지 않습니다. 숫자를 입력해주세요") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package lotto.dto | ||
|
||
import lotto.domain.LottoTickets | ||
import lotto.domain.LottoTickets.Companion.LOTTO_TICKET_PRICE | ||
import lotto.domain.Money | ||
|
||
data class PurchaseDetail( | ||
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.
https://velog.io/@paulus0617/kotlin-getter-setter 요글을 읽어보시면 그래서 코틀린 진영에서는 필드가 아닌 프로퍼티라는 네이밍으로 사용하고 있습니다 :) 디컴파일 해보시면 실제 javaCode에서는 혹시 제가 질문을 잘 못이해한거라면 다시한번 말씀부탁드림니다! |
||
val purchaseAmount: 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. https://edu.nextstep.camp/s/l3Ppxbm8/ls/ROS71xiT 에 보면 |
||
val autoLottoQuantity: Int, | ||
val manualLottoQuantity: Int, | ||
val manualLottoTickets: LottoTickets, | ||
) { | ||
init { | ||
require(manualLottoQuantity * LOTTO_TICKET_PRICE <= purchaseAmount) { "수동으로 구입할 로또의 수량이 구입금액보다 많습니다" } | ||
require(autoLottoQuantity <= purchaseAmount / LOTTO_TICKET_PRICE) { "자동으로 구입할 로또의 수량이 구입금액보다 많습니다" } | ||
} | ||
constructor( | ||
money: Money, | ||
manualLottoTickets: LottoTickets, | ||
) : this( | ||
money.amount, | ||
money.amount / LOTTO_TICKET_PRICE - manualLottoTickets.size, | ||
manualLottoTickets.size, | ||
manualLottoTickets, | ||
) | ||
|
||
companion object { | ||
fun of( | ||
money: Money, | ||
manualLottoTickets: LottoTickets, | ||
): PurchaseDetail { | ||
return PurchaseDetail( | ||
money.amount, | ||
money.amount / LOTTO_TICKET_PRICE - manualLottoTickets.size, | ||
manualLottoTickets.size, | ||
manualLottoTickets, | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,19 +2,47 @@ package lotto.view | |
|
||
import lotto.domain.LottoNumber | ||
import lotto.domain.LottoTicket | ||
import lotto.domain.LottoTickets | ||
import lotto.domain.Money | ||
import lotto.domain.WinningLotto | ||
import lotto.dto.PurchaseDetail | ||
|
||
object InputView { | ||
fun getUserAmount(): Int { | ||
private const val DELIMITER = "," | ||
|
||
fun getPurchaseDetail(): PurchaseDetail { | ||
val money = getPurchaseAmount() | ||
val manualLottoQuantity = getManualLottoQuantity() | ||
val manualLottoTickets = getManualLottoTickets(manualLottoQuantity) | ||
return PurchaseDetail.of(money, manualLottoTickets) | ||
} | ||
|
||
private fun getManualLottoTickets(manualLottoQuantity: Int): LottoTickets { | ||
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. LottoTicket을 만드는 책임이 View에 있는 것 같아요! 자동로또와 동일�한 레벨로 옮겨보면 어떨까요? |
||
println("수동으로 구매할 번호를 입력해 주세요.") | ||
val manualLottoTickets = | ||
List(manualLottoQuantity) { | ||
val readLine = readlnOrNull()?.takeIf { it.isNotBlank() } ?: throw IllegalArgumentException("로또 번호를 입력해주세요.") | ||
LottoTicket.makeLottoTicket(readLine) | ||
} | ||
return LottoTickets(manualLottoTickets) | ||
} | ||
|
||
private fun getManualLottoQuantity(): Int { | ||
println("수동으로 구매할 로또 수를 입력해 주세요.") | ||
val quantity = readln() | ||
return quantity.toIntOrNull() ?: throw IllegalArgumentException("유효한 숫자를 입력해주세요") | ||
} | ||
|
||
private fun getPurchaseAmount(): Money { | ||
println("구입 금액을 입력해 주세요.") | ||
val amount = readln() | ||
return amount.toIntOrNull() ?: throw IllegalArgumentException("구입 금액이 유효하지 않습니다. 숫자를 입력해주세요") | ||
return Money(amount) | ||
} | ||
|
||
fun getUserWinningLotto(): WinningLotto { | ||
println("지난 주 당첨 번호를 입력해 주세요.") | ||
val winningLottoNumbers: String = readln() | ||
val numbers = winningLottoNumbers.split(",").map { it.toInt() }.toSet() | ||
val numbers = winningLottoNumbers.split(DELIMITER).map { it.toInt() }.toSet() | ||
|
||
println("보너스 볼을 입력해 주세요.") | ||
val bonusNumber: String = readln() | ||
|
This file was deleted.
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.
해당 함수는 이제 미사용으로 보이네요! :)