-
Notifications
You must be signed in to change notification settings - Fork 29
[정승현_BackEnd]1주차 과제 제출 #6
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,49 @@ | ||
| package racingcar; | ||
|
|
||
| import java.util.Scanner; | ||
| import java.util.Random; | ||
|
Comment on lines
+2
to
+3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 프로그래밍 요구사항에 "JDK에서 제공하는 Random 및 Scanner API 대신 camp.nextstep.edu.missionutils의 Randoms 및 Console API를 사용하여 구현해야 한다"고 되어 있어요. 이 부분은 꼭 변경이 필요합니다. |
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| Random r = new Random(); | ||
| Scanner sc = new Scanner(System.in); | ||
|
|
||
| int n = sc.nextInt(); | ||
| String[][] car = new String[n][2]; | ||
|
|
||
| int set = sc.nextInt(); | ||
|
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기능 요구사항에서 입력 순서는 자동차 이름(쉼표 구분) → 시도 횟수 순서인데, 현재 코드는 자동차 수 → 시도 횟수 → 이름 순서로 받고 있어요. 입출력 예시를 다시 확인해보면 좋겠습니다.
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. n, r, sc, set 같은 변수명이 의미를 파악하기 어려워요. carCount, tryCount 같이 의미가 드러나는 이름을 쓰면 코드를 읽기 더 편해집니다. |
||
|
|
||
| for(int i = 0; i < n; i++) { | ||
| car[i][0] = sc.next(); | ||
| car[i][1] = ""; | ||
| } | ||
|
|
||
| for(int i = 0; i < set; i++) { | ||
| for(int j = 0; j < n; j++) { | ||
| int num = r.nextInt(10); | ||
| if(num >= 4) { | ||
| car[j][1] += "-"; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기능 요구사항에서 "각 차수별 실행 결과"를 출력하도록 되어 있는데, 현재는 모든 라운드가 끝난 뒤 최종 결과만 출력하고 있어요. 매 라운드마다 현재 상태를 출력해보면 좋겠습니다.
Comment on lines
+20
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 프로그래밍 요구사항에 "indent depth를 3이 넘지 않도록 구현한다"가 있는데, 여기서 depth가 4까지 들어가고 있어요. 메서드를 분리하면 depth를 줄일 수 있습니다. |
||
|
|
||
| for(int i = 0; i < n; i++) { | ||
| System.out.println(car[i][0] + ":" + car[i][1]); | ||
| } | ||
|
|
||
| int max = 0; | ||
|
|
||
| for(int i = 0; i < n; i++) { | ||
| int distance = car[i][1].length(); | ||
| if(distance > max) { | ||
| max = distance; | ||
| } | ||
| } | ||
|
|
||
| System.out.print("우승자: "); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 출력 형식이 요구사항의 "최종 우승자 : pobi, jun"과 다르고, 공동 우승자도 쉼표로 구분해야 해요. 입출력 예시를 한 번 더 확인해보면 좋겠습니다. |
||
| for(int i = 0; i < n; i++) { | ||
| if(car[i][1].length() == max) { | ||
| System.out.print(car[i][0] + " "); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
"사용자가 잘못된 값을 입력할 경우 IllegalArgumentException을 발생시킨 후 애플리케이션은 종료되어야 한다"는 요구사항이 있는데, 입력 검증과 예외 처리 로직이 빠져 있어요.
"자동차 이름은 5자 이하만 가능하다"는 요구사항에 대한 검증 로직도 추가해보면 좋겠습니다.