Conversation
BaeJinho4028
left a comment
There was a problem hiding this comment.
줄넘김과 공백을 잘 신경쓰시면 좋을 것 같습니당
간단한 리뷰 남깁니담. 고생하셨어요
| public void forward(String[] cars){ | ||
| for (int i =0;i < cars.length; i++){ | ||
|
|
||
| } |
|
|
||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { |
There was a problem hiding this comment.
main()에서 입력, 검증, 게임 진행, 우승자 출력까지 모두 담당하고 있어 역할별 메서드로 나누면 가독성이 더 좋아질 것 같습니다.
| for (int j = 0; j < cars.length; j++) { | ||
| int num = Randoms.pickNumberInRange(0, 9); | ||
| System.out.print(cars[j] + " : "); | ||
| if (num >= 4) {race[j] += "-";System.out.println(race[j]);count[j]++;} |
There was a problem hiding this comment.
한 줄에 여러 동작이 함께 들어가 있어, 줄을 나누면 읽기 훨씬 편해질 것 같습니다.
| String[] race = new String[cars.length]; | ||
| Arrays.fill(race,""); | ||
| int[] count = new int[cars.length]; |
There was a problem hiding this comment.
자동차 이름과 이동 상태를 각각 배열로 관리하기보다 클래스로 묶으면 데이터 관리가 더 자연스러울 것 같습니다.
BaeJinho4028
left a comment
There was a problem hiding this comment.
클래스들을 잘 쪼개보면 좋을 것 같습니다.
특히 다른 분들의 코드를 많이 참고하시는 것을 추천드립니다
| static String[] cars; | ||
| static int[] count; | ||
| static class player{//자동차 이름 및 경주 순위 클래스 | ||
| String name; | ||
| int counting; | ||
|
|
||
| player(String name, int counting){ | ||
| this.name = name; | ||
| this.counting = counting; | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| //플레이어 자동차 이름 입력받기 | ||
| static player[] playerarr; |
| static class player{//자동차 이름 및 경주 순위 클래스 | ||
| String name; | ||
| int counting; | ||
|
|
||
| player(String name, int counting){ | ||
| this.name = name; | ||
| this.counting = counting; | ||
| } | ||
| } |
There was a problem hiding this comment.
데이터를 담는 객체만 추가된 상태라기보다, 자동차가 스스로 상태와 행위를 가지는 구조로 바꾸면 더 객체지향적인 설계가 될 것 같습니다.
| public static void name(){//자동차 이름 입력 | ||
| System.out.print("경주할 자동차 이름을 입력하세요 (,로 구분하고 5자 이하) : "); | ||
| String carsinput = Console.readLine(); | ||
| String[] cars = carsinput.split(","); | ||
| cars = carsinput.split(","); | ||
|
|
||
| //이름 예외처리 | ||
|
|
||
| for(int i =0;i < cars.length;i++){ //5자 이하로 | ||
| if (cars[i].length() > 5){ | ||
| for (String car : cars) { //5자 이하로 | ||
| if (car.length() > 5) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
|
|
||
| if(cars[i].isBlank()){ //빈칸 | ||
| if (car.isBlank()) { //빈칸 | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } |
There was a problem hiding this comment.
입력을 받는 메서드가 검증과 상태 저장까지 함께 담당하고 있어 책임이 다소 많이 몰려 있습니다.
| String[] race = new String[cars.length]; | ||
| Arrays.fill(race,""); |
There was a problem hiding this comment.
race 문자열 배열로 출력 상태를 따로 관리하기보다 자동차 객체가 자신의 이동 상태를 표현하도록 하는건 어떨까요
No description provided.