-
Notifications
You must be signed in to change notification settings - Fork 55
[서유정_BackEnd] 2주차 과제 제출합니다. #45
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?
Conversation
DHkimgit
left a comment
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.
과제하느라 수고하셨습니다. 깔끔하고 간결한 코드라 이해하기 편했어요! 다음번에는 커밋 하실 때 기능 단위로 해주시면 좋을 것 같아요. 깃허브 커밋 메시지 컨벤션 키워드를 찾아보세요!
| public String getPositionToString(){ | ||
| return "-".repeat(position); | ||
| } |
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.
repeat 👍
| public void move(){ | ||
| if (pickNumberInRange(0, 9) >= 4) { | ||
| position += 1; | ||
| } | ||
| } |
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.
조건문의 4와 같은 값을 상수로 선언하면 어떤 장점이 생길까요?
| public Car(String name){ | ||
| if (name.length() > 5) { | ||
| throw new IllegalArgumentException("오류: 문자열은 최대 5글자까지만 입력할 수 있습니다."); | ||
| } | ||
| this.name = name; | ||
| } |
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.
Car의 생성자가 검증의 책임을 갖도록 해주셨네요. 이 부분을 private 메서드로 분리하는건 어떨까요?
|
|
||
| public class Car { | ||
| private String name; | ||
| private int position = 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.
객체지향 수업 전인데 클레스로 분리 해주셨네요 👍👍
| for (int i = 0; i < count; i++) { | ||
| for (Car car: cars){ | ||
| car.move(); | ||
| System.out.println(car.getName() + " : " + car.getPositionToString()); | ||
| } | ||
| System.out.println(); | ||
| } |
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.
함수를 사용해 코드를 기능 단위로 분리할 수 있습니다. 분리된 함수에 역할이 명확히 드러나도록 이름을 잘 지어 놓으면 함수 이름만 읽어도 어떤 작업을 하는 코드인지 알 수 있고, 전체적인 흐름 파악도 쉬워져요.
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| System.out.println("경주할 자동차 이름을 입력하세요. (이름은 쉼표(,) 기준으로 구분)"); | ||
| String[] names = readLine().split(","); |
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.
join, repeat, split 등 자바에서 제공하는 api를 적극적으로 사용해 주셨네요!
dradnats1012
left a comment
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.
고생하셨습니다!
기능별 메서드 분리만 좀 더 해주면 가독성이 좀 더 좋아질 것 같아요~!
| for (Car cars : winners) { | ||
| if (cars.getPosition() > winnerPosition) { | ||
| winnerPosition = cars.getPosition(); | ||
| } | ||
| } |
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.
이런것들도 따로 메서드로 분리할 수 있을 것 같아요!
ex) private int findWinnerPosition(), private int findMaxPosition()
1주차 과제 제출합니다.