From b05cab017bf1cb43c54ba43c44d8891dcca1ab77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Wed, 23 Oct 2024 21:14:46 +0900 Subject: [PATCH 01/17] =?UTF-8?q?docs:=20README.md=EC=97=90=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=ED=95=A0=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=EC=9D=84=20=EC=A0=95=EB=A6=AC=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 62fa463c..97d321ca 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ # kotlin-racingcar-precourse + +## 구현할 기능 목록 +- [ ] 자동차 이름 분류 +- [ ] 랜덤 이동값 +- [ ] 자동차 이동 +- [ ] 실행 결과 출력 +- [ ] 승리자 계산 + +### 테스트 +- [ ] 정상적인 입력에서 잘 기능하는지 +- [ ] 잘못입력하였을 경우 +- [ ] 공동 우승일 경우 \ No newline at end of file From ac017e5cab5ab12c01630e581fdb53cb483d2a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 14:39:40 +0900 Subject: [PATCH 02/17] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=ED=95=9C=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- src/main/kotlin/racingcar/Application.kt | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 97d321ca..bbb74f45 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # kotlin-racingcar-precourse ## 구현할 기능 목록 -- [ ] 자동차 이름 분류 +- [x] 자동차 이름 분류 + - [ ] 5자까지만 가능 - [ ] 랜덤 이동값 - [ ] 자동차 이동 - [ ] 실행 결과 출력 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 0d8f3a79..46b1deb4 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -2,4 +2,7 @@ package racingcar fun main() { // TODO: 프로그램 구현 + val inputValue = readLine() + val cars = inputValue?.split(',') + } From c8a6055e468558b9ac5e894c6560cc2c5f352abf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 15:16:59 +0900 Subject: [PATCH 03/17] =?UTF-8?q?feat:=20=EC=8B=9C=EB=8F=84=ED=95=A0=20?= =?UTF-8?q?=ED=9A=9F=EC=88=98=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 ++++-- src/main/kotlin/racingcar/Application.kt | 10 ++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index bbb74f45..0005d878 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,10 @@ ## 구현할 기능 목록 - [x] 자동차 이름 분류 - - [ ] 5자까지만 가능 -- [ ] 랜덤 이동값 + - [ ] (예외) 5자이상인경우 +- [x] 랜덤 이동값 + - [ ] (예외) 숫자가 아닌 경우 + - [ ] 자동차 이동 - [ ] 실행 결과 출력 - [ ] 승리자 계산 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 46b1deb4..4d21269d 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -2,7 +2,13 @@ package racingcar fun main() { // TODO: 프로그램 구현 - val inputValue = readLine() - val cars = inputValue?.split(',') + println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + val inputCar = readLine() + val cars = inputCar?.split(',') + + + println("시도할 횟수는 몇 회인가요?") + val inputCount = readLine() + val count = inputCount } From 48f0460e046a02866d697b12a3456a888aad0b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:06:30 +0900 Subject: [PATCH 04/17] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 17 ++++++++++------ src/main/kotlin/racingcar/Application.kt | 25 ++++++++++++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 0005d878..d2c92401 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,20 @@ # kotlin-racingcar-precourse ## 구현할 기능 목록 -- [x] 자동차 이름 분류 - - [ ] (예외) 5자이상인경우 -- [x] 랜덤 이동값 - - [ ] (예외) 숫자가 아닌 경우 +- [x] 자동차 이름 분류 + - [ ] (예외) 5자이상인경우 +- [x] 이동할 횟수 + - [ ] (예외) 숫자가 아닌 경우 + +- [x] 랜덤 이동값 + - [x] 자동차 개수만큼 이동한 횟수 배열 생성 + - [x] 4이상일 경우 이동 + - [x] 실행 결과 출력 -- [ ] 자동차 이동 -- [ ] 실행 결과 출력 - [ ] 승리자 계산 +- [ ] depth 2이하 + ### 테스트 - [ ] 정상적인 입력에서 잘 기능하는지 - [ ] 잘못입력하였을 경우 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 4d21269d..65ac902f 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -1,14 +1,31 @@ package racingcar +import camp.nextstep.edu.missionutils.Randoms +import camp.nextstep.edu.missionutils.Console + fun main() { // TODO: 프로그램 구현 println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") - val inputCar = readLine() - val cars = inputCar?.split(',') + val inputCar = Console.readLine() + val cars = inputCar.split(',') println("시도할 횟수는 몇 회인가요?") - val inputCount = readLine() - val count = inputCount + val inputCount = Console.readLine() + val count = inputCount.toInt() + + println("실행 결과") + + val carsMovings = Array(cars.count()) { 0 } + for (i in 0 until count){ + for(j in 0 until cars.count()){ + if(Randoms.pickNumberInRange(0,9) >= 4){ + //이동 + carsMovings[j] += 1 + } + println("${cars[j]} : ${"-".repeat(carsMovings[j])}") + } + println() + } } From 0f70d83c04263da0daee64889ce645a4af07791b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 16:32:28 +0900 Subject: [PATCH 05/17] =?UTF-8?q?feat:=20=EC=B5=9C=EC=A2=85=20=EC=9A=B0?= =?UTF-8?q?=EC=8A=B9=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++- src/main/kotlin/racingcar/Application.kt | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d2c92401..86498c3a 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,8 @@ - [x] 4이상일 경우 이동 - [x] 실행 결과 출력 -- [ ] 승리자 계산 +- [x] 최종 우승자 + - [x] 공동 우승자면 함께 - [ ] depth 2이하 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 65ac902f..ffecb342 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -3,6 +3,25 @@ package racingcar import camp.nextstep.edu.missionutils.Randoms import camp.nextstep.edu.missionutils.Console + +fun getWinnerIndex(carsMovings : Array): MutableList { + val winners = mutableListOf() + var maxNumber = 0 + + carsMovings.forEachIndexed { idx, it -> + if(it == maxNumber){ + winners.addLast(idx) + } + if(it > maxNumber){ + maxNumber = it + winners.clear() + winners.addLast(idx) + } + } + + return winners +} + fun main() { // TODO: 프로그램 구현 println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") @@ -28,4 +47,7 @@ fun main() { } println() } + + val result = getWinnerIndex(carsMovings).map { cars[it] } + println("최종 우승자 : ${result.joinToString(", ")}") } From 55f7b910bb65d9cf1be4fb0154031273ee6a8e86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:33:24 +0900 Subject: [PATCH 06/17] =?UTF-8?q?refactor:=20indent=20depth=202=EC=9D=B4?= =?UTF-8?q?=ED=95=98=EB=A5=BC=20=EC=9C=84=ED=95=B4=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=A5=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- src/main/kotlin/racingcar/Application.kt | 55 +++++++++++++++++------- 2 files changed, 41 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 86498c3a..b004b65d 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ - [x] 최종 우승자 - [x] 공동 우승자면 함께 -- [ ] depth 2이하 +- [x] depth 2이하 ### 테스트 -- [ ] 정상적인 입력에서 잘 기능하는지 +- [ ] 아무 입력 안했을 경우 - [ ] 잘못입력하였을 경우 - [ ] 공동 우승일 경우 \ No newline at end of file diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index ffecb342..743f3c79 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -4,11 +4,43 @@ import camp.nextstep.edu.missionutils.Randoms import camp.nextstep.edu.missionutils.Console -fun getWinnerIndex(carsMovings : Array): MutableList { +class OutputView { + fun gameResult(carName:String, movingCount: Int){ + println("$carName : ${"-".repeat(movingCount)}") + } +} + + + +fun isCanMove(): Boolean { + return Randoms.pickNumberInRange(0,9) >= 4 +} + +fun gameOfOneCar(carsMoving : Array, index : Int) { + if(isCanMove()){ + carsMoving[index] += 1 + } +} + +fun gameOfTurn(cars : List, carsMovingArray : Array, outputView : OutputView){ + for(i in 0 until cars.count()){ + gameOfOneCar(carsMovingArray, i) + outputView.gameResult(cars[i], carsMovingArray[i]) + } + println() +} + +fun game(cars : List, carsMovingArray: Array, outputView: OutputView, count : Int){ + for (i in 0 until count){ + gameOfTurn(cars, carsMovingArray, outputView) + } +} + +fun getWinnerIndex(carsMoving : Array): MutableList { val winners = mutableListOf() var maxNumber = 0 - carsMovings.forEachIndexed { idx, it -> + carsMoving.forEachIndexed { idx, it -> if(it == maxNumber){ winners.addLast(idx) } @@ -18,12 +50,12 @@ fun getWinnerIndex(carsMovings : Array): MutableList { winners.addLast(idx) } } - return winners } fun main() { - // TODO: 프로그램 구현 + val outputView = OutputView() + println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") val inputCar = Console.readLine() val cars = inputCar.split(',') @@ -35,19 +67,10 @@ fun main() { println("실행 결과") - val carsMovings = Array(cars.count()) { 0 } + val carsMovingArray = Array(cars.count()) { 0 } - for (i in 0 until count){ - for(j in 0 until cars.count()){ - if(Randoms.pickNumberInRange(0,9) >= 4){ - //이동 - carsMovings[j] += 1 - } - println("${cars[j]} : ${"-".repeat(carsMovings[j])}") - } - println() - } + game(cars, carsMovingArray, outputView, count) - val result = getWinnerIndex(carsMovings).map { cars[it] } + val result = getWinnerIndex(carsMovingArray).map { cars[it] } println("최종 우승자 : ${result.joinToString(", ")}") } From 509e05ab2fc2692f9afb07ce05ded59b68617572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:41:34 +0900 Subject: [PATCH 07/17] =?UTF-8?q?refactor:=20print=EB=AC=B8=EC=9D=84=20?= =?UTF-8?q?=EB=AA=A8=EB=91=90=20=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 31 ++++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 743f3c79..af301391 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -4,13 +4,29 @@ import camp.nextstep.edu.missionutils.Randoms import camp.nextstep.edu.missionutils.Console +class InputView{ + fun inputCars(){ + println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + } + + fun inputCount(){ + println("시도할 횟수는 몇 회인가요?") + } +} + class OutputView { + fun outputPrint(){ + println("실행 결과") + } fun gameResult(carName:String, movingCount: Int){ println("$carName : ${"-".repeat(movingCount)}") } -} + fun winnerPrint(winners : List){ + println("최종 우승자 : ${winners.joinToString(", ")}") + } +} fun isCanMove(): Boolean { return Randoms.pickNumberInRange(0,9) >= 4 @@ -55,22 +71,21 @@ fun getWinnerIndex(carsMoving : Array): MutableList { fun main() { val outputView = OutputView() + val inputView = InputView() - println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + inputView.inputCars() val inputCar = Console.readLine() val cars = inputCar.split(',') - - println("시도할 횟수는 몇 회인가요?") + inputView.inputCount() val inputCount = Console.readLine() val count = inputCount.toInt() - println("실행 결과") - val carsMovingArray = Array(cars.count()) { 0 } + outputView.outputPrint() game(cars, carsMovingArray, outputView, count) - val result = getWinnerIndex(carsMovingArray).map { cars[it] } - println("최종 우승자 : ${result.joinToString(", ")}") + val winners = getWinnerIndex(carsMovingArray).map { cars[it] } + outputView.winnerPrint(winners) } From bfbf74d051109020d738eb3435d05c9528a21013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:56:02 +0900 Subject: [PATCH 08/17] =?UTF-8?q?refactor:=20=EC=9E=90=EB=8F=99=EC=B0=A8?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=B4=205=EC=9E=90=EC=9D=B4=EC=83=81?= =?UTF-8?q?=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/racingcar/Application.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b004b65d..41425e26 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## 구현할 기능 목록 - [x] 자동차 이름 분류 - - [ ] (예외) 5자이상인경우 + - [x] (예외) 5자이상인경우 - [x] 이동할 횟수 - [ ] (예외) 숫자가 아닌 경우 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index af301391..e3983119 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -69,13 +69,21 @@ fun getWinnerIndex(carsMoving : Array): MutableList { return winners } + +fun checkCarNameLength(cars : List) { + if (!(cars.all { it -> it.count() <= 5 })){ + throw IllegalArgumentException("자동차 이름은 5자 이하만 가능하다") + } +} + fun main() { val outputView = OutputView() val inputView = InputView() inputView.inputCars() val inputCar = Console.readLine() - val cars = inputCar.split(',') + val cars : List = inputCar.split(',') + checkCarNameLength(cars) inputView.inputCount() val inputCount = Console.readLine() From 0bc88c8404bd972cf9e9d21bc0f8ede507c6bdd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sat, 26 Oct 2024 21:01:31 +0900 Subject: [PATCH 09/17] =?UTF-8?q?refactor:=20=ED=9A=9F=EC=88=98=EB=8A=94?= =?UTF-8?q?=20=EC=A0=95=EC=88=98=EB=A7=8C=20=EC=9E=85=EB=A0=A5=EA=B0=80?= =?UTF-8?q?=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/kotlin/racingcar/Application.kt | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 41425e26..95ec7964 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ - [x] 자동차 이름 분류 - [x] (예외) 5자이상인경우 - [x] 이동할 횟수 - - [ ] (예외) 숫자가 아닌 경우 + - [x] (예외) 정수가 아닌 경우 - [x] 랜덤 이동값 - [x] 자동차 개수만큼 이동한 횟수 배열 생성 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index e3983119..d6b76e1a 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -2,6 +2,7 @@ package racingcar import camp.nextstep.edu.missionutils.Randoms import camp.nextstep.edu.missionutils.Console +import java.lang.NumberFormatException class InputView{ @@ -72,7 +73,15 @@ fun getWinnerIndex(carsMoving : Array): MutableList { fun checkCarNameLength(cars : List) { if (!(cars.all { it -> it.count() <= 5 })){ - throw IllegalArgumentException("자동차 이름은 5자 이하만 가능하다") + throw IllegalArgumentException("자동차 이름은 5자 이하만 가능합니다") + } +} + +fun checkCountIsNumber(inputCount : String){ + try { + inputCount.toInt() + }catch (e: NumberFormatException){ + throw IllegalArgumentException("정수만 입력가능합니다") } } @@ -87,6 +96,7 @@ fun main() { inputView.inputCount() val inputCount = Console.readLine() + checkCountIsNumber(inputCount) val count = inputCount.toInt() val carsMovingArray = Array(cars.count()) { 0 } From 9625336b2772064a0550bbaccbd4517d49984c51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:22:23 +0900 Subject: [PATCH 10/17] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=97=90=20=EC=95=84=EB=AC=B4=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=95=88=ED=96=88=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +++++-- src/main/kotlin/racingcar/Application.kt | 11 +++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 95ec7964..41199220 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ ## 구현할 기능 목록 - [x] 자동차 이름 분류 - [x] (예외) 5자이상인경우 + - [x] (예외) 아무입력도 안했을 경우 - [x] 이동할 횟수 - [x] (예외) 정수가 아닌 경우 @@ -17,6 +18,8 @@ - [x] depth 2이하 ### 테스트 -- [ ] 아무 입력 안했을 경우 -- [ ] 잘못입력하였을 경우 +- [ ] 자동차 이름에 아무 입력 안했을 경우 +- [ ] 자동차 이름이 중복인 경우 +- [ ] 횟수에 문자를 입력하였을 경우 에러 +- [ ] 횟수에 소수를 입력하였을 경우 에러 - [ ] 공동 우승일 경우 \ No newline at end of file diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index d6b76e1a..d74abcfb 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -29,12 +29,12 @@ class OutputView { } } -fun isCanMove(): Boolean { +fun isCanGo(): Boolean { return Randoms.pickNumberInRange(0,9) >= 4 } fun gameOfOneCar(carsMoving : Array, index : Int) { - if(isCanMove()){ + if(isCanGo()){ carsMoving[index] += 1 } } @@ -77,6 +77,12 @@ fun checkCarNameLength(cars : List) { } } +fun checkInputCarIsNotEmpty(inputCar : String){ + if(inputCar == ""){ + throw IllegalArgumentException("자동차 이름을 입력해주세요") + } +} + fun checkCountIsNumber(inputCount : String){ try { inputCount.toInt() @@ -91,6 +97,7 @@ fun main() { inputView.inputCars() val inputCar = Console.readLine() + checkInputCarIsNotEmpty(inputCar) val cars : List = inputCar.split(',') checkCarNameLength(cars) From 94aa1e68105d60fb79ea2c44e6d6fbfbeabcbda2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:23:24 +0900 Subject: [PATCH 11/17] =?UTF-8?q?test:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=97=90=20=EC=95=84=EB=AC=B4=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=20=EC=95=88=ED=96=88=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/test/kotlin/racingcar/ApplicationTest.kt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 41199220..ee570de8 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ - [x] depth 2이하 ### 테스트 -- [ ] 자동차 이름에 아무 입력 안했을 경우 +- [x] 자동차 이름에 아무 입력 안했을 경우 - [ ] 자동차 이름이 중복인 경우 - [ ] 횟수에 문자를 입력하였을 경우 에러 - [ ] 횟수에 소수를 입력하였을 경우 에러 diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 3c601c8e..837cc700 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -17,6 +17,8 @@ class ApplicationTest : NsTest() { }, MOVING_FORWARD, STOP ) + + } @Test @@ -24,6 +26,9 @@ class ApplicationTest : NsTest() { assertSimpleTest { assertThrows { runException("pobi,javaji", "1") } } + assertSimpleTest { + assertThrows { runException("","") } + } } override fun runMain() { From 8864304f0a434ce7746d760426a13c04ae01a0c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:37:44 +0900 Subject: [PATCH 12/17] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=B4=20=EC=A4=91=EB=B3=B5=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/main/kotlin/racingcar/Application.kt | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ee570de8..844a74c8 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ - [x] 자동차 이름 분류 - [x] (예외) 5자이상인경우 - [x] (예외) 아무입력도 안했을 경우 + - [x] (예외) 자동차 이름이 중복인 경우 - [x] 이동할 횟수 - [x] (예외) 정수가 아닌 경우 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index d74abcfb..1f7f2373 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -79,10 +79,17 @@ fun checkCarNameLength(cars : List) { fun checkInputCarIsNotEmpty(inputCar : String){ if(inputCar == ""){ - throw IllegalArgumentException("자동차 이름을 입력해주세요") + throw IllegalArgumentException("자동차 이름을 입력하지 않았습니다") } } +fun checkCarNameDuplication(cars : List) { + if(cars.toSet().size != cars.size){ + throw IllegalArgumentException("자동차 이름이 중복입니다") + } + +} + fun checkCountIsNumber(inputCount : String){ try { inputCount.toInt() @@ -100,6 +107,7 @@ fun main() { checkInputCarIsNotEmpty(inputCar) val cars : List = inputCar.split(',') checkCarNameLength(cars) + checkCarNameDuplication(cars) inputView.inputCount() val inputCount = Console.readLine() From 87b64df27feaa137374d882c8151bf2651e47bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 12:49:01 +0900 Subject: [PATCH 13/17] =?UTF-8?q?test:=20=EC=9E=90=EB=8F=99=EC=9D=B4=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=B4=20=EC=A4=91=EB=B3=B5=EC=9D=B8=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/test/kotlin/racingcar/ApplicationTest.kt | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 844a74c8..6096dcae 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ ### 테스트 - [x] 자동차 이름에 아무 입력 안했을 경우 -- [ ] 자동차 이름이 중복인 경우 +- [x] 자동차 이름이 중복인 경우 - [ ] 횟수에 문자를 입력하였을 경우 에러 - [ ] 횟수에 소수를 입력하였을 경우 에러 - [ ] 공동 우승일 경우 \ No newline at end of file diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 837cc700..70745e36 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -27,7 +27,10 @@ class ApplicationTest : NsTest() { assertThrows { runException("pobi,javaji", "1") } } assertSimpleTest { - assertThrows { runException("","") } + assertThrows { runException("","1") } + } + assertSimpleTest { + assertThrows { runException("pobi,pobi,woni","3") } } } From 6f7677968d4464182330e71084f3833110f8cdad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:21:02 +0900 Subject: [PATCH 14/17] =?UTF-8?q?feat:=20=EC=9E=90=EB=8F=99=EC=B0=A8=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=96=91=EC=98=86=EC=97=90=20=EA=B3=B5?= =?UTF-8?q?=EB=B0=B1=EC=9D=B4=20=EC=9E=88=EC=9D=84=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + src/main/kotlin/racingcar/Application.kt | 62 +++++++++++++----------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 6096dcae..81c32920 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - [x] (예외) 5자이상인경우 - [x] (예외) 아무입력도 안했을 경우 - [x] (예외) 자동차 이름이 중복인 경우 + - [x] 이름 양옆에 공백이 있을 경우 제거 - [x] 이동할 횟수 - [x] (예외) 정수가 아닌 경우 diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index 1f7f2373..df35a471 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -5,63 +5,68 @@ import camp.nextstep.edu.missionutils.Console import java.lang.NumberFormatException -class InputView{ - fun inputCars(){ +class InputView { + fun inputCars() { println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") } - fun inputCount(){ + fun inputCount() { println("시도할 횟수는 몇 회인가요?") } } class OutputView { - fun outputPrint(){ + fun outputPrint() { println("실행 결과") } - fun gameResult(carName:String, movingCount: Int){ + + fun gameResult(carName: String, movingCount: Int) { println("$carName : ${"-".repeat(movingCount)}") } - fun winnerPrint(winners : List){ + fun winnerPrint(winners: List) { println("최종 우승자 : ${winners.joinToString(", ")}") } } +fun carsNameTrim(cars : List): List { + return cars.map { it.trim() } +} + fun isCanGo(): Boolean { - return Randoms.pickNumberInRange(0,9) >= 4 + return Randoms.pickNumberInRange(0, 9) >= 4 } -fun gameOfOneCar(carsMoving : Array, index : Int) { - if(isCanGo()){ +fun gameOfOneCar(carsMoving: Array, index: Int) { + if (isCanGo()) { carsMoving[index] += 1 } } -fun gameOfTurn(cars : List, carsMovingArray : Array, outputView : OutputView){ - for(i in 0 until cars.count()){ +fun gameOfTurn(cars: List, carsMovingArray: Array, outputView: OutputView) { + for (i in 0 until cars.count()) { gameOfOneCar(carsMovingArray, i) outputView.gameResult(cars[i], carsMovingArray[i]) } println() } -fun game(cars : List, carsMovingArray: Array, outputView: OutputView, count : Int){ - for (i in 0 until count){ +fun game(cars: List, carsMovingArray: Array, outputView: OutputView, count: Int) { + for (i in 0 until count) { gameOfTurn(cars, carsMovingArray, outputView) } } -fun getWinnerIndex(carsMoving : Array): MutableList { - val winners = mutableListOf() +fun getWinnerIndex(carsMoving: Array): MutableList { + val winners = mutableListOf() var maxNumber = 0 carsMoving.forEachIndexed { idx, it -> - if(it == maxNumber){ + if (it == maxNumber) { winners.addLast(idx) } - if(it > maxNumber){ + if (it > maxNumber) { maxNumber = it winners.clear() winners.addLast(idx) @@ -71,33 +76,34 @@ fun getWinnerIndex(carsMoving : Array): MutableList { } -fun checkCarNameLength(cars : List) { - if (!(cars.all { it -> it.count() <= 5 })){ +fun checkCarNameLength(cars: List) { + if (!(cars.all { it -> it.count() <= 5 })) { throw IllegalArgumentException("자동차 이름은 5자 이하만 가능합니다") } } -fun checkInputCarIsNotEmpty(inputCar : String){ - if(inputCar == ""){ +fun checkInputCarIsNotEmpty(inputCar: String) { + if (inputCar == "") { throw IllegalArgumentException("자동차 이름을 입력하지 않았습니다") } } -fun checkCarNameDuplication(cars : List) { - if(cars.toSet().size != cars.size){ +fun checkCarNameDuplication(cars: List) { + if (cars.toSet().size != cars.size) { throw IllegalArgumentException("자동차 이름이 중복입니다") } } -fun checkCountIsNumber(inputCount : String){ +fun checkCountIsNumber(inputCount: String) { try { inputCount.toInt() - }catch (e: NumberFormatException){ + } catch (e: NumberFormatException) { throw IllegalArgumentException("정수만 입력가능합니다") } } + fun main() { val outputView = OutputView() val inputView = InputView() @@ -105,9 +111,11 @@ fun main() { inputView.inputCars() val inputCar = Console.readLine() checkInputCarIsNotEmpty(inputCar) - val cars : List = inputCar.split(',') - checkCarNameLength(cars) + var cars: List = inputCar.split(',') checkCarNameDuplication(cars) + cars = carsNameTrim(cars) + checkCarNameLength(cars) + inputView.inputCount() val inputCount = Console.readLine() From b65741c34b996063a587b12641f4a8c5f9a1ae20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:30:56 +0900 Subject: [PATCH 15/17] =?UTF-8?q?test:=20=ED=9A=9F=EC=88=98=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EC=9D=B4=20=EC=A0=95=EC=88=98=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=88=EB=A9=B4=20=EC=98=88=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/test/kotlin/racingcar/ApplicationTest.kt | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 81c32920..ac7948c7 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,6 @@ ### 테스트 - [x] 자동차 이름에 아무 입력 안했을 경우 - [x] 자동차 이름이 중복인 경우 -- [ ] 횟수에 문자를 입력하였을 경우 에러 -- [ ] 횟수에 소수를 입력하였을 경우 에러 +- [x] 횟수에 문자를 입력하였을 경우 에러 +- [x] 횟수에 소수를 입력하였을 경우 에러 - [ ] 공동 우승일 경우 \ No newline at end of file diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index 70745e36..d27f6fb6 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -17,8 +17,6 @@ class ApplicationTest : NsTest() { }, MOVING_FORWARD, STOP ) - - } @Test @@ -27,10 +25,17 @@ class ApplicationTest : NsTest() { assertThrows { runException("pobi,javaji", "1") } } assertSimpleTest { - assertThrows { runException("","1") } + assertThrows { runException("", "1") } + } + assertSimpleTest { + assertThrows { runException("pobi,pobi,woni", "3") } + } + + assertSimpleTest { + assertThrows { runException("pobi,woni", "a") } } assertSimpleTest { - assertThrows { runException("pobi,pobi,woni","3") } + assertThrows { runException("pobi,woni", "1.1") } } } From d9d0f1e53c36acdc17a70625c415a7f089747575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:38:42 +0900 Subject: [PATCH 16/17] =?UTF-8?q?test:=20=EA=B3=B5=EB=8F=99=20=EC=9A=B0?= =?UTF-8?q?=EC=8A=B9=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/test/kotlin/racingcar/ApplicationTest.kt | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac7948c7..02bdaec0 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,4 @@ - [x] 자동차 이름이 중복인 경우 - [x] 횟수에 문자를 입력하였을 경우 에러 - [x] 횟수에 소수를 입력하였을 경우 에러 -- [ ] 공동 우승일 경우 \ No newline at end of file +- [x] 공동 우승일 경우 \ No newline at end of file diff --git a/src/test/kotlin/racingcar/ApplicationTest.kt b/src/test/kotlin/racingcar/ApplicationTest.kt index d27f6fb6..77ee95ff 100644 --- a/src/test/kotlin/racingcar/ApplicationTest.kt +++ b/src/test/kotlin/racingcar/ApplicationTest.kt @@ -17,6 +17,13 @@ class ApplicationTest : NsTest() { }, MOVING_FORWARD, STOP ) + assertRandomNumberInRangeTest( + { + run("pobi,woni,jiji", "1") + assertThat(output()).contains("pobi : -", "woni : -", "jiji : ", "최종 우승자 : pobi, woni") + }, + MOVING_FORWARD, MOVING_FORWARD, STOP + ) } @Test From daf715a061421a7bbf2d7bb839e67fbdecb9f888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B2=9C=EC=A7=80=EC=9C=A4?= <70828192+cheonjiyun@users.noreply.github.com> Date: Sun, 27 Oct 2024 17:59:35 +0900 Subject: [PATCH 17/17] =?UTF-8?q?refactor:=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/racingcar/Application.kt | 82 +++++-------------- .../kotlin/racingcar/Validation/Validation.kt | 31 +++++++ src/main/kotlin/racingcar/View/InputView.kt | 11 +++ src/main/kotlin/racingcar/View/OutputView.kt | 16 ++++ 4 files changed, 79 insertions(+), 61 deletions(-) create mode 100644 src/main/kotlin/racingcar/Validation/Validation.kt create mode 100644 src/main/kotlin/racingcar/View/InputView.kt create mode 100644 src/main/kotlin/racingcar/View/OutputView.kt diff --git a/src/main/kotlin/racingcar/Application.kt b/src/main/kotlin/racingcar/Application.kt index df35a471..5bfa0f5d 100644 --- a/src/main/kotlin/racingcar/Application.kt +++ b/src/main/kotlin/racingcar/Application.kt @@ -2,34 +2,11 @@ package racingcar import camp.nextstep.edu.missionutils.Randoms import camp.nextstep.edu.missionutils.Console -import java.lang.NumberFormatException +import racingcar.Validation.Validation +import racingcar.View.InputView +import racingcar.View.OutputView -class InputView { - fun inputCars() { - println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") - } - - fun inputCount() { - println("시도할 횟수는 몇 회인가요?") - } -} - -class OutputView { - fun outputPrint() { - println("실행 결과") - } - - fun gameResult(carName: String, movingCount: Int) { - println("$carName : ${"-".repeat(movingCount)}") - } - - fun winnerPrint(winners: List) { - println("최종 우승자 : ${winners.joinToString(", ")}") - - } -} - fun carsNameTrim(cars : List): List { return cars.map { it.trim() } } @@ -75,52 +52,35 @@ fun getWinnerIndex(carsMoving: Array): MutableList { return winners } +fun inputCars(inputView: InputView, validation: Validation): List { + inputView.inputCars() + val inputCar = Console.readLine() + validation.checkInputCarIsNotEmpty(inputCar) -fun checkCarNameLength(cars: List) { - if (!(cars.all { it -> it.count() <= 5 })) { - throw IllegalArgumentException("자동차 이름은 5자 이하만 가능합니다") - } -} + var cars: List = inputCar.split(',') + validation.checkCarNameDuplication(cars) + cars = carsNameTrim(cars) + validation.checkCarNameLength(cars) -fun checkInputCarIsNotEmpty(inputCar: String) { - if (inputCar == "") { - throw IllegalArgumentException("자동차 이름을 입력하지 않았습니다") - } + return cars } -fun checkCarNameDuplication(cars: List) { - if (cars.toSet().size != cars.size) { - throw IllegalArgumentException("자동차 이름이 중복입니다") - } - -} +fun inputCount(inputView: InputView, validation: Validation): Int { + inputView.inputCount() + val inputCount = Console.readLine() + validation.checkCountIsNumber(inputCount) + val count = inputCount.toInt() -fun checkCountIsNumber(inputCount: String) { - try { - inputCount.toInt() - } catch (e: NumberFormatException) { - throw IllegalArgumentException("정수만 입력가능합니다") - } + return count } - fun main() { val outputView = OutputView() val inputView = InputView() + val validation = Validation() - inputView.inputCars() - val inputCar = Console.readLine() - checkInputCarIsNotEmpty(inputCar) - var cars: List = inputCar.split(',') - checkCarNameDuplication(cars) - cars = carsNameTrim(cars) - checkCarNameLength(cars) - - - inputView.inputCount() - val inputCount = Console.readLine() - checkCountIsNumber(inputCount) - val count = inputCount.toInt() + val cars = inputCars(inputView, validation) + val count = inputCount(inputView, validation) val carsMovingArray = Array(cars.count()) { 0 } diff --git a/src/main/kotlin/racingcar/Validation/Validation.kt b/src/main/kotlin/racingcar/Validation/Validation.kt new file mode 100644 index 00000000..7abe1b6f --- /dev/null +++ b/src/main/kotlin/racingcar/Validation/Validation.kt @@ -0,0 +1,31 @@ +package racingcar.Validation + +import java.lang.NumberFormatException + +class Validation { + fun checkCarNameLength(cars: List) { + if (!(cars.all { it -> it.count() <= 5 })) { + throw IllegalArgumentException("자동차 이름은 5자 이하만 가능합니다") + } + } + + fun checkInputCarIsNotEmpty(inputCar: String) { + if (inputCar == "") { + throw IllegalArgumentException("자동차 이름을 입력하지 않았습니다") + } + } + + fun checkCarNameDuplication(cars: List) { + if (cars.toSet().size != cars.size) { + throw IllegalArgumentException("자동차 이름이 중복입니다") + } + + } + fun checkCountIsNumber(inputCount: String) { + try { + inputCount.toInt() + } catch (e: NumberFormatException) { + throw IllegalArgumentException("정수만 입력가능합니다") + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/racingcar/View/InputView.kt b/src/main/kotlin/racingcar/View/InputView.kt new file mode 100644 index 00000000..7302d8d7 --- /dev/null +++ b/src/main/kotlin/racingcar/View/InputView.kt @@ -0,0 +1,11 @@ +package racingcar.View + +class InputView { + fun inputCars() { + println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)") + } + + fun inputCount() { + println("시도할 횟수는 몇 회인가요?") + } +} \ No newline at end of file diff --git a/src/main/kotlin/racingcar/View/OutputView.kt b/src/main/kotlin/racingcar/View/OutputView.kt new file mode 100644 index 00000000..2e3ab591 --- /dev/null +++ b/src/main/kotlin/racingcar/View/OutputView.kt @@ -0,0 +1,16 @@ +package racingcar.View + +class OutputView { + fun outputPrint() { + println("실행 결과") + } + + fun gameResult(carName: String, movingCount: Int) { + println("$carName : ${"-".repeat(movingCount)}") + } + + fun winnerPrint(winners: List) { + println("최종 우승자 : ${winners.joinToString(", ")}") + + } +} \ No newline at end of file