Open
Conversation
dh2906
reviewed
Mar 29, 2026
Collaborator
dh2906
left a comment
There was a problem hiding this comment.
고생하셨습니다!
레이싱 게임의 과정이 몇 단계로 되어있는지 생각해보시고 각 단계를 메소드로 분리해주세요!
| - 자동차 이릅 입력받기 | ||
| - 시도할 횟수 입력받기 | ||
| - 입력받은 자동차 이름이 5자 이하인지 확인하기 | ||
| - 숫자에 따라 자동차가 전진/후진 할지 결정하기 |
Comment on lines
+19
to
+26
| if (names[i].isEmpty()) // 빈값 (예: pobi,,woni) | ||
| { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| if (names[i].contains(" ")) // 이름에 공백 포함 (예: pobi, woni) | ||
| { | ||
| throw new IllegalArgumentException(); | ||
| } |
Collaborator
There was a problem hiding this comment.
Suggested change
| if (names[i].isEmpty()) // 빈값 (예: pobi,,woni) | |
| { | |
| throw new IllegalArgumentException(); | |
| } | |
| if (names[i].contains(" ")) // 이름에 공백 포함 (예: pobi, woni) | |
| { | |
| throw new IllegalArgumentException(); | |
| } | |
| if (names[i].isBlank()) | |
| { | |
| throw new IllegalArgumentException(); | |
| } |
이런 식으로 통합할 수도 있어 보여요!
isEmpty랑 isBlank의 차이를 찾아보시는걸 추천드립니다.
| } | ||
| } | ||
|
|
||
| // 2. 이름 중복 예외 처리 (이중 for문으로 하나씩 비교) |
Collaborator
There was a problem hiding this comment.
컬렉션 중에 중복을 허용하지 않는 자료구조가 있습니다!
찾아보시고 적용도 해보시면 좋을 것 같아요.
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| int[] position = new int [names.length]; |
Collaborator
There was a problem hiding this comment.
-
이러면 자동차의 이름과 위치를 담당하는 배열이 분리되어 있으니 이를 하나로 묶는게 낫지 않을까요?
-
어떻게 묶을까요?
| { | ||
| for (int j = 0 ; j < names.length; j++) | ||
| { | ||
| int randomnum = camp.nextstep.edu.missionutils.Randoms.pickNumberInRange(0,9); |
Collaborator
There was a problem hiding this comment.
3번 라인처럼 import를 사용하면 랜덤 값을 꺼내기 위한 메소드를 사용하는데 이렇게 긴 코드가 필요하지 않을거에요
Comment on lines
+66
to
+67
| int randomnum = camp.nextstep.edu.missionutils.Randoms.pickNumberInRange(0,9); | ||
| if (randomnum >= 4) |
Collaborator
There was a problem hiding this comment.
Suggested change
| int randomnum = camp.nextstep.edu.missionutils.Randoms.pickNumberInRange(0,9); | |
| if (randomnum >= 4) | |
| if (pickNumberInRange(0,9) >= 4) |
-
바로 이런 식으로 한다면
randomnum이라는 변수는 필요없지 않을까요? -
자바에서는 변수명을 카멜케이스로 사용하는 것이 컨벤션 입니다. 자바의 네이밍 컨벤션에 대해서도 찾아보시는걸 추천드려요!
Comment on lines
+73
to
+76
| for(int k = 0; k < position[j]; k++) | ||
| { | ||
| System.out.print("-"); | ||
| } |
Collaborator
There was a problem hiding this comment.
String.repeat() 메소드를 사용한다면 반복문이 필요없어져요!
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.
과제를 진행하면서 어려운 점 보다는 처음 테스트를 실행을 하려고 하는데 자꾸 에러가 발생해 어떤 문제지 찾다가 캐시무효화를 시키니 정상작동을 하는 것을 알 수 있었습니다.
