-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Review #1484
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
base: main
Are you sure you want to change the base?
Review #1484
Changes from all commits
51e920d
ca35d77
57b6265
aba327d
70d353e
0e9a00e
67d4b47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,143 @@ | ||
| # java-racingcar-precourse | ||
| # 자동차 경주 | ||
|
|
||
| ## 과제 진행 요구 사항 | ||
|
|
||
| - 미션은 [자동차 경주](https://github.com/woowacourse-precourse/java-racingcar-7) 저장소를 포크하고 클론하는 것으로 시작한다. | ||
|
|
||
| - **기능을 구현하기 전 `README.md`에 구현할 기능 목록을 정리**해 추가한다. | ||
|
|
||
| - Git의 커밋 단위는 앞 단계에서 `README.md`에 정리한 기능 목록 단위로 추가한다. | ||
|
|
||
|
|
||
| - [AngularJS Git Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153)을 참고해 커밋 메시지를 작성한다. | ||
|
|
||
| - 자세한 과제 진행 방법은 프리코스 진행 가이드 문서를 참고한다. | ||
|
|
||
| ## 기능 요구 사항 | ||
|
|
||
| 초간단 자동차 경주 게임을 구현한다. | ||
|
|
||
| - 주어진 횟수 동안 n대의 자동차는 전진 또는 멈출 수 있다. | ||
|
|
||
| - 각 자동차에 이름을 부여할 수 있다. 전진하는 자동차를 출력할 때 자동차 이름을 같이 출력한다. | ||
|
|
||
| - 자동차 이름은 쉼표(,)를 기준으로 구분하며 이름은 5자 이하만 가능하다. | ||
|
|
||
| - 사용자는 몇 번의 이동을 할 것인지를 입력할 수 있어야 한다. | ||
|
|
||
| - 전진하는 조건은 0에서 9 사이에서 무작위 값을 구한 후 무작위 값이 4 이상일 경우이다. | ||
|
|
||
| - 자동차 경주 게임을 완료한 후 누가 우승했는지를 알려준다. 우승자는 한 명 이상일 수 있다. | ||
|
|
||
| - 우승자가 여러 명일 경우 쉼표(,)를 이용하여 구분한다. | ||
|
|
||
| - 사용자가 잘못된 값을 입력할 경우 `IllegalArgumentException`을 발생시킨 후 애플리케이션은 종료되어야 한다. | ||
|
|
||
| ### 입출력 요구 사항 | ||
|
|
||
| #### 입력 | ||
|
|
||
| - 경주할 자동차 이름(이름은 쉼표(,) 기준으로 구분) | ||
|
|
||
| ```autohotkey | ||
| pobi,woni,jun | ||
| ``` | ||
|
|
||
| - 시도할 횟수 | ||
|
|
||
| ```undefined | ||
| 5 | ||
| ``` | ||
|
|
||
| #### 출력 | ||
|
|
||
| - 차수별 실행 결과 | ||
|
|
||
| ```ada | ||
| pobi : -- woni : ---- jun : --- | ||
| ``` | ||
|
|
||
| - 단독 우승자 안내 문구 | ||
|
|
||
| ```ada | ||
| 최종 우승자 : pobi | ||
| ``` | ||
|
|
||
| - 공동 우승자 안내 문구 | ||
|
|
||
| ```ada | ||
| 최종 우승자 : pobi, jun | ||
| ``` | ||
|
|
||
| #### 실행 결과 예시 | ||
|
|
||
| ```ada | ||
| 경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분) pobi,woni,jun 시도할 횟수는 몇 회인가요? 5 실행 결과 pobi : - woni : jun : - pobi : -- woni : - jun : -- pobi : --- woni : -- jun : --- pobi : ---- woni : --- jun : ---- pobi : ----- woni : ---- jun : ----- 최종 우승자 : pobi, jun | ||
| ``` | ||
|
|
||
| ## 프로그래밍 요구 사항 1 | ||
|
|
||
| - JDK 21 버전에서 실행 가능해야 한다. | ||
|
|
||
| - 프로그램 실행의 시작점은 `Application`의 `main()`이다. | ||
|
|
||
| - `build.gradle` 파일은 변경할 수 없으며, **제공된 라이브러리 이외의 외부 라이브러리는 사용하지 않는다.** | ||
|
|
||
| - 프로그램 종료 시 `System.exit()`를 호출하지 않는다. | ||
|
|
||
| - 프로그래밍 요구 사항에서 달리 명시하지 않는 한 파일, 패키지 등의 이름을 바꾸거나 이동하지 않는다. | ||
|
|
||
| - 자바 코드 컨벤션을 지키면서 프로그래밍한다. | ||
|
|
||
|
|
||
| - 기본적으로 [Java Style Guide](https://github.com/woowacourse/woowacourse-docs/blob/main/styleguide/java)를 원칙으로 한다. | ||
|
|
||
| ## 프로그래밍 요구 사항 2 | ||
|
|
||
| - indent(인덴트, 들여쓰기) depth를 3이 넘지 않도록 구현한다. 2까지만 허용한다. | ||
|
|
||
|
|
||
| - 예를 들어 while문 안에 if문이 있으면 들여쓰기는 2이다. | ||
|
|
||
|
|
||
| - 힌트: indent(인덴트, 들여쓰기) depth를 줄이는 좋은 방법은 함수(또는 메서드)를 분리하면 된다. | ||
|
|
||
| - 3항 연산자를 쓰지 않는다. | ||
|
|
||
| - 함수(또는 메서드)가 한 가지 일만 하도록 최대한 작게 만들어라. | ||
|
|
||
| - JUnit 5와 AssertJ를 이용하여 정리한 기능 목록이 정상적으로 작동하는지 테스트 코드로 확인한다. | ||
|
|
||
|
|
||
| - 테스트 도구 사용법이 익숙하지 않다면 아래 문서를 참고하여 학습한 후 테스트를 구현한다. | ||
|
|
||
|
|
||
| - [JUnit 5 User Guide](https://junit.org/junit5/docs/current/user-guide) | ||
|
|
||
|
|
||
| - [AssertJ User Guide](https://assertj.github.io/doc) | ||
|
|
||
|
|
||
| - [AssertJ Exception Assertions](https://www.baeldung.com/assertj-exception-assertion) | ||
|
|
||
|
|
||
| - [Guide to JUnit 5 Parameterized Tests](https://www.baeldung.com/parameterized-tests-junit-5) | ||
|
|
||
| ### 라이브러리 | ||
|
|
||
| - `camp.nextstep.edu.missionutils`에서 제공하는 `Randoms` 및 `Console` API를 사용하여 구현해야 한다. | ||
|
|
||
|
|
||
| - Random 값 추출은 `camp.nextstep.edu.missionutils.Randoms`의 `pickNumberInRange()`를 활용한다. | ||
|
|
||
|
|
||
| - 사용자가 입력하는 값은 `camp.nextstep.edu.missionutils.Console`의 `readLine()`을 활용한다. | ||
|
|
||
| #### 사용 예시 | ||
|
|
||
| - 0에서 9까지의 정수 중 한 개의 정수 반환 | ||
|
|
||
| ```java | ||
| Randoms.pickNumberInRange(0, 9); | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| package racingcar; | ||
|
|
||
| import racingcar.Controller.RacingCarController; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
|
|
||
| RacingCarController racingcarController = new RacingCarController(); | ||
| racingcarController.run(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package racingcar.Controller; | ||
|
|
||
| import racingcar.Model.Cars; | ||
| import racingcar.Service.*; | ||
| import racingcar.View.InputView; | ||
| import racingcar.View.OutputView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class RacingCarController { | ||
| private final ClassificationService classificationService; | ||
| private final MovementService movementService; | ||
| private final RandomService randomService; | ||
| private final InputView inputView; | ||
| private final OutputView outputView; | ||
| private final NameValidationService nameValidationService; | ||
| private final NameSplitterService nameSplitterService; | ||
| private final ParseService parseService; | ||
| private final ResultService resultService; | ||
| private final GameService gameService; | ||
| private final CreateCarService createCarService; | ||
|
|
||
| public RacingCarController() { | ||
| this.classificationService = new ClassificationService(); | ||
| this.movementService = new MovementService(); | ||
| this.randomService = new RandomService(); | ||
| this.inputView = new InputView(); | ||
| this.outputView = new OutputView(); | ||
| this.nameValidationService = new NameValidationService(); | ||
| this.nameSplitterService = new NameSplitterService(); | ||
| this.parseService = new ParseService(); | ||
| this.resultService = new ResultService(); | ||
| this.gameService = new GameService(randomService, classificationService, movementService); | ||
| this.createCarService = new CreateCarService(); | ||
| } | ||
|
|
||
| public void run() { | ||
| List<String> input = inputView.input(); | ||
| List<String> carNames = | ||
| nameValidationService.validateName(nameSplitterService.nameSplit(input.getFirst())); | ||
|
Comment on lines
+39
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 코드 한줄에서 여러개의 |
||
|
|
||
| Cars carRacers = createCarService.crateCar(carNames); | ||
|
|
||
| int roundCount = parseService.parseInt(input.getLast()); | ||
|
|
||
| for (int round = 0; round < roundCount; round++) { | ||
| gameService.gameRound(carRacers); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드명은 명사보단 동사로 지어 어떤 동작을 수행하는지 나타내야합니다. |
||
| outputView.output_round(carRacers); | ||
| } | ||
| List<String> winnerNames = resultService.findWinners(carRacers); | ||
|
|
||
| outputView.output_winner(winnerNames); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Java 에서는 카멜 케이스 표기법을 준수해주세요. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package racingcar.Model; | ||
|
|
||
| public class Car { | ||
| private String racerName; | ||
| private int position; | ||
|
|
||
| public String getName() { | ||
| return racerName; | ||
| } | ||
| public void setName(String racerName) { | ||
| this.racerName = racerName; | ||
| } | ||
| public int getPosition() { | ||
| return position; | ||
| } | ||
| public void setPosition(int position) { | ||
| this.position = position; | ||
| } | ||
|
|
||
| public void move() { | ||
| ++position; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package racingcar.Model; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Cars { | ||
| private List<Car> racers; | ||
|
|
||
| public void setCarRacers(List<Car> racers) { | ||
| this.racers = racers; | ||
| } | ||
|
|
||
| public Car getCar(int index) { | ||
| return racers.get(index); | ||
| } | ||
|
|
||
| public int size() { | ||
| return racers.size(); | ||
| } | ||
|
Comment on lines
+16
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 메서드명 동사로 바꿔주세요. |
||
|
|
||
| public int getMaxPosition() { | ||
| int maxPosition = 0; | ||
| for (Car racer : racers) { | ||
| if (maxPosition < racer.getPosition()) { | ||
| maxPosition = racer.getPosition(); | ||
| } | ||
| } | ||
| return maxPosition; | ||
| } | ||
|
Comment on lines
+20
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package racingcar.Service; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class ClassificationService { | ||
| public List<Integer> classifyValue(List<Integer> racingCars) { | ||
| List<Integer> result = new ArrayList<>(); | ||
|
|
||
| for (Integer racingCarRandomValue : racingCars) { | ||
| if (racingCarRandomValue > 3) { | ||
| result.add(1); | ||
| } else { | ||
| result.add(0); | ||
| } | ||
| } | ||
|
Comment on lines
+11
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이전 미션 리뷰를 안읽으셨나요? |
||
| return result; | ||
| } | ||
|
|
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package racingcar.Service; | ||
|
|
||
| import racingcar.Model.Car; | ||
| import racingcar.Model.Cars; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class CreateCarService { | ||
| public Cars crateCar(List<String> carNames) { | ||
| List<Car> cars = new ArrayList<>(); | ||
| for (String carName : carNames) { | ||
| Car car = new Car(); | ||
| car.setName(carName); | ||
| car.setPosition(0); | ||
| cars.add(car); | ||
| } | ||
|
|
||
| Cars racers = new Cars(); | ||
| racers.setCarRacers(cars); | ||
| return racers; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package racingcar.Service; | ||
|
|
||
| import racingcar.Model.Cars; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class GameService { | ||
| private final RandomService randomService; | ||
| private final ClassificationService classificationService; | ||
| private final MovementService movementService; | ||
|
|
||
| public GameService(RandomService randomService, ClassificationService classificationService, | ||
| MovementService movementService) { | ||
| this.randomService = randomService; | ||
| this.classificationService = classificationService; | ||
| this.movementService = movementService; | ||
| } | ||
|
|
||
| public void gameRound(Cars racers) { | ||
| List<Integer> classifyCars = | ||
| classificationService.classifyValue(randomService.randomValue(racers.size())); | ||
| movementService.playRound(classifyCars, racers); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package racingcar.Service; | ||
|
|
||
| import racingcar.Model.Cars; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class MovementService { | ||
|
|
||
| public void playRound(List<Integer> sortedRacingCars, Cars racers) { | ||
| for (int index = 0; index < sortedRacingCars.size(); index++) { | ||
| if (sortedRacingCars.get(index).equals(1)) { | ||
| racers.getCar(index).move(); | ||
| racers.getCar(index).setPosition(racers.getCar(index).getPosition()); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package racingcar.Service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class NameSplitterService { | ||
|
|
||
| public List<String> nameSplit(String names) { | ||
| return List.of(names.split(",")); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package racingcar.Service; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class NameValidationService { | ||
| public List<String> validateName(List<String> racerNames) { | ||
| for (String name : racerNames) { | ||
| if (name == null || name.isBlank()) { | ||
| throw new IllegalArgumentException("이름은 비어있을 수 없습니다. 애플리케이션 종료."); | ||
| } | ||
| if (name.matches(".*\\s.*")) { | ||
| throw new IllegalArgumentException("이름에는 공백을 입력할 수 없습니다. 애플리케이션 종료."); | ||
| } | ||
| if (name.length() > 5) { | ||
| throw new IllegalArgumentException(name + "의 길이가 5글자 이상입니다. 애플리케이션 종료."); | ||
| } | ||
| } | ||
| return racerNames; | ||
| } | ||
| } | ||
|
Comment on lines
+5
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package racingcar.Service; | ||
|
|
||
| public class ParseService { | ||
| public int parseInt(String roundCount) { | ||
| return Integer.parseInt(roundCount); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"테스트 코드로 확인한다."