-
Notifications
You must be signed in to change notification settings - Fork 10
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
[숫자 야구 게임] 박지현 미션 제출합니다. #13
base: main
Are you sure you want to change the base?
Conversation
for (int i = 0; i < 3; i++) { | ||
do { | ||
duplicate = false; | ||
r[i] = 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.
변수명을 좀더 명확하게 변경해주세요
import camp.nextstep.edu.missionutils.Randoms; | ||
|
||
public class RandomNumber { | ||
void randomNumber(int[] r){ |
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.
배열이 아닐 list를 사용해서 contains함수를 사용해보세요
int countBall(int[] r, String[] str) { | ||
for (int i = 0; i < 3; i++) { | ||
for (int j = 0; j < 3; j++) { | ||
if (i != j && r[i] == Integer.parseInt(str[j])) { |
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.
블록 들여쓰기가 너무 많으면 가독성이 떨어집니다. 메소드를 분리하거나 java 라이브러리 함수를 사용해보세요~~
public class Application { | ||
public static void main(String[] args) { | ||
// TODO: 프로그램 구현 | ||
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 말고 과제에서 제공한 라이브러리에 있는 Console.read를 사용하세요
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 scanner = new Scanner(System.in); | ||
|
||
System.out.println("숫자 야구 게임을 시작합니다."); | ||
int[] randoms = new int[3]; |
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넘버 배열을 RandomNumber에서 생성해도 될거 같아요
|
||
while (true) { | ||
try { | ||
System.out.print("숫자를 입력해주세요 : "); |
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.
한 게임을 하는 기능이랑 게임을 재시작하는 기능을 분리할 수 있을거 같아요!
|
||
String answer = Console.readLine(); | ||
ExceptionHandler exceptionHandler = new ExceptionHandler(); | ||
exceptionHandler.checkValid(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.
예외처리 클래스를 만든것은 아주 좋은 생각이에요!!
package baseball; | ||
|
||
public class ExceptionHandler { | ||
void checkValid(String 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.
예외를 좀더 생각해보면서 다양한 경우를 생각해보세요!! 다양한 경우에 따라 메소드를 분리해보면 좀더 명확하겠죠?
|
||
if (count.getStrikes() == 3) { | ||
System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요."); | ||
int option = scanner.nextInt(); |
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.
Console.read를 사용하세요
야구 게임