Skip to content
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

Car 출발(1회) 구현완료 #1

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Car 출발(1회) 구현완료 #1

wants to merge 4 commits into from

Conversation

wapago
Copy link
Contributor

@wapago wapago commented Apr 29, 2023

No description provided.

@wapago wapago requested review from chs1234 and dongKos April 29, 2023 15:16
Copy link

@dongKos dongKos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

프로그램이 정상 동작 하지 않습니다 😢
스크린샷 2023-04-30 오전 9 50 20

@dongKos
Copy link

dongKos commented Apr 30, 2023

아직 구현중인건가..?

Copy link

@chs1234 chs1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구현하는데 고생하셨다는 말씀 먼저 드리며,
커밋 메시지, 주석 등 의미가 없는 코드들은 앞으로 작업하실 때 같이 올라가지 않도록
신경써주시면 더욱 줗아질 거 같습니다!


public String[] inputCarNames() {
gameView.viewInputCarName();
String[] carNamesArray = gameView.inputCarName();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

carNamesArray 변수를 inputCarNames() 메소드 내부에서 다시 사용하지 않을 거라면
바로 리턴해줘도 좋을 거 같아요!
return gameView.inputCarName()


return playTime;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 마찬가지!
return gameView.inputPlayTime();


String[] carNamesArray = makeCarNamesArray(carNames);

// isContainSpecialChar(carNamesArray);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앞으로 커밋을 하실 때는 사용하지 않는 코드, 필요없는 주석은 지우고 올려주세요!

}

public void validateInputPlayTimes(String inputPlayTime) {
if(!inputPlayTime.matches(NUMERIC)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정규식을 이용해서 패턴매칭 검사를 하셨네요!
좋습니다!

return carNamesArray;
}

// public void isContainSpecialChar(String[] carNamesArray) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

지워주세요ㅠㅠ

Copy link

@chs1234 chs1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코멘트 추가합니다~!

this.isMove = isMove;
Car car;

public Result(Car car) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

작성하신 Result 객체는 사용하는 곳이 없는 거 같아요!


public void isCarAtLeatTwo(String[] carNamesArray) {
if(!(carNamesArray.length >= 2)) {
throw new IllegalArgumentException("최소 2대의 자동차이름을 입력해야 합니다.");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

메소드 내부에 매직넘버는 메소드 내부에서 직접 하드코딩 하지 않고
클래스 위쪽에 상수로 정의하시거나 따로 상수모음 클래스를 만들어서 관리하면 더 좋을 거 같습니다!

import java.util.*;

public class Decider {
GetRandomNumber getRandomNumber = new GetRandomNumber();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

클래스는 명사로 네이밍 해주시는 게 좋습니다.


Integer max = Collections.max(positionList);

for(Map.Entry<String, Integer> entry : positionMap.entrySet()) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key, value의 의미를 carName, position 변수명으로 바꿔주시면 좀 더 가독성이 좋아질 거 같습니다!
if (position == max) { winners.add(carName); }

Copy link

@chs1234 chs1234 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리팩토링 추천 제안 코멘트


if(canMove) {
car.setMoveMarker(currentMoveMarker + "-");
car.setPosition(currentPosition + 1);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후에 position 값을 가지고 marker로 변환하는 걸로 리팩토링 해보면 좋을 거 같아요!
그럼 Car 객체는 굳이 moveMarker라는 멤버를 갖고 있지 않아도 되서 로직이 좀 더 깔끔해질 거 같습니다!

List<Integer> positionList = new ArrayList<>();
List<String> winners = new ArrayList<>();

for(int i=0; i<carList.size(); i++) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

향상된 for문으로 리팩토링 하시면 코드가 좀 더 깔끔해질 거 같아요!

String key = entry.getKey();
Integer value = entry.getValue();

if(value == max) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int 형 비교가 아닌 Wrapper 클래스 Integer는 null을 허용할 수 있기 때문에
좀 더 안전하게 equals()로 비교하시길 추천드립니다.
cf. 인텔리제이에서도 그렇게 추천함

Copy link

@dongKos dongKos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다! 초장맛 어떠신가요? 😄

@@ -3,20 +3,38 @@
import racing.util.GetRandomNumber;

public class Car {
private final String name;
private String carName;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경되지 않는 property들은 final로 선언해주세요.


public class Cars {

public List<Car> carList = new ArrayList<>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

객체 내의 필드들은 private 접근제어자로 캡슐화를 하는것이 기본적입니다. 특별한 이유가 없다면요

public List<Car> carList = new ArrayList<>();
int playTime;

Decider decider = new Decider();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decider 라는 이름이 명확하지 않습니다. 무엇을 결정하는지? 네이밍에 포함시켜주세요

decider.decideMove(car);
}

System.out.println();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

출력구문은 이 함수에 책임이 없습니다. 뷰 단으로 분리해보면 어떨까요?

}

public void move() {
for(Car car : carList) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

향상된 for문도 좋지만 java 8의 stream을 이용해 봅시다. forEach는 stream 안써도 걍 쓸 수 있어요. 함수형 프로그래밍에 익숙해지면 코드가 간결해지고 가독성이 올라갑니다

Suggested change
for(Car car : carList) {
carList.forEach(car -> decider.decideMove(car));

// }
// }

public void isCarAtLeatTwo(String[] carNamesArray) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is~로 시작하는 함수는 보통 리턴형을 boolean으로 하는것이 관행입니다. 여기서는 validation check를 하기 때문에 명명을 조금 다르게 하는게 좋을것 같아요

Suggested change
public void isCarAtLeatTwo(String[] carNamesArray) {
public void validateIfCarsAtLeastTwo(String[] carNamesArray) {
Suggested change
public void isCarAtLeatTwo(String[] carNamesArray) {
public void throwIfCarsLessThanTwo(String[] carNamesArray) {

}
}

private void isDuplicateCarNames(String[] carNamesArray) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위와 동 입니다.

}
}

String resultStr = stringBuilder.toString();
Copy link

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<winners.size(); i++) {
stringBuilder.append(winners.get(i));

if(winners.size() != 1 && i != winners.size() - 1) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2단으로 들어가기 금지 입니다 :) 수정해주세요

import java.util.Scanner;

public class GameView {
Scanner scanner = new Scanner(System.in);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

외부에서 사용하지 않아야 하기 때문에 private final을 붙여주세요

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants