Skip to content

[자동차 경주] 김가윤 미션 제출합니다.#49

Open
JCTA0125 wants to merge 17 commits intowoowacourse-precourse:mainfrom
JCTA0125:JCTA0125
Open

[자동차 경주] 김가윤 미션 제출합니다.#49
JCTA0125 wants to merge 17 commits intowoowacourse-precourse:mainfrom
JCTA0125:JCTA0125

Conversation

@JCTA0125
Copy link

기능 목록

1. 입력

  • 자동차 이름 입력
  • 시도할 횟수 입력

2. 경주 준비

  • 이름 쉼표 단위 분리
  • 이름 5자 이하 확인

3. 경주 시작

  • 무작위 값 부여
  • 정해진 횟수만큼 반복

4. 경주 결과

  • 우승자 결정

5. 출력

  • 중간 과정 출력
  • 우승자 출력

스스로 판단한 사항

  • 이름으로 공백 입력할 경우 예외 발생
  • 시도 횟수 0 이하인 경우 예외 발생
  • 중복된 이름 사용할 경우 예외 발생

Copy link

@CommitTheKermit CommitTheKermit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 잘 읽었습니다. 전체적으로 MVC 패턴을 잘 준수하셔서 쉽게 읽혔네요. 코드를 읽다보니 저도 지적받은 사항이 있어서 저도 몇 글자 적어봤습니다. 다가오는 3주차도 화이팅입니다~

Comment on lines +3 to +16
object CarValidator {
fun parse(input: String): List<String> {
val names = input.split(",").map { it.trim() }
validateCarName(names)

return names
}

private fun validateCarName(names: List<String>) {
require(names.all { it.isNotBlank() }) { throw IllegalArgumentException("자동차 이름은 비어 있을 수 없습니다.") }
require(names.all { it.length <= 5 }) { throw IllegalArgumentException("자동차 이름은 5자 이하만 가능합니다.") }
require(names.distinct().size == names.size) { throw IllegalArgumentException("자동차 이름은 중복될 수 없습니다.") }
}
} No newline at end of file

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CarValidator에 validate 말고도 parse도 있네요. parse를 따로 parser 클래스에 두시거나 Car 클래스에 두시는 것도 좋았을 것 같습니다.

Comment on lines +8 to +13
fun readCarNames(): List<String> {
println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)")
val carsInput = Console.readLine()

return CarValidator.parse(carsInput)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 지적받은 사항인데, InputView에서는 parse와 같은 다른 처리를 두지 않고 입력만 처리하면 좋을 것 같습니다!

Comment on lines +9 to +10
private val inputView: InputView = InputView(),
private val outputView: OutputView = OutputView()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InputView, OutputView는 프로젝트 내에서 여러 번 할당되지도 않고 상태도 갖고 있지 않기에 object 클래스로 선언하여 static 처럼 쓰시는 게 좋을 거 같습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants