-
Notifications
You must be signed in to change notification settings - Fork 0
Java racing car 이현 #4
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?
The head ref may contain hidden characters: "java_racing_car_\uC774\uD604"
Conversation
bit.ly/3g4kkS5
shkisme
left a comment
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.
리뷰가 조금 늦었습니다! 🙇♀️ stream 을 아주 잘 쓰시네요 ㅎㅎ
| private void printStatus() { | ||
| carList.forEach(car -> | ||
| System.out.printf("%s : %s\n", car.getName(), | ||
| PROGRESS_BAR.repeat(car.getPosition()))); |
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.
👍👍👍 for 문으로 돌리는 것보다 훨씬 간결합니다
| public static final int RANDOM_MIN_NUMBER = 4; | ||
| public static final String SEPARATOR = ","; | ||
| public static final String PROGRESS_BAR = "-"; | ||
| public static final Scanner SCANNER = new Scanner(System.in); |
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.
의미가 있는 상수, 자주쓰는 상수, Scanner 들을 Util 클래스로 분리하신 점 좋습니다!
|
|
||
| private void input() { | ||
| System.out.println("경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)"); | ||
| while (inputCarNames() == false) |
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.
inputCarNames 메서드가 boolean 값을 반환하고 있는데, 어떤 의미인지 명확하진 않은 것 같습니다. Enum으로 표현하는 것은 어떨까요?
ex)
while (inputCarNames() == INVALID)
;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.
Enum으로 수정하겠습니다!
| .collect(Collectors.joining(String.format("%s ", SEPARATOR)))); | ||
| } | ||
|
|
||
| public void run() { |
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.
run 메서드를 클래스 가장 밑에 두신 이유가 있나요? 코드 가독성 면에서는 위에 두는 것도 괜찮을 것 같아서요!
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.
파이썬 코드를 저렇게 짜다 보니까 습관이 되었네요..
| int maxPosition = carList.stream() | ||
| .map(Car::getPosition) | ||
| .reduce(Integer::max) | ||
| .orElse(-1); |
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.
👍👍👍👍
| private int count = 0; | ||
|
|
||
| private int randomize() { | ||
| Random r = new Random(); |
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.
Random도 Util 클래스에 두거나, GamePlayer 필드에 두는 것은 어떤가요?
|
@shkisme 수정 완료하였습니다 :) |
shkisme
left a comment
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.
수고하셨습니다! 다음 챌린지 로또게임 해보셔도 좋을 것 같네요 ㅎㅎ 👍
이번 챌린지는 functional한 기능들을 사용하여 구현해봤습니다.
확실히 코드가 길어지지 않고 한 눈에 보이네요.
시간 날 때마다 업데이트 해보겠습니다.
테스트 코드도 작성해보겠습니다 ㅎㅎ..