-
Notifications
You must be signed in to change notification settings - Fork 911
[자동차 경주] 복지민 미션 제출합니다. #933
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
b-jm
wants to merge
32
commits into
woowacourse-precourse:main
Choose a base branch
from
b-jm:b-jm
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
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
- 자동차 이름 입력 안내 메시지 상수 추가 - 시도 횟수 입력 안내 메시지 상수 추가
- Input에 자동차 이름 입력 기능 추가 - Console 입력 후 쉼표(,) 기준으로 이름 분리
- View는 입력/출력만 담당하고, 도메인 로직은 비즈니스 계층에서 처리하도록 구조 개선
- 사용자로부터 시도 횟수를 입력받는 inputTryCount 메서드 추가
- 자동차 이름, 시도 횟수 관련 에러 메시지를 상수로 분리
- 프로그램의 실행 흐름(run)을 담당할 RacingController 클래스 추가 - 이후 InputView, OutputView, Service를 연결하는 중심 역할 예정
- RacingController에서 Input으로부터 시도 횟수를 입력받아 Rounds 객체 생성 - Rounds에서 문자열 입력값을 BigInteger로 변환하고 숫자 검증 로직 추가 - 잘못된 입력 시 IllegalArgumentException 발생 처리
- validatePositive(BigInteger count) 메서드 추가로 0 이하 입력 검증 처리 - ErrorMessage import 범위를 *로 확장
- BigInteger 타입 반환에 맞게 parseToInt() → parseToBigInteger()로 메서드명 수정
- Cars 클래스에서 자동차 이름을 문자열로 입력받아 리스트로 변환 - parseNames() 메서드를 통해 ',' 기준으로 이름 분리 로직 구현
- validateMinimumSize() 메서드로 최소 2대 이상인지 검증 - validateDuplicates() 메서드로 이름 중복 여부 확인 - Cars 생성 시 validateList()를 통해 유효성 검사 수행
자동차 이름들을 Car 객체로 만들어 cars 리스트에 저장하고 조회할 수 있도록 구현
- 이름이 5자를 초과할 경우 IllegalArgumentException 발생 - validateNameLength() 메서드로 이름 길이 검증 수행 - Car 생성 시 validate()를 통해 자동 검증
- validateNoBlank() 메서드로 공백 포함 여부 검증 - validateNoEmpty() 메서드로 빈 문자열 입력 검증 - 잘못된 입력 시 IllegalArgumentException 발생
- OutputMessage 클래스에 RESULT_TITLE 상수 정의 - Output 클래스에서 printResultTitle() 메서드로 결과 제목 출력
- NumberGenerator 인터페이스 정의 (pickNumber 메서드) - RandomNumberGenerator 클래스에서 0~9 범위의 난수 생성 구현
- moveAllCars() 메서드 추가로 모든 자동차에 대해 이동 수행 - NumberGenerator를 통해 0~9 범위의 랜덤 숫자 생성 - 각 자동차별로 랜덤 값에 따라 move() 호출
- Cars 클래스에서 RandomNumberGenerator 직접 생성 제거 - NumberGenerator를 생성자를 통해 주입받도록 수정 (의존성 주입 구조)
- 자동차들의 현재 위치 중 최대 이동 거리를 계산하는 findMaxPosition() 메서드 추가 - 최대 이동 거리에 도달한 자동차들을 반환하는 findWinners() 메서드 구현
- 랜덤 값이 MOVE_CONDITION_NUMBER 이상일 경우 position 증가 로직 구현 - 자동차의 현재 상태를 문자열로 반환하는 toResultString() 메서드 추가 - 최대 이동 거리와 비교하여 우승 여부를 반환하는 isWinner() 메서드 추가 - 자동차 이름과 위치를 반환하는 getter 메서드(getName, getPosition) 추가
- 최종 우승자 출력 시 사용될 메시지 상수(WINNER_MESSAGE) 추가
- run() 메서드에서 자동차 생성, 라운드 설정, 경주 진행, 결과 출력까지 전체 흐름 구현 - setupCars(), setupRounds() 메서드를 분리하여 초기화 책임 명확화 - Race와 RaceService를 활용해 라운드별 경주 수행 및 상태 출력 - 최종 우승자 목록을 Output을 통해 출력하도록 구성
- Race 도메인 클래스 신규 생성 - Cars와 Rounds를 필드로 두어 경주 전체를 관리하도록 구성 - runSingleRound()를 통해 한 라운드 경주 수행 기능 구현 - findWinners(), getCurrentCars(), getRoundCount() 메서드로 우승자 조회 및 상태 반환 로직 추가 - 경주 로직의 중심 역할을 담당하는 도메인 클래스 설계
- BigInteger 타입 대신 int 타입으로 라운드 수 관리하도록 변경 - parseToBigInteger() 메서드를 parseToInt()로 단순화 - 불필요한 객체 생성 제거로 코드 가독성 및 성능 개선 - 라운드 입력값 검증(validatePositive) 로직은 기존 그대로 유지
- RaceService 클래스 신규 생성 - Race 도메인을 주입받아 runSingleRound(), getWinners() 기능 구현
- 자동차의 이동 상태를 출력하는 printCarsStatus() 메서드 추가
- 최종 우승자 목록을 출력하는 printWinners() 메서드 구현
- 실행 결과 제목을 출력하는 printResultTitle() 메서드 유지
- DISTANCE_UNIT 상수("-") 추가로 출력 포맷 일관성 확보
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.