-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
83 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package lotto | ||
|
||
class Lotto { | ||
class Lotto( | ||
val numbers: List<Int> = generateLottoNumbers(), | ||
var matchCount: Int = 0 | ||
) { | ||
|
||
val numbers: List<Int> = generateLottoNumbers() | ||
companion object { | ||
const val PRICE: Int = 1000 | ||
} | ||
|
||
fun match(target: Lotto) { | ||
matchCount = numbers.intersect(target.numbers).count() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package lotto | ||
|
||
fun main(args: Array<String>) { | ||
println("구매금액을 입력해주세요.") | ||
var inputMoney = readLine()!!.toInt() | ||
|
||
val lottoBuyer = LottoBuyer(inputMoney) | ||
val lottos = lottoBuyer.buyLottoFrom(LottoStore()) | ||
|
||
println(String.format("%s개를 구매했습니다.", lottos.size)) | ||
lottos.forEach { lotto -> | ||
println(lotto.numbers) | ||
} | ||
|
||
println("지난 주 당첨 번호를 입력해주세요.") | ||
val lastWeekWinningNumbers = readLine()!!.split(", ").map { it.toInt() } | ||
|
||
lottos.forEach { lotto -> | ||
lotto.match(Lotto(lastWeekWinningNumbers)) | ||
} | ||
|
||
println("당첨 통계") | ||
println("---------") | ||
println("3개 일치 (5000원) - ${lottos.count { it.matchCount == 3 }}개") | ||
println("4개 일치 (50000원) - ${lottos.count { it.matchCount == 4 }}개") | ||
println("5개 일치 (1500000원) - ${lottos.count { it.matchCount == 5 }}개") | ||
println("6개 일치 (2000000000원) - ${lottos.count { it.matchCount == 6 }}개") | ||
println("총 수익률은 ${lottos.size * Lotto.PRICE / inputMoney}입니다.") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters