diff --git a/src/main/kotlin/racingcar/controller/GameController.kt b/src/main/kotlin/racingcar/controller/GameController.kt index 5be310c30..e114c605f 100644 --- a/src/main/kotlin/racingcar/controller/GameController.kt +++ b/src/main/kotlin/racingcar/controller/GameController.kt @@ -14,6 +14,7 @@ class GameController { createRaceNumber() println() playRace() + gameResult() } fun createCarList() { @@ -32,4 +33,8 @@ class GameController { println(InformationMessage.EXECUTION_RESULT.message) raceService.playRace() } + fun gameResult() { + val winner = carService.getWinner() + println(InformationMessage.FINAL_WINNER.message + winner) + } } \ No newline at end of file diff --git a/src/main/kotlin/racingcar/global/InformationMessage.kt b/src/main/kotlin/racingcar/global/InformationMessage.kt index 88e5cfcd2..141724ae1 100644 --- a/src/main/kotlin/racingcar/global/InformationMessage.kt +++ b/src/main/kotlin/racingcar/global/InformationMessage.kt @@ -3,5 +3,6 @@ package racingcar.global enum class InformationMessage(val message: String) { INPUT_CARS_NAME("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"), ATTEMPT_NUMBER("시도할 횟수는 몇 회인가요?"), - EXECUTION_RESULT("실행 결과") + EXECUTION_RESULT("실행 결과"), + FINAL_WINNER("최종 우승자 : ") } \ No newline at end of file diff --git a/src/main/kotlin/racingcar/service/CarService.kt b/src/main/kotlin/racingcar/service/CarService.kt index 4795ed802..6fe941e1a 100644 --- a/src/main/kotlin/racingcar/service/CarService.kt +++ b/src/main/kotlin/racingcar/service/CarService.kt @@ -24,4 +24,10 @@ class CarService { if(random >= 4) car.move() } } + + fun getWinner(): String { + val largestNumber = Companion.cars.maxOf(Car::location) + return Companion.cars.filter { it.location == largestNumber } + .joinToString(separator = ", ") { car -> car.name } + } } \ No newline at end of file