-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
๐ 4๋จ๊ณ - ์๋์ฐจ ๊ฒฝ์ฃผ(์ฐ์น์) #6061
base: kjy2844
Are you sure you want to change the base?
Conversation
- [x] `Car` ํด๋์ค์ ์ด๋ฆ ํ๋ ์ถ๊ฐ - [x] ์ด๋ฆ ์ ํจ์ฑ ๊ฒ์ฌ (5์ ์ด๊ณผ ๋ถ๊ฐ) - [x] `Car` ์์ฑ์์ ์ด๋ฆ ํ๋ผ๋ฏธํฐ ์ถ๊ฐ - [x] `CarTest`์ ์ด๋ฆ ๊ด๋ จ ํ ์คํธ ์ถ๊ฐ - [x] ์ด๋ฆ์ด 5์๋ฅผ ์ด๊ณผํ๋ฉด ์์ธ ๋ฐ์ - [x] ์ ํจํ ์ด๋ฆ์ผ๋ก ์์ฑ ๊ฐ๋ฅ
- [x] `ResultView` ์์ - [x] ์๋์ฐจ ์ด๋ฆ๊ณผ ์์น๋ฅผ ํจ๊ป ์ถ๋ ฅํ๋ ํ์ ๋ณ๊ฒฝ - [x] `presentCars` ๋ฉ์๋ ํ๋ผ๋ฏธํฐ ์์ (์ด๋ฆ ์ ๋ณด ์ถ๊ฐ) - [x] `Race` ํด๋์ค ์์ - [x] `getCarPositions` ๋ฉ์๋๋ฅผ `getCarStatus`๋ก ๋ณ๊ฒฝ - [x] ์๋์ฐจ ์ด๋ฆ๊ณผ ์์น๋ฅผ ํจ๊ป ๋ฐํํ๋๋ก ์์
- [x] `InputView` ์์ - [x] ์๋์ฐจ ์ด๋ฆ ์ ๋ ฅ ๋ฉ์๋ ์ถ๊ฐ - [x] ์ผํ๋ก ๊ตฌ๋ถ๋ ์ด๋ฆ ๋ฌธ์์ด ํ์ฑ ๋ก์ง ์ถ๊ฐ - [x] `GameSettings` ์์ - [x] ์๋์ฐจ ์ด๋ฆ ๋ชฉ๋ก ํ๋ ์ถ๊ฐ - [x] ์์ฑ์ ์์
- [x] `Race` ํด๋์ค์ ์ฐ์น์ ํ์ ๋ก์ง ์ถ๊ฐ - [x] `getWinners` ๋ฉ์๋ ์ถ๊ฐ - [x] ๊ฐ์ฅ ๋ฉ๋ฆฌ ๊ฐ ์๋์ฐจ๋ค ์ฐพ๊ธฐ - [x] `ResultView`์ ์ฐ์น์ ์ถ๋ ฅ ๋ฉ์๋ ์ถ๊ฐ - [x] `Game` ํด๋์ค ์์ - [x] ๊ฒฝ์ฃผ ์ข ๋ฃ ํ ์ฐ์น์ ์ถ๋ ฅ ๋ก์ง ์ถ๊ฐ
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.
์๋
ํ์ธ์ panya ๋~ 4๋จ๊ณ๋ ๋น ๋ฅด๊ฒ ์ ์งํํด์ฃผ์
จ์ต๋๋ค!
์์ฑ๋๊ฐ ๋๊ธฐ ๋๋ฌธ์ ๋ช ๊ฐ์ง ๊ณ ๋ฏผํด๋ณด์ค๋งํ ํฌ์ธํธ์ ์ฝ๋ฉํธ ๋จ๊ฒผ์ต๋๋ค.
๊ถ๊ธํ์ ์ ์ธ์ ๋ ์ง ํธํ๊ฒ ์ง๋ฌธ์ฃผ์ธ์~
private void validateName(String name) { | ||
if (name == null || name.trim().isBlank()) { | ||
throw new IllegalArgumentException("Name cannot be blank"); | ||
} | ||
if (name.length() > 5) { | ||
throw new IllegalArgumentException("Name cannot be longer than 5 characters"); | ||
} |
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.
๊ณต๋ฐฑ์ ๋ํ ๊ฒ์ฆ์ ํ๊ณ ์ ํ๋ค๋ฉด trim()
์ ์๋ต ๋์ด๋ ๊ฐ์ ํจ๊ณผ๊ฐ ๋์ฌ๊ฑฐ ๊ฐ์์ ๐
for (String name : carNames) { | ||
if (name == null || name.trim().isEmpty()) { | ||
throw new IllegalArgumentException("์๋์ฐจ ์ด๋ฆ์ ๋น์ด์์ ์ ์์ต๋๋ค."); | ||
} | ||
} |
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.
๋ง์ฐฌ๊ฐ์ง๋ก isBlank() ๋ก ๋์ฒดํ ์ ์๊ฒ ๋ค์!
public class InputView { | ||
|
||
public static final String CAR_NAME_DELIMITER = ","; | ||
private final Scanner scanner; | ||
|
||
public InputView() { | ||
this.scanner = new Scanner(System.in); | ||
} | ||
|
||
public GameSettings getGameSettings() { | ||
int carCount = promptInt("์๋์ฐจ ๋์๋ ๋ช ๋ ์ธ๊ฐ์?"); | ||
String inputCarNames = prompt("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์ ๋ ฅํ์ธ์(์ด๋ฆ์ ์ผํ(,)๋ฅผ ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)."); | ||
String[] carNames = inputCarNames.split(CAR_NAME_DELIMITER); | ||
int roundCount = promptInt("์๋ํ ํ์๋ ๋ช ํ ์ธ๊ฐ์?"); | ||
return new GameSettings(carCount, roundCount); | ||
return new GameSettings(carNames, roundCount); | ||
} |
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
๋ ๋ณ๋๋ก ๋ณ๊ฒฝ๋๋ ์ํ๋ฅผ ๊ฐ๊ณ ์์ง ์๊ณ , ๋ช ๋ฒ์ ์๋์ฐจ ๊ฒ์์์๋ ์ฌํ์ฉ์ด ๊ฐ๋ฅํ ๊ฑธ๋ก ๋ณด์ด๋๋ฐ์,
InputView
์ธ์คํด์ค๋ฅผ ๋งค๋ฒ ์์ฑํ ํ์ ์์ด static ํ๊ฒ ์ฌ์ฉํ ์ ์๋๋ก ๋ค๋ฌ์ด๋ณด๋ ๊ฑด ์ด๋จ๊น์?
@FunctionalInterface | ||
public interface MoveStrategy { | ||
|
||
boolean shouldMove(); | ||
} |
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.
ํจ์ํ ์ธํฐํ์ด์ค ์ ์ธ ๐
private boolean isWinner(Car car, int maxPosition) { | ||
return car.getPosition() == maxPosition; | ||
} |
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.
์๋์ฐจ ๊ฐ์ฒด๋ก๋ถํฐ ๊ฐ์ ์ถ์ถํ๊ณ ๋น๊ตํ๋ ๊ฒ๋ ์ข์ง๋ง, ๊ฐ์ ์๋์ฐจ ๊ฐ์ฒด์๊ฒ ์ ๋ฌํ์ฌ ์ํ๋ ๊ฑธ ๋ฌผ์ด๋ณด๋ ๊ฑด ์ด๋จ๊น์?
๊ฐ์ฒด์๊ฒ ์ง๋ฌธํ๋ผ
์ด๋ฐ ์ฝ๋์๋ ์ด๋ค ์ฅ์ ์ด ์๊ธธ๊น์?
private List<CarStatus> findWinnersWithPosition(int maxPosition) { | ||
List<CarStatus> winners = new ArrayList<>(); | ||
for (Car car : cars) { | ||
addWinnerIfQualified(winners, car, maxPosition); | ||
} | ||
return winners; | ||
} | ||
|
||
private void addWinnerIfQualified(List<CarStatus> winners, Car car, int maxPosition) { | ||
if (isWinner(car, maxPosition)) { | ||
winners.add(new CarStatus(car)); | ||
} | ||
} |
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.
ํ์ฌ List<Car> cars
์ปฌ๋ ์
์๊ฒ ์ปฌ๋ ์
๊ทธ ์ด์์ ์๊ตฌ, ๋น์ฆ๋์ค์ ์ธ ์๊ตฌ๊ฐ ๋ง์์ง๊ณ ์์ด์.
์ ๋ ์ด ์์ ์ด ์ผ๊ธ ์ปฌ๋ ์
์ ๋์
ํ๊ธฐ ๊ฐ์ฅ ์ข์ ์์ ์ด๋ผ๊ณ ์๊ฐํ๋๋ฐ์,
ํ๋ฒ ์ผ๊ธ ์ปฌ๋ ์
๋์
์ ์๋ํด๋ณด๋ ๊ฑด ์ด๋จ๊น์? ๐
https://jojoldu.tistory.com/412
public class RandomMoveStrategy implements MoveStrategy { | ||
|
||
public static final int RANDOM_NUMBER_RANGE = 10; | ||
private static final int MOVE_THRESHOLD = 4; |
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.
private ์ผ๋ก ์จ๊ฒจ์ค๋ ๋๊ฒ ๋ค์!
intelliJ ๋ฅผ ์ด์ฉํ์ ๋ค๋ฉด ์์์์ฑ ๋จ์ถํค๋ฅผ ์ฐ์ 2ํ ์
๋ ฅํ์๋ฉด ์ต์
๋ณ๊ฒฝ์ด ๊ฐ๋ฅํฉ๋๋ค.
๊ตฌํ TODO ๋ชฉ๋ก
์๋์ฐจ ์ด๋ฆ ๊ธฐ๋ฅ
Car
ํด๋์ค์ ์ด๋ฆ ํ๋ ์ถ๊ฐCar
์์ฑ์์ ์ด๋ฆ ํ๋ผ๋ฏธํฐ ์ถ๊ฐCarTest
์ ์ด๋ฆ ๊ด๋ จ ํ ์คํธ ์ถ๊ฐ์๋์ฐจ ์ด๋ฆ ์ถ๋ ฅ
ResultView
์์ presentCars
๋ฉ์๋ ํ๋ผ๋ฏธํฐ ์์ (์ด๋ฆ ์ ๋ณด ์ถ๊ฐ)Race
ํด๋์ค ์์ getCarPositions
๋ฉ์๋๋ฅผgetCarStatus
๋ก ๋ณ๊ฒฝ์๋์ฐจ ์ด๋ฆ ์ ๋ ฅ
InputView
์์ GameSettings
์์ ์ฐ์น์ ํ์
Race
ํด๋์ค์ ์ฐ์น์ ํ์ ๋ก์ง ์ถ๊ฐgetWinners
๋ฉ์๋ ์ถ๊ฐResultView
์ ์ฐ์น์ ์ถ๋ ฅ ๋ฉ์๋ ์ถ๊ฐGame
ํด๋์ค ์์ ๊ฐ๋ฐ ๊ตฌ์กฐ