-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
| private String name; |
- 객체지향 생활체조 : 모든 원자 값은 포장하라
- String name 을 Name 클래스로 만들어 보세요~
java_racingcar/src/main/java/domain/Car.java
Lines 22 to 32 in a452814
| for (int i = 0; i < attempt_count; i++) { | |
| Random random = new Random(); | |
| // 0~10사이의 난수 | |
| int random_number = random.nextInt(10); | |
| if(random_number > 5){ | |
| // 해당 move_count 값을 어떻게 유지하고 있는가. | |
| move_count++; | |
| } | |
| } |
- 객체지향 생활체조 : indent 2이상
| private int move_count; |
- camel case하지 않아요. Google java style guide 읽어보세요(플레이그라운드 요구사항에 있는 것 같아요)
| public void printNames(int attempt_count) { |
- 이름을 프린트하는 메소드인지, 움직이는걸 시도하는 메소드인지 모르겠어요
- 메소드가 한가지만 작동하도록 구현해보세여
| public List<Car> getCars() { |
- 이렇게 하면 안에 일급컬렉션 만드는 의미가 없겠죠
- 불변 객체로 변환해봐요
- https://jojoldu.tistory.com/412
| public static Cars Start(){ |
- Start() 메소드가 시작하는 메소드인건지, 자동차 이름을 입력하는 건지 자동차들을 만드는 클래스인건지 모르겠어요 메소드가 한가지일만 하도록 해봐요
- 모든 메소드는 소문자로 시작해요. Google java style guide 읽어보세요~
| public static int Racing() { |
- 모든 메소드는 소문자로 시작해요. Google java style guide 읽어보세요~
- Racing의미가 경주인데 시도 횟수만 입력하는 메소드같네요 다른 사람이 보았을 때 햇갈릴 것 같아요
java_racingcar/src/main/java/ui/ResultView.java
Lines 11 to 40 in a452814
| public static void printResult(List<Car> cars) { | |
| List<String> winner_list = new ArrayList<>(); | |
| String winner = null; | |
| int max_count = 0; | |
| for (int i = 0; i < cars.size(); i++) { | |
| String current_car = cars.get(i).getName(); | |
| int last_count = cars.get(i).getMove_count(); | |
| if (last_count > max_count) { | |
| winner = current_car; | |
| max_count = last_count; | |
| } | |
| if (max_count == last_count) { | |
| winner_list.add(winner); | |
| } | |
| } | |
| System.out.println("실행 결과"); | |
| for (int i = 0; i < winner_list.size(); i++) { | |
| System.out.print(winner_list.get(i) + " "); | |
| } | |
| System.out.print("가 최종 우승했습니다."); | |
| } |
- printResult 메소드는 10줄 이내로 작성해주세요
- indent 2이상이네요 수정해주세요~
- 결과를 판별하는 메소드이기도하고, 프린트도 하고 우승자도 찾고 우승자도 프린트하는 메소드 같아요 분할하여 관리하면 좋을 것 같아요
java_racingcar/src/main/java/Main.java
Lines 12 to 23 in a452814
| Cars cars = InputView.Start(); // List<Car> Car객체를 담고 있는 Cars 객체 생성 | |
| int attempt_count = InputView.Racing(); // 게임 시도 횟수 | |
| // 시도한 횟수만큼 게임을 돈다. | |
| for (int attempt_index = 0; attempt_index < attempt_count; attempt_index++) { | |
| cars.printNames(attempt_index + 1); | |
| } | |
| List<Car> result_car = cars.getCars(); | |
| ResultView.printResult(result_car); |
- 주석은 쓰지 않습니다. (http://amazingguni.github.io/blog/2016/05/Clean-Code-4-%EC%A3%BC%EC%84%9D)
- Start() 인데 자동차 입력을 입력하고 Racing()인데 시도 횟수를 입력하고 다른 사람이 보면 이해하기 어려운 코드같아요
- '시도한 횟수만큼 게임을 돈다' 캡슐화 추상화 해보세여
- https://developerdk.tistory.com/5
고민하구 열심히 한 것 같은데 테스트 코드가 하나도 없네요..ㅜㅜ
잘하고 있는데 끝까지 해봐요. 급하게 생각하지말고 안되고 안깨우쳐지는게 당연합니다.
끝까지 해보세요~
할 수 있어요!
질문은 이슈사항에 남겨주세요~
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels