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

Ye6194 #172

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,30 @@ class Lotto(private val numbers: List<Int>) {
- **Git의 커밋 단위는 앞 단계에서 `docs/README.md`에 정리한 기능 목록 단위**로 추가한다.
- [커밋 메시지 컨벤션](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) 가이드를 참고해 커밋 메시지를 작성한다.
- 과제 진행 및 제출 방법은 [프리코스 과제 제출](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) 문서를 참고한다.


## 구현할 기능 목록
1. 로또 구입 금액 입력 후 로또 발행
2. 발행한 로또 번호 오름차순 정렬 후 출력
3. 당첨 번호, 보너스 번호 입력
4. 당첨 내역, 수익률 구한 뒤 출력


## 참고 사이트
enum 클래스
https://www.devkuma.com/docs/kotlin/enum-classes/

비지니스 로직, 도메인 로직
https://velog.io/@eddy_song/domain-logic

단위 테스트
https://velog.io/@seongwon97/Unit-Test-%EB%8B%A8%EC%9C%84-%ED%85%8C%EC%8A%A4%ED%8A%B8

AssertJ
https://www.daleseo.com/assertj/

2차원 배열, List
https://velog.io/@lifeisbeautiful/Kotlin%EC%97%90%EC%84%9C%EC%9D%98-%EB%B0%B0%EC%97%B4%EA%B3%BC-List-Java%EC%99%80-%EC%B0%A8%EC%9D%B4%EC%A0%90

리스트 정렬
https://velog.io/@changhee09/Kotlin-%EB%A6%AC%EC%8A%A4%ED%8A%B8-%EC%A0%95%EB%A0%ACsort-sortBy-sortWith
15 changes: 14 additions & 1 deletion src/main/kotlin/lotto/Application.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
package lotto

fun main() {
TODO("프로그램 구현")
val purchase = PurchaseAmount()
val purchaseAmount = purchase.enterNumber() // 구입횟수

val lottos = Lottos()
val numbers = lottos.getNumbers(purchaseAmount)
lottos.printLottos(numbers) // 오름차순 후 출력

val winningNumber = WinningNumber()
winningNumber.inputWinningNumber()
winningNumber.inputBonusNumber()

val result = Result()
result.printResult()

}
12 changes: 10 additions & 2 deletions src/main/kotlin/lotto/Lotto.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package lotto
import camp.nextstep.edu.missionutils.Randoms

class Lotto(private val numbers: List<Int>) {

class Lotto(private var numbers: List<Int>) { // private 변경 금지, 필드 추가 금지
init {
require(numbers.size == 6)
}
// TODO 1. 숫자 몇개 일치하는지 판단하는 함수
// TODO 2. 1 함수로 수익률 판단

fun matchNumber() {

}

// TODO: 추가 기능 구현
fun profit()
}
24 changes: 24 additions & 0 deletions src/main/kotlin/lotto/Lottos.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package lotto

import camp.nextstep.edu.missionutils.Randoms

class Lottos {
fun getNumbers(purchaseAmount: Int): Array<List<Int>> { // 로또 발행(정렬x)
var sortedLottos = List<Int>(6) { 0 }
var lottos = Array(purchaseAmount) { List(6) { 1 } }

for (i in 0 until purchaseAmount) {
lottos[i] = Randoms.pickUniqueNumbersInRange(1, 45, 6)
lottos[i] = lottos[i].sorted() // 오름차순 정렬
}
return lottos
}

fun printLottos(sortedLottos: Array<List<Int>>) { // (정렬 후) 로또 출력
println()
println("${sortedLottos.size}개를 구입했습니다.")
for (i in sortedLottos.indices)
println(sortedLottos[i])
}

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

import camp.nextstep.edu.missionutils.Randoms

class PurchaseAmount {
var purchaseAmount = 0
fun enterNumber(): Int {
println("구입금액을 입력해 주세요.")
purchaseAmount = readln().toInt() // readln 뭔지 찾아보기
if (purchaseAmount % 1000 != 0)
throw IllegalArgumentException("Error")
return purchaseAmount/1000
}

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

class Result {
fun statistic() {

}

fun printResult() {

println("""
당첨 통계
---
3개 일치 (5,000원) - ${}개
4개 일치 (50,000원) - ${}개
5개 일치 (1,500,000원) - ${}개
5개 일치, 보너스 볼 일치 (30,000,000원) - ${}개
6개 일치 (2,000,000,000원) - ${}개
총 수익률은 ${}%입니다.
""".trimIndent())
}
}
30 changes: 30 additions & 0 deletions src/main/kotlin/lotto/WinningNumber.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lotto

class WinningNumber {
fun inputWinningNumber() {
println()
println("당첨 번호를 입력해주세요.")
val inputWinningNumber = readLine()?.split(",") // "," 기준으로 자름

// TODO 옳지않은 값 들어오면 Exception 처리 구현 (try-catch 이용)
val winningNumber = stringToInt(inputWinningNumber)
//for (i in winningNumber.indices)
// println(winningNumber[i])
}

private fun stringToInt(inputWinningNumber: List<String>?): Array<Int> {
val winningNumber = Array<Int>(6) { 0 }
for (i in inputWinningNumber!!.indices)
winningNumber[i] = inputWinningNumber[i].toInt()
return winningNumber
}

fun inputBonusNumber(): Int {
println()
println("보너스 번호를 입력해 주세요.")
val bonusNumber = readLine()!!.toInt()
// TODO 옳지않은 값 들어오면 Exception 처리 구현 (try-catch)

return bonusNumber
}
}
8 changes: 7 additions & 1 deletion src/test/kotlin/lotto/LottoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package lotto

import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

import org.assertj.core.api.Assertions.*

class LottoTest {
@Test
Expand All @@ -21,4 +21,10 @@ class LottoTest {
}

// 아래에 추가 테스트 작성 가능
@Test
fun `구입 금액의 값이 잘못되면 예외가 발생한다`() {
assertThrows<IllegalArgumentException> {

}
}
}