-
Notifications
You must be signed in to change notification settings - Fork 3
[java-baseball] yohan.kim(김요한) 과제 제출합니다. #2
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: yohan/java-baseball
Are you sure you want to change the base?
[java-baseball] yohan.kim(김요한) 과제 제출합니다. #2
Conversation
swandevson
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.
고생하셨습니다!
| # 기능 목록 | ||
|
|
||
| - [x] 게임 관리 - GameManager class | ||
| - [x] 게임 시작 - start() | ||
| - [x] 숫자 야구 구현 - BaseballGame class | ||
| - [x] 세 자리수 랜덤 숫자 생성 - generateAnswer() | ||
| - [x] 사용자 입력 받기 - receiveUserInput() | ||
| - [x] 사용자 숫자를 받아 채점 및 정답 여부 반환 - score() |
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.
각 기능에 대한 예외사항과 핸들링도 기재되면 좋을 것 같습니다!
| public int receiveUserInput() { | ||
| System.out.print("숫자를 입력해주세요 : "); | ||
|
|
||
| String input = Console.readLine(); | ||
| validateInput(input); | ||
|
|
||
| try { | ||
| return Integer.parseInt(input); | ||
| } catch (NumberFormatException e) { | ||
| throw new IllegalArgumentException("잘못된 입력 형식입니다."); | ||
| } | ||
| } |
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.
해당 부분은 view로 분리할 수 있을 것 같아보입니당
| while (numbers.size() < 3) { | ||
| numbers.add(Randoms.pickNumberInRange(1, 9)); | ||
| } |
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.
3, 1, 9와 같은 숫자를 상수로 선언해 사용하시는건 어떨까요?
| if (strike == 3) { | ||
| System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료"); | ||
| return true; | ||
| } |
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.
출력과 boolean값 return을 동시에 해서 두가지 일을 하는 것 처럼 보입니다
외부에서 ture/false에 따라 출력 여부를 결정하도록 변경하면 어떨까요?
KimGyeongLock
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.
수고하셨습니다!
공부하는데 많이 참고할 것 같습니다!
|
|
||
| public class BaseballGame { | ||
|
|
||
| private Integer answer; |
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가 아닌 Integer을 사용한 이유가 궁금합니다!
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.
의도는 generateAnswer()에서 answer에 값을 넣어주는 부분이 있는데,
int 자료형이면 값 참조를 못해서, 값이 안들어갈까봐 Integer로 설정해주었습니다!
그런데, 찾아보니까 int여도 값이 잘 들어간다고 하네요ㅠ
int로 바꾸는게 더 좋을 것 같습니다.
[java-baseball] yohan.kim(김요한) 과제 제출합니다.