-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[자동차 경주] 김채원 미션 제출합니다. #1452
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
Open
Dim-chae
wants to merge
14
commits into
woowacourse-precourse:main
Choose a base branch
from
Dim-chae:Dim-chae
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[자동차 경주] 김채원 미션 제출합니다. #1452
Conversation
This file contains hidden or 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
[기능 요구 사항] 자동차 경주 문제에 대한 로직을 기능 별로 분리 및 순차 정리 - 초기 입력 - 전진에 따른 난수 생성 및 전진 여부 판별 - 1회 시도마다 전진 현황 출력 - 우승자 선정, 최종 우승자 출력 [예외 케이스] - 자동차 이름 문자열이 쉼표로 구분되지 않을 경우 구분 시 5자 이하가 아닐 경우 - 시도할 횟수 양의 정수가 아닌 경우
- 경주할 자동차의 이름과 시도할 횟수를 입력 받음 - 시도할 횟수를 숫자로 포맷하는 과정에서 에러가 날 경우 Exception 발생
- 개별 자동차에 대한 컨테이너를 Map 형태로 선언 - 초기 입력 문자열에 split 함수를 이용하여 String 배열 저장 - String 배열 검사, 5 이하일 경우에만 cars 컨테이너에 입력 값 저장
- 각 자동차마다 pickNumberInRange() 메소드로 난수 생성 - 4 이상일 경우에만 car 컨테이너의 value 값에 1을 더함 - 입력 받은 시도 횟수(경기를 진행하는 수)만큼 반복 수행
- 각 자동차의 이름과 전진 값을 map 컨테이너 이용하여 출력 - "-" 문자를 출력할 때 repeat() 메소드로 전진 값(value)만큼 반복하도록 함
- Collections.max()를 사용하여 최대 전진 거리 계산 - Stream API로 최대 전진 거리와 동일한 자동차들을 우승자로 선정
- 최대 전진 거리를 value로 가지는 자동차(우승자) 리스트 출력 - String.join() 메소드를 통해 우승자가 여러 명일 경우 쉼표로 구분
[Main] - Application 클래스: 메인 로직 실행 [Model] - Car 클래스: 자동차 객체 생성 및 이동 로직 구현 - RacingGame 클래스: 게임 진행, 자동차 관리, 우승자 결정 로직 구현 [View] - RacingGameView 클래스: 사용자 입력 프롬프트 및 게임 결과 출력 [Controller] - RacingGameController 클래스: 사용자 입력 처리, Model과 View 간 상호작용 조정
- MOVE_THRESHOLD: 난수를 생성했을 때 전진 여부를 판별하는 임계값(4)에 대한 상수 - RANDOM_BOUND: 난수를 생성할 수 있는 범위의 최댓값(9)에 대한 상수
- validateName(String name) 메소드로 name의 길이 검사 - name의 길이가 5를 초과할 시 IllegalArgumentException 발생
- MAX_NAME_LENGTH: 자동차 이름의 길이가 5자가 넘는지 판별 시 최댓값에 대한 상수
- 기능 요구 사항의 입력, 출력 단계에 대해 구체적으로 기술함
- validateInputString 메소드: 입력 문자열에 ","가 없는지 검사 - validateCarName 메소드: 자동차 이름이 비어 있거나 최대 글자수를 넘는지 검사 - validateRoundCount 메소드: 시도 횟수가 0 이하인지 검사 - validateCarPosition 메소드: 자동차의 위치가 음수인지 검사
- 이름 길이 초과 예외 테스트: 이름 길이가 5자 초과일 경우 - 빈 이름 예외 테스트: 입력 문자열을 분리한 결과 빈 문자열이 있을 경우 - 시도 횟수 예외 테스트: 시도 횟수를 입력한 값이 문자열일 경우
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.