Skip to content

김도완_backend 1주차 과제제출#3

Open
gimdowan wants to merge 3 commits intoBCSDLab-Edu:mainfrom
gimdowan:homework
Open

김도완_backend 1주차 과제제출#3
gimdowan wants to merge 3 commits intoBCSDLab-Edu:mainfrom
gimdowan:homework

Conversation

@gimdowan
Copy link
Copy Markdown

No description provided.

@gimdowan gimdowan changed the title 레이싱게임 과제제출 김도완_backend 1주차 과제제출 Mar 29, 2026
@gimdowan
Copy link
Copy Markdown
Author

image 테스트 확인 완료했습니다!

Copy link
Copy Markdown
Collaborator

@dh2906 dh2906 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

  1. 코드들이 공백없이 붙어있어서 가독성이 떨어지고 있어요.
    코드에서 다른 맥락이 시작된다면 공백으로 구분짓는게 좋을 것 같습니당

  2. 현재 main() 메소드는 레이싱 게임을 위한 모든 과정을 담당해야 하는 책임을 지고 있어요.
    레이싱 게임에서 과정을 구분 지어보고 각 과정을 메소드로 분할해주세요!

}
// 자동차를 배열로 받고 시행횟수 받고 배열만들고
// 랜덤함수 돌리고 숫자 넘으면 -를 배열에 들어간 숫자만큼 반복하고
//비교 하고 최종우승자 나오게해보자 No newline at end of file
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

깃허브에 코드를 올릴때는 맨 마지막 라인에 공백이 들어와야 해요!

자료 참고바랍니당

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

넵!알겠습니다

Comment on lines +13 to +17
if (cars[i].isEmpty()) {
throw new IllegalArgumentException("이름은 비어 있을 수 없음");
}
if (!cars[i].equals(cars[i].trim())) {
throw new IllegalArgumentException("이름에 공백 불가");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

두 조건문을 String.isBlank() 메소드로 대체할 수 있어 보여요.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

오 한번 찾아보겠습니다!

}
}
System.out.println("시도할 회수는 몇회인가요?");
String input = sc.nextLine();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

시도 횟수를 입력받을 때 처음부터 sc.nextInt()를 사용하지 않은 이유가 있으신가요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

자바를 처음 배워서 블로그를 참조하였는데 블로그에서 저런식으로 문자열로 받고 정수형 변환하는 것을 보고 배웠는데 더 단순하게 할 수 있었네요!!

} catch (NumberFormatException e) {
throw new IllegalArgumentException("횟수는 숫자여야 함"); //catch에 있는 문장을 읽고 IllegalArgumentException을 통하여 프로그램 종료
}
int[] arr = new int[cars.length];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

이 배열은 자동차의 위치를 저장하는 배열로 보이는데 이렇게 되면 자동차의 이름 배열, 자동차의 위치 배열로 분리되어 관리 포인트가 2개가 되므로 클래스를 사용해서 하나로 합치는건 어떻게 생각하시나요??

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

오..... 한 번 노력해보겠습니다!

Comment on lines +44 to +47
int randNum = Randoms.pickNumberInRange(0, 9); //기존에 import java.util.Random을 사용하였었는데 테스트가 통과하지 않아 바꿨습니다!
if (randNum >= 4) {
arr[j] += 1;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
int randNum = Randoms.pickNumberInRange(0, 9); //기존에 import java.util.Random을 사용하였었는데 테스트가 통과하지 않아 바꿨습니다!
if (randNum >= 4) {
arr[j] += 1;
}
if (Randoms.pickNumberInRange(0, 9) >= 4) {
arr[j] += 1;
}

이렇게 하면 randNum이라는 변수가 더이상 필요하지 않아보여요!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

이렇게 하면 randNum도 필요없고 코드가 더 짧아지네요!

Comment on lines +49 to +51
for (int k = 0; k < arr[j]; k++) {
System.out.print("-");
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

반복문으로도 할 수 있지만, String.repeat() 메소드가 있습니다!
찾아보시는걸 추천드려요.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

한 번 찾아보겠습니다!

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.

2 participants