Conversation
Application.java : 기능 요구 사항_차량 이름 입력받기 carInput(), carSplit() 매서드 추가
dradnats1012
left a comment
There was a problem hiding this comment.
고생하셨습니다!
변수명이나 개행, 주석같은 부분은 계속 코드를 치시다보면 익숙해질겁니다
이번주에 객체지향 관련 학습을 하시면서 Car 클래스, Racing 클래스 등 다양한 역할을 가진 클래스로 구분하는 연습을 해보시면 좋을 것 같아요 :) 👍
| // import java.util.LinkedList; | ||
| // import java.util.Queue; |
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| String carsStr = carInput(); |
There was a problem hiding this comment.
carStr이라는 변수명은 자료형이 들어가 권장되지 않는 변수명입니다!
| // 여기까지 입력 | ||
|
|
||
| Game(carsList, tryNum); | ||
|
|
|
|
||
| } | ||
|
|
||
| public static String carInput() { // 사용자 입력 (자동차 목록) |
There was a problem hiding this comment.
static으로 메서드를 선언하셨는데 이렇게 되면 어떻게 동작할까요?
객체지향에서 static 사용은 객체지향에서 어떻게 다가올까요?
| public static String[] carSplit(String carsStr) { // 사용자 한테 입려받은 문자열 "," 기준으로 찢기 | ||
| String[] carsList = carsStr.split(","); | ||
| return carsList; | ||
| } |
| } | ||
|
|
||
| public static void errCheck_carsList(String[] carsList) throws IllegalArgumentException{ // 입력한 차 이름이 5글자 이하인지 체크 | ||
| for (String s : carsList) { |
| return tryNum; | ||
| } | ||
|
|
||
| public static void errCheck_carsList(String[] carsList) throws IllegalArgumentException{ // 입력한 차 이름이 5글자 이하인지 체크 |
There was a problem hiding this comment.
메서드명에 _를 추가하셨는데 다른 메서드들과 다른 이유가 있을까요?
validate 라는 네이밍은 어떨까요?
| public static int[] move(String[] carsList, int[] moveCnt) { | ||
| for (int i = 0; i < carsList.length; i++) { | ||
| moveCnt = randomMove(moveCnt, i); | ||
| } | ||
| return moveCnt; | ||
| } |
There was a problem hiding this comment.
이렇게 되면 각 자동차들의 움직임에 대한 관리가 어려울 것 같은데 어떻게 생각하시나요?
이번주 객체지향을 공부하시면서 Car 클래스로 분리할 방법에 대해 고민해보면 좋을 것 같아요!
| } | ||
|
|
||
| public static String[] checkWinner(String[] carsList, int[] moveCnt) { | ||
| /* |
| return moveCnt; | ||
| } | ||
|
|
||
| public static void printEachMove(String[] carsList, int[] moveCnt){ |
Choon0414
left a comment
There was a problem hiding this comment.
고생하셨습니다!
기능 단위로 메서드를 분리하려고 많이 노력하신 것 같아요.
처음이라 많이 어려우셨을 텐데, 앞으로 천천히 교육을 들으면서 코드를 고쳐나가면 실력이 금방 느실 것 같습니다.
|
|
||
| } | ||
|
|
||
| public static String carInput() { // 사용자 입력 (자동차 목록) |
There was a problem hiding this comment.
메서드 명명 규칙에 대해 찾아보면 좋을 것 같습니다!
짧고 간결한 것도 좋지만, 이름을 통해 역할을 잘 표현하는 것도 중요합니다.
| for (int i = 0; i < moveCnt.length; i++) { | ||
| if(moveCnt[i] == maxValue) { | ||
| winner[cnt] = carsList[i]; | ||
| cnt++; |
There was a problem hiding this comment.
두 분기점에서 공통으로 수행하는 부분은 if문 바깥에 구현해주는 건 어떤가요?
| printEachMove(carsList, moveCnt); | ||
| } | ||
|
|
||
| String[] winner = checkWinner(carsList, moveCnt); |
There was a problem hiding this comment.
리뷰해주신 메서드 명, if문 구현, 매서드 분리 리팩토링 해보겠습니다.!
… for-each 문 변수명 변경
errCheck_carsList() -> validateCarsList() errCheck_tryNum() -> validateTryNum()
|
분발해라 |
No description provided.