Conversation
Choon0414
left a comment
There was a problem hiding this comment.
첫 주 과제 고생하셨습니다!
공부하면서 배운 것들을 여러가지 시도해 보신 것 같네요. 다만 문법과 개념을 좀 더 보완하면 좋을 것 같습니다.
다른 분들의 코드를 보며 새로 배워가는 것도 정말 좋지만, 내가 무엇을 모르는지 인지하고 해당 부분을 보완해 나가는 걸 병행하는 것도 중요하다 생각합니다.
| Car car = new Car(); | ||
| Racing Game = new Racing(); | ||
|
|
||
| car.get_Car_Names(); |
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| Car car = new Car(); | ||
| Racing Game = new Racing(); |
There was a problem hiding this comment.
car와 Game에서 각각 소문자/대문자를 사용하신 이유가 궁금합니다!
There was a problem hiding this comment.
사실 이름에 대해서는 크게 신경을 쓰지 않은 것 같습니다. 자바 네이밍 규칙 준수하겠습니다.
| import camp.nextstep.edu.missionutils.Randoms; | ||
|
|
||
| class Car { | ||
| private static final int MOVING_FORWARD = 4; |
There was a problem hiding this comment.
여기도 MOVING_FORWARD와 start/end의 변수 명명을 구분하신 이유가 있으신가요?
변수와 상수의 차이에 대해 알아보시면 좋을 것 같습니다!
src/main/java/racingcar/Car.java
Outdated
| protected int[] Move_count; | ||
|
|
||
| // 자동차 수 만큼 int 배열 정의 | ||
| protected void get_Players_Move() { Move_count = new int[Car_Names.length]; } |
There was a problem hiding this comment.
메서드 내용이 한 줄이어도 다른 메서드랑 같은 형태로 가져가는걸 추천드려요.
src/main/java/racingcar/Racing.java
Outdated
| import java.util.ArrayList; | ||
|
|
||
|
|
||
| public class Racing extends Car { |
There was a problem hiding this comment.
개념적으로 Racing(경주)와 Car(자동차)의 관계가 어떻게 되는지 한 번 더 고민해보면 좋을 것 같아요.
extends를 시도해보신 건 좋습니다!
상속은 주로 동물 > 강아지/고양이, 자동차 > 승용차/화물차 와 같은 관계에서 많이 사용이 됩니다.
src/main/java/racingcar/Racing.java
Outdated
| round = Integer.parseInt(input); | ||
|
|
||
| // 입력 예외 처리 | ||
| if (round < 0) { throw new IllegalArgumentException("시도 횟수는 음수일 수 없습니다."); } |
src/main/java/racingcar/Car.java
Outdated
| // 이름 예외 처리 | ||
| for (int i = 0; i < Car_Names.length; i++) { | ||
| Car_Name = Car_Names[i]; | ||
| if (Car_Name.length() > 5) { throw new IllegalArgumentException("이름은 5자 이하만 가능합니다."); } |
There was a problem hiding this comment.
제한 글자수도 상수로 선언해보는 건 어떨까요?
ex) carName.length() > MAX_LENGTH
Car 클래스, Racing 클래스를 만들어서 해결했습니다.
우승자를 찾기 위해서 Racing 클래스의 게임 종료 및 우승자 출력 함수에서 최대 이동 횟수를 찾고, 참가자의 이동 횟수가 최대 이동 횟수와 똑같다면 우승자 리스트에 추가했습니다. 다른 좋은 방법이 있다면 알려주세요.