Skip to content

Conversation

@yohanii
Copy link
Member

@yohanii yohanii commented Sep 23, 2024

[java-baseball] yohan.kim(김요한) 과제 제출합니다.

Copy link

@swandevson swandevson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

Comment on lines +1 to +8
# 기능 목록

- [x] 게임 관리 - GameManager class
- [x] 게임 시작 - start()
- [x] 숫자 야구 구현 - BaseballGame class
- [x] 세 자리수 랜덤 숫자 생성 - generateAnswer()
- [x] 사용자 입력 받기 - receiveUserInput()
- [x] 사용자 숫자를 받아 채점 및 정답 여부 반환 - score()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

각 기능에 대한 예외사항과 핸들링도 기재되면 좋을 것 같습니다!

Comment on lines +41 to +52
public int receiveUserInput() {
System.out.print("숫자를 입력해주세요 : ");

String input = Console.readLine();
validateInput(input);

try {
return Integer.parseInt(input);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("잘못된 입력 형식입니다.");
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 부분은 view로 분리할 수 있을 것 같아보입니당

Comment on lines +29 to +31
while (numbers.size() < 3) {
numbers.add(Randoms.pickNumberInRange(1, 9));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3, 1, 9와 같은 숫자를 상수로 선언해 사용하시는건 어떨까요?

Comment on lines +93 to +96
if (strike == 3) {
System.out.println("3개의 숫자를 모두 맞히셨습니다! 게임 종료");
return true;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

출력과 boolean값 return을 동시에 해서 두가지 일을 하는 것 처럼 보입니다
외부에서 ture/false에 따라 출력 여부를 결정하도록 변경하면 어떨까요?

Copy link

@KimGyeongLock KimGyeongLock left a 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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int가 아닌 Integer을 사용한 이유가 궁금합니다!

Copy link
Member Author

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로 바꾸는게 더 좋을 것 같습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants