-
Notifications
You must be signed in to change notification settings - Fork 7
2nd / 3rd 과제 PR _ 문자열 사칙 연산 계산기 구현 / 초간단 자동차 경주 게임 #25
base: CJiu01
Are you sure you want to change the base?
Conversation
실수로 코드 작성을 vsc에서 하다가 commit 했더니 문제가 생겨 원래 있던 폴더들이 사라져버렸는데 다시 fork 해야 할까요..? |
@CJiu01 기존에 있던 파일들을 삭제한걸로 나와요. |
src/main/java/Calculator.java
Outdated
return Integer.parseInt(str); | ||
} | ||
|
||
public String[] seperate(String str){ |
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.
seperate
->separate
오타 같습니다 :)- 이 메소드는 public 일 필요가 없습니다.
src/main/java/Calculator.java
Outdated
return result; | ||
} | ||
|
||
public int getInt(String str){ |
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 일 필요가 없습니다.
src/main/java/Calculator.java
Outdated
@@ -0,0 +1,19 @@ | |||
public class Calculator { | |||
public int calculateUser(String input) { |
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.
메소드 이름은 calculateUserInput 정도가 어떨까요?
src/main/java/Control.java
Outdated
InputView inputView = new InputView(); | ||
inputView.setUpRacingGame(); | ||
|
||
RacingGame racingGame = new RacingGame(); | ||
racingGame.readyGame(inputView.getCarCount()); | ||
racingGame.startGame(inputView.getTryCount()); |
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.
InputView 가 별도로 분리되어 있는 구조 좋습니다 👍
src/main/java/RacingCar.java
Outdated
|
||
public class RacingCar { | ||
private int successCount; | ||
private final Random random = new Random(); |
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.
Random 때문에 테스트가 어렵습니다. 줌 수업을 통해서 개선방법을 알려드렸습니다.
밖으로 분리해보세요 :)
src/main/java/RacingGame.java
Outdated
|
||
public class RacingGame { | ||
|
||
private final List<RacingCar> cars = new ArrayList<>(); |
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.
cars 를 List 로 관리하지 않고 일급 컬렉션 객체로 관리할 수 있습니다.
First collection class
src/main/java/RacingGame.java
Outdated
private final List<RacingCar> cars = new ArrayList<>(); | ||
private final ResultView resultView = new ResultView(); | ||
|
||
void readyGame(int carCount){ |
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 / private 을 붙여주는게 좋습니다.
public int move(boolean isSuccess) { | ||
if(isSuccess){ | ||
position++; | ||
} | ||
return 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.
move를 굳이 isSuccess 를 전달할 필요는 없어보입니다.
그냥 move()
면 되지 않을까 하네요 :)
return names.split(","); | ||
} | ||
|
||
private void readyGame(String[] cars) { |
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.
요런 역할이라면 readyGame
보다는 initGame
이라고 많이 씁니다
public String getNames() { | ||
return inputNames; | ||
} | ||
|
||
public int getTryCount(){ | ||
return tryCount; | ||
} |
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.
InputValues 객체를 따로 만들어서 전달하는게 어떨까요?
그렇게 되면 Control 객체에서도 두번 메소드를 호출하지 않아도 됩니다.
|
||
public class RacingCars { | ||
|
||
private final Map<Car, List<Integer>> positionInfo = new HashMap<>(); |
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.
Map 안에 List 가 있는 구조보다는 결과를 기록하는 별도의 클래스를 만들어보면 좋겠습니다.
public Map<Car, List<Integer>> getPositionInfo() { | ||
return positionInfo; | ||
} |
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.
Cars 가 Car 객체를 다루고 있는데 반환타입에 Car 를 포함하고 있는 Map을 반환하게 되면
일급 콜렉션 객체가 Car 를 담고 있는 의미가 퇴색됩니다.
System.out.println(winnerName + " 가 최종우승했습니다."); | ||
} | ||
|
||
private void showCarPosition(Car car, int 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.
ResultView 에서 RacingCars 와의 연관되어 있는데
그 하위에 Car를 다시 알고 있어야 되는 관계가 형성되어 있습니다. 이를 개선해봐주세요 :)
[Add] 1st commit