[자동차 경주] 박규영 미션 제출합니다.#198
Open
cloudsoswift wants to merge 7 commits intowoowacourse-precourse:mainfrom
Open
Conversation
자동차 경주 기능 구현을 위해 구현할 기능 목록 README.md에 작성
문자열을 입력받아, 쉼표(,)를 기준으로 자동차 이름들을 추출하는 함수 carNameSplitter를 추가 - 문자열을 입력으로 받아, 문자열 배열을 반환 - 만약 자동차 이름들 중 5자를 초과하는 이름이 있을 경우 Error 던짐
한 번의 이동 과정을 진행하는 함수 doRace를 추가하고, 이에 필요한 Random 의존성을 추가함. 또한, constructor()를 추가해 각 자동차 이름이 담긴 배열(cars)과 각 자동차의 전진 상태를 저장하는 배열(carsRaceProgress)을 추가. - 각 자동차에 대해, 범위 0~9 사이의 랜덤한 수를 뽑아 4 이상일 경우 전진 - 전진은 각 차의 진행 상황(carsRaceProgress[i])에 '-' 문자열을 추가하는 것을 의미
각 주차별 경주 진행 상황을 출력하는 함수 printRaceRound를 추가 - 각 자동차 이름과 진행 정도를 출력 - 또한, printRaceRound 함수를 doRace에서 전진 작업을 수행한 뒤 바로 호출하도록 수정
최종 우승 자동차(들)의 이름을 출력하는 함수 printRaceWinner를 추가 - carsRaceProgress를 순회하며, 길이가 가장 긴 문자열(=가장 멀리 전진한)을 갖는 문자열들의 index를 기록한 뒤, 해당 index를 갖는 차의 이름들을 join으로 합쳐 출력
일련의 경주 과정을 수행하는 함수 App.run 작성 - 경주할 자동차 이름을 입력받아 carNameSplitter를 호출해 이들을 분리하고, 시도할 횟수를 입력받은 뒤 그 만큼 doRace를 반복 수행 - 이후 printRaceWinner를 호출해 최종 우승자를 출력함
일부 함수들의 출력 관련해 수정 - App.run의 경우, 실행 결과 예시와 유사하게 공백 줄바꿈 출력 및 "실행 결과"라는 문자열 출력하도록 수정 - doRace의 경우, Console.print()에 별도의 문자열을 넘기지 않고 호출해서 한 줄만 공백 줄바꿈 출력되도록 수정 - printRaceRound의 경우, 배열 내용을 그대로 출력하는게 아닌 join을 통해 각 문자열을 띄어쓰기없이 합쳐 출력하도록 수정
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
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.