Skip to content

Conversation

@Soe-Yujeong
Copy link

1주차 과제 제출합니다.

Copy link

@DHkimgit DHkimgit 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 +22 to +24
public String getPositionToString(){
return "-".repeat(position);
}

Choose a reason for hiding this comment

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

repeat 👍

Comment on lines +16 to +20
public void move(){
if (pickNumberInRange(0, 9) >= 4) {
position += 1;
}
}

Choose a reason for hiding this comment

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

조건문의 4와 같은 값을 상수로 선언하면 어떤 장점이 생길까요?

Comment on lines +9 to +14
public Car(String name){
if (name.length() > 5) {
throw new IllegalArgumentException("오류: 문자열은 최대 5글자까지만 입력할 수 있습니다.");
}
this.name = name;
}

Choose a reason for hiding this comment

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

Car의 생성자가 검증의 책임을 갖도록 해주셨네요. 이 부분을 private 메서드로 분리하는건 어떨까요?

Comment on lines +4 to +8

public class Car {
private String name;
private int position = 0;

Choose a reason for hiding this comment

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

객체지향 수업 전인데 클레스로 분리 해주셨네요 👍👍

Comment on lines +22 to +28
for (int i = 0; i < count; i++) {
for (Car car: cars){
car.move();
System.out.println(car.getName() + " : " + car.getPositionToString());
}
System.out.println();
}

Choose a reason for hiding this comment

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

함수를 사용해 코드를 기능 단위로 분리할 수 있습니다. 분리된 함수에 역할이 명확히 드러나도록 이름을 잘 지어 놓으면 함수 이름만 읽어도 어떤 작업을 하는 코드인지 알 수 있고, 전체적인 흐름 파악도 쉬워져요.

public static void main(String[] args) {
// TODO: 프로그램 구현
System.out.println("경주할 자동차 이름을 입력하세요. (이름은 쉼표(,) 기준으로 구분)");
String[] names = readLine().split(",");

Choose a reason for hiding this comment

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

join, repeat, split 등 자바에서 제공하는 api를 적극적으로 사용해 주셨네요!

@Soe-Yujeong Soe-Yujeong changed the title [서유정_BackEnd] 1주차 과제 제출합니다. [서유정_BackEnd] 2주차 과제 제출합니다. Mar 31, 2025
Copy link

@dradnats1012 dradnats1012 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 +11 to +15
for (Car cars : winners) {
if (cars.getPosition() > winnerPosition) {
winnerPosition = cars.getPosition();
}
}

Choose a reason for hiding this comment

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

이런것들도 따로 메서드로 분리할 수 있을 것 같아요!
ex) private int findWinnerPosition(), private int findMaxPosition()

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