Skip to content
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
10dca15
docs(guide): 구현할 기능목록과 예외처리 목록 추가
oereo Mar 4, 2021
7759d90
test: Car의 move 메서드 호출시 한칸 전진하는 테스트 작성
oereo Mar 4, 2021
29c34ea
feat: 자동차가 움직이는 기능 구현
oereo Mar 4, 2021
a14473d
test: 전진 여부 판단 test code 작성
oereo Mar 4, 2021
a51c4e4
feat: 전진 여부 판단 기능 구현
oereo Mar 4, 2021
d56921b
feat: 0~9 범위의 난수 생성 기능 구현
oereo Mar 4, 2021
3d28c49
test: car 객체를 CarManager에 추가하는 test 작성
oereo Mar 4, 2021
4eebc6d
feat: Car 객체 추가 테스트 통과하는 기능 구현
oereo Mar 4, 2021
69f37d0
test: 중복되는 이름의 Car 객체를 추가할 시 NotDulicateNameException를 던지는 test 작성
oereo Mar 4, 2021
7d614b4
fix: 독립된 테스트케이스 환경 구성
oereo Mar 4, 2021
0c6bb59
feat: 중복되는 이름의 Car 객체를 검사하고 존재하면 NotDuplicateNameException 던지는 기능 구현
oereo Mar 4, 2021
1ff4c7a
test: Car 객체의 상태를 출력 포맷에 맞게 String으로 반환하는 test 작성
oereo Mar 4, 2021
b2daa5d
feat: Car 객체의 상태를 출력 포맷에 맞게 String으로 반환하는 기능 구현
oereo Mar 4, 2021
40b18e4
test: 빈 String의 이름을 가진 Car 객체를 생성하면 NotBlankException을 던지는 test 작성
oereo Mar 4, 2021
e16fdb8
feat: 빈 String의 이름을 가진 Car 객체를 생성하면 NotBlankException을 던지는 기능 구현
oereo Mar 4, 2021
218bed6
refactor: 루트 패키지 racingcar 추가
oereo Mar 4, 2021
f0d1f09
refactor: Discriminator 패키지 위치 변경
oereo Mar 9, 2021
e72ba2f
refactor: 플레이어 추가를 addAllCars method 로 test case 작성
oereo Mar 9, 2021
cf8d6d4
refactor: 플레이어 추가를 addAllCars method 로 구현
oereo Mar 9, 2021
4e74812
test: 랜덤 숫자 리스트 기준에 따라 플레이어가 이동하는 test case 작성
oereo Mar 9, 2021
c6f3b68
feat: 랜덤 숫자 리스트 기준에 따라 플레이어가 이동하는 method 구현
oereo Mar 9, 2021
396584f
refactor: car 객체와 생성된 난수를 dto로 mapping
oereo Mar 9, 2021
c08b45d
test: dto 리스틀를 생성하는 test case 작성
oereo Mar 9, 2021
f982c1d
feat: dto에 car 객체와 난수 생성하는 기능 구현
oereo Mar 9, 2021
bd63d3d
feat: 출력 담당 Printer class 구현
oereo Mar 9, 2021
b9dc073
feat: 전체 car 의 state 를 출력하는 printCarState method 구현
oereo Mar 9, 2021
ec26f16
feat: 사용자의 입력을 받는 역할을 담당하는 Receiver class 구현
oereo Mar 9, 2021
eb40f45
test: 승자가 한명일 때 그 이름을 출력하는 test case 작성
oereo Mar 9, 2021
89965af
test: 승자가 여러명일 때 그 이름들을 comma로 구분하여 출력하는 test case 작성
oereo Mar 9, 2021
a04b488
feat: 승자를 구하고 그 승자이름들을 comma로 구분하여 출력하는 기능 구현
oereo Mar 9, 2021
9db711b
feat: 게임 흐름 제어하는 RacingGameApplication 구현
oereo Mar 9, 2021
267a80a
fix: 정상적이지 않은 입력값에 대한 예외 처리 NotBlankException
oereo Mar 9, 2021
fc8d01c
docs(guide): 예외처리 목록 추가 및 체크사항 수정
oereo Mar 9, 2021
9ceca45
docs(guide): 5글자 이상의 차 이름을 입력했을 때 허용하지 않는 케이스 예외처리 목록에 추가
oereo Mar 16, 2021
01c78c6
test: 5글자 이상의 이름이 주어지면 NotValidNameLengthException 던지는 테스트 케이스 작성
oereo Mar 16, 2021
eb7a7c5
feat: NotValidNameLengthException 예외처리 추가 및 Car 객체 생성 시 예외처리 로직 추가
oereo Mar 18, 2021
1b7f367
fix: Car객체 생성 시 5글자 이상의 name을 넣는 테스트 케이스 일괄 수정
oereo Mar 18, 2021
1e1ce79
fix: Car 객체의 이름이 빈 스트링일 경우 기존 name.equals("")에서 api를 이용한 isBlank() me…
oereo Mar 18, 2021
48dca32
refactor: NotBlankException를 발생시키는 createAllCars()에만 try catch 적용
oereo Mar 19, 2021
d9012d1
fix: Car 이름의 길이 제한하는 기준과 한번 이동할 때의 숫자를 상수화
oereo Mar 19, 2021
107e35f
fix: 컬렉션의 of 메소드가 java8에서 작동이 안되는 문제점 해결하기 위해 Arrays.asList 로 수정
oereo Mar 20, 2021
df55a8c
refactor: CarName class 선언 및 Car 객체 생성시에 예외처리를 해줄 수 있도록 구조 수정
oereo Mar 20, 2021
914a0b5
refactor: createAllCars method 수정
oereo Mar 20, 2021
946fadf
docs(guide): 5글자 이상의 차 이름을 입력했을 때 허용하지 앟는 예외처리 목록 체크 반영
oereo Mar 20, 2021
498d3be
feat: isWinnerPosition method를 Car class 안에 추가
oereo Mar 21, 2021
9857960
fix: getPosition으로 Car 객체의 위치를 바로 가져오는 것이 아닌 Car class 내의 method로 판단하…
oereo Mar 21, 2021
9430694
feat: Round class 추가
oereo Mar 25, 2021
cc8172a
feat: Round 객체 생성 및 RacingGameApplication method 변경
oereo Mar 25, 2021
16aa313
feat: RacingGameApplication 안에서 DELIMITER 로 split 하는 함수 제외 및 Receiver…
oereo Mar 25, 2021
ab0b294
refactor: receiveNumberOfRounds method 에 예외처리 로직 추가
oereo Mar 25, 2021
8f40658
refactor: throwExceptionIfInputIsZero method 와 SplitInputLine method …
oereo Mar 25, 2021
6f57314
feat: Receiver 에서 validate 하지 않은 input 값이 들어올 시 다시 Receiver class로 요청…
oereo Mar 25, 2021
c40921a
delete: random util class의 필요성이 없기 때문에 RandomGenerator 삭제
oereo Mar 25, 2021
735092e
feat: MoveStrategy class 생성 및 RandomMoveStrategy class 생성
oereo Mar 25, 2021
6144be7
feat: RandomMoveStrategy 의 숫자에 의해서 car 객체가 움직일지 말지의 여부를 판단하고 행동하는 For…
oereo Mar 25, 2021
d573258
delete: Discriminator class 삭제 및 test case 삭제
oereo Mar 25, 2021
9169126
refactor: Discriminator class 관련 로직 제거 및 직접 Car 객체를 move() 하는 로직 제거
oereo Mar 25, 2021
761b3dc
refactor: receiveNumberOfRounds validation 와 관련된 로직 분리
oereo Mar 26, 2021
35ed5d8
refactor: round 형태를 variable경 이 아닌 객체로 변
oereo Mar 26, 2021
fec9808
feat: round에 관련된 값을 받을 시에 validate한 값이 들어올 수 있도록 ReceiverValidator cl…
oereo Mar 26, 2021
ea5a4fd
refactor: random number 를 저장할 이유가 없기 때문에 제거 및 class naming 수정
oereo Mar 26, 2021
de3ba25
feat: CarManagerValidator class 추가
oereo Mar 26, 2021
c5eb648
refactor: run() method 간소화 및 createAllCars() method 를 RacingGameAppli…
oereo Mar 26, 2021
8afc5d2
refactor: NotDuplicateNameException 예외처리를 ValidateAddCars method 에서 처리
oereo Mar 26, 2021
8501c47
feat: Winner class 생성
oereo Mar 26, 2021
ea61730
feat: CarManager class 안 createWinnerMessage method 역할 분리
oereo Mar 26, 2021
257a825
refactor: class 이동 및 구조 변경
oereo Mar 26, 2021
8c28348
refactor: class 이동 및 구조 변경
oereo Mar 26, 2021
50063f2
delete: 사용하지 않는 모듈 삭제
oereo Mar 26, 2021
bcf9d28
refactor: 사용하지 않는 모듈 삭제 및 구조 변경
oereo Mar 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# 미션 - 자동차 경주 게임

## 구현할 기능 목록
- [ ] 차의 이름과 위치를 관리하는 클래스를 구현한다.
- [ ] 0부터 9사이의 정수값을 랜덤하게 생성
- [ ] 난수가 4이상이면 전진
- [ ] 난수가 3이하이면 이동하지 않는다
- [ ] 턴이 모두 지났을 때 가장 앞에 있는 차의 이름을 출력한다.
- [ ] 턴이 모두 지났을 때 앞에 있는 차가 2개 이상일 경우 전부 출력한다.
- [ ] 차의 이름에 대한 입력값을 쉼표로 구분할 수 있다.
- [ ] 시도할 횟수를 입력 받을 수 있다.
- [ ] 현재 자동차의 위치상황을 이름과 함께 출력할 수 있다.

## 예외 처리 목록
Comment thread
oereo marked this conversation as resolved.
Comment thread
oereo marked this conversation as resolved.
- [ ] 빈 문자열 입력은 허용하지 않는다.
- [ ] 중복되는 이름의 차를 입력했을 때 허용하지 않는다.

## 🚀 기능 요구사항

- 주어진 횟수 동안 n대의 자동차는 전진 또는 멈출 수 있다.
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/domain/Car.java

This file was deleted.

94 changes: 94 additions & 0 deletions src/main/java/racingcar/RacingGameApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package racingcar;

import racingcar.domain.Car;
import racingcar.domain.exception.NotBlankException;
import racingcar.dto.CarNumberDto;
import racingcar.exception.NotZeroRoundException;
import racingcar.repository.CarManager;
import racingcar.ui.Printer;
import racingcar.ui.Receiver;

import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.List;

public class RacingGameApplication {
private static final int INPUT_ZERO = 0;
private static final String DELIMITER = ",";

private final Printer printer = new Printer();
private final Receiver receiver = new Receiver();
private final CarManager carManager = new CarManager();

public void run() {
printer.requestCarName();
String line = receiver.receiveCarNames();
try {
List<Car> carList = createAllCars(splitInputLine(line));
carManager.addAllCars(carList);

printer.requestNumberOfRounds();
int rounds = receiveRounds();
proceedRound(rounds);

printer.printWinner(carManager.createWinnerMessage());
} catch (NotBlankException e) {
printer.printExceptionMessage(e);
run();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NotBlankException를 발생시키는 곳은 createAllCars()인데 너무 많은 부분이 try 블록으로 감싸져있네요.
createAllCars() 이외의 영역에서 추가로 새로운 예외가 정의되면 처리하는 부분이 점점 복잡해질것같아요.
실제로 발생하는 곳만 예외를 처리하도록 변경해보세요!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

앗 네엡!!! 수정하도록 하겠습니다!!! 이 부분을 try catch 로 block을 크게 잡은 이유는 결국에 순서를 보장해주고자 했던 것 같아요! 해결해보도록 하겠습니다!!

}

private void proceedRound(int rounds) {
printer.printResultHeader();
for (int i = 0; i < rounds; i++) {
List<CarNumberDto> carNumberDtos = carManager.generateCarNumberDtos();
carManager.moveAllCars(carNumberDtos);
carManager.printCarState(printer);
}
}

private List<Car> createAllCars(List<String> carNames) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

RacingGameApplication이 너무 많은 역할을 하고 있는것 같아요
의도했던 RacingGameApplication의 역할은 무엇인가요?
그리고 현재 RacingGameApplication는 어떤 역할들을 하고 있나요?

  • 라운드를 진행시키고(proceedRound)
  • 자동차를 만들고(createAllCars)
  • 라운드를 입력받고(receiveRounds)
  • 예외를 던지고(throwExceptionIfInputIsZero)
  • 문자열을 스플릿하고(splitInputLine)

다양한 기능을 하고있네요! SRP(Single Responsibility Principle)를 지키도록 클래스를 분리해보세요!
처음부터 너무 작게는 어려울 수 있으니 크게크게라도 분리해보면 좋을것같아요

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

RacingGameApplication class의 주된 역할은 게임의 순서와 연관된 기능들을 한다고 생각을 했어요!! 사실 지금 다시 보니까 분리를 시켜야될 필요성이 있을 것 같아요 ㅠ method도 그렇지만 책임이 다양하게 있는 느낌이네요 ㅠㅠ
먼저 예외를 던지는 것과 문자열을 스플릿하는 역할들은 RacingGameApplication class와 동떨어진 역할을 하는 아이들인 것 같아요! 이 부분부터 먼저 분리를 하도록 하겠습니다!! 감사합니당!

List<Car> carList = new ArrayList<>();
if (carNames.size() == 0) {
throw new NotBlankException();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

carName이 사용되는 곳마다 이런 검증 로직이 들어갈 것 같아요.
carName이라는 String 원시 값을 포장해보면 어떨까요?
새로운 클래스를 만들고 그 안에 검증 로직을 둬서 이런 부분을 해소해보세요!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

CarName이라는 class를 만들고 Car 객체 생성시에 빈 이름이 들어올 경우 예외 처리를 할 수 있도록 구조를 바꾸었습니다! 허나 문제가 생긴 것 같습니다 ㅠㅠㅠ
, , , -> 예외처릭가 정상적으로 이루어 집니다!
,,, -> 예외처리가 비정상적으로 이루어집니다! list size가 0이기 때문에 에러가 나는 문제가 생기는 것 같습니다 ㅠ


for (String name : carNames) {
carList.add(new Car(name));
}
return carList;
}

private int receiveRounds() {
int rounds = 0;
boolean isInvalidInput = true;
while (isInvalidInput) {
try {
rounds = receiver.receiveNumberOfRounds();
throwExceptionIfInputIsZero(rounds);
isInvalidInput = false;
} catch (InputMismatchException e) {
printer.printInputMismatchExceptionMessage(receiver);
} catch (IllegalArgumentException e) {
printer.printExceptionMessage(e);
}
}
return rounds;
}

private void throwExceptionIfInputIsZero(int rounds) {
if (rounds == INPUT_ZERO) {
throw new NotZeroRoundException();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이 부분은 객체로 포장해보면 어떨까요?

}

private List<String> splitInputLine(String line) {
return List.of(line.split(DELIMITER));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

컬렉션의 of 메소드는 자바 8에서 작동 안한다는 사실 알아두면 좋을 것 같네요!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Arrays.asList 로 바꾸면 될 것 같아요!!! 수정하겠습니다!! 처음 들어본 사실에 ㅠㅠ 감탄과 부끄럼을 느낍니다!!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

자바 하위 호환성을 보장하는게 일반적인가요?
만약 그렇다면 8버전까지 보장하는게 일반적인가요?

}

public static void main(String[] args) {
RacingGameApplication app = new RacingGameApplication();
app.run();
}
}

51 changes: 51 additions & 0 deletions src/main/java/racingcar/domain/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package racingcar.domain;

import racingcar.domain.exception.NotBlankException;

import java.util.Objects;

public class Car {
private final String name;
private int position = 0;

public Car(String name) {
checkBlankName(name);
this.name = name;
}

private void checkBlankName(String name) {
if (name.equals("")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

String엔 isBlank()란 메소드가 있습니다!
api를 적극 활용해보세요!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

앗 감사합니다!! 적극적으로 사용해봐야 될 것 같아요!!!

throw new NotBlankException();
}
}

public String getName() {
return name;
}

public int getPosition() {
return position;
}

public void move() {
position += 1;
}

@Override
public String toString() {
return name + " : " + "-".repeat(Math.max(0, position));
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Car car = (Car) o;
return name.equals(car.name);
}

@Override
public int hashCode() {
return Objects.hash(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package racingcar.domain.exception;

public class NotBlankException extends RuntimeException {
private static final String MESSAGE = "빈 문자열 이름의 차를 생성할 수는 없습니다.";

public NotBlankException() {
super(MESSAGE);
}
}
21 changes: 21 additions & 0 deletions src/main/java/racingcar/dto/CarNumberDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package racingcar.dto;

import racingcar.domain.Car;

public class CarNumberDto {
private final Car car;
private final int number;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

car와 number를 dto로 감싼 이유가 있을까요?


public CarNumberDto(Car car, int number) {
this.car = car;
this.number = number;
}

public Car getCar() {
return car;
}

public int getNumber() {
return number;
}
}
9 changes: 9 additions & 0 deletions src/main/java/racingcar/exception/NotZeroRoundException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package racingcar.exception;

public class NotZeroRoundException extends IllegalArgumentException {
private static final String NOT_ZERO_ROUND_EXCEPTION_MESSAGE = "라운드 회수로 0은 입력하실 수 없습니다.";

public NotZeroRoundException() {
super(NOT_ZERO_ROUND_EXCEPTION_MESSAGE);
}
}
88 changes: 88 additions & 0 deletions src/main/java/racingcar/repository/CarManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package racingcar.repository;

import racingcar.domain.Car;
import racingcar.dto.CarNumberDto;
import racingcar.repository.exception.NotDuplicateNameException;
import racingcar.ui.Printer;
import racingcar.util.Discriminator;
import racingcar.util.RandomGenerator;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class CarManager {
private List<Car> cars;

public CarManager() {
cars = new ArrayList<>();
}

private void checkDuplicateName(Car car) {
if (cars.contains(car)) {
throw new NotDuplicateNameException("중복되는 이름의 차를 입력하실 수 없습니다.");
}
}

public int size() {
return cars.size();
}

public void addAllCars(List<Car> cars) {
for (Car car : cars) {
checkDuplicateName(car);
this.cars.add(car);
}
}

public List<CarNumberDto> generateCarNumberDtos() {
List<CarNumberDto> dtos = new ArrayList<>();

for (Car car: cars) {
int randomNumber = RandomGenerator.generateNumber();
dtos.add(new CarNumberDto(car, randomNumber));
}

return dtos;
}

public void moveAllCars(List<CarNumberDto> carNumberList) {
for (CarNumberDto dto : carNumberList) {
if (Discriminator.isMove(dto.getNumber())) {
dto.getCar().move();
}
}
}

public void printCarState(Printer printer) {
for (Car car : cars) {
printer.printCarState(car);
}
printer.printNewLine();
}

public String createWinnerMessage() {
StringBuilder winnerNames = new StringBuilder();
List<Car> winners = winnerList();
winnerNames.append(winners.get(0).getName());

for (int i = 1; i < winners.size(); i++) {
Car winner = winners.get(i);
winnerNames.append(", ");
winnerNames.append(winner.getName());
}

return winnerNames.toString();
}
Comment on lines +57 to +76

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

비즈니스로직과 뷰 로직이 섞여있네요!
이 부분을 분리해보세요!


private List<Car> winnerList() {
int winnerPosition = cars.stream()
.mapToInt(Car::getPosition)
.max()
.orElseThrow(IllegalArgumentException::new);

return cars.stream()
.filter(car -> car.getPosition() == winnerPosition)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

stream api 활용 👍🏻
다만 오늘 배운것처럼 값을 꺼내는 것이 아닌 car에게 메시지를 보내는 식으로 변경해보세요!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

이 부분을 바꿔보도록 하겠습니다!! 다만 구조를 전반적으로 바꿔야 될지 조금더 고민을 해보도록 하겠습니다!

.collect(Collectors.toList());
}
Comment thread
oereo marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package racingcar.repository.exception;

public class NotDuplicateNameException extends RuntimeException {
public NotDuplicateNameException(String message) {
super(message);
}
}
Comment thread
oereo marked this conversation as resolved.
44 changes: 44 additions & 0 deletions src/main/java/racingcar/ui/Printer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package racingcar.ui;

import racingcar.domain.Car;

public class Printer {
private static final String CAR_NAME_REQUEST_MESSAGE = "경주할 자동차 이름을 입력하세요.(이름은 쉼표(,) 기준으로 구분)";
private static final String ROUND_REQUEST_MESSAGE = "시도할 회수는 몇회인가요?";
private static final String RESULT_HEADER = "실행 결과";
private static final String WINNER_MESSAGE = "가 최종 우승했습니다.";
private static final String INPUT_MISMATCH_EXCEPTION_MESSAGE = "라운드 횟수로 숫자만 입력하실 수 있습니다.";

public void requestCarName() {
System.out.println(CAR_NAME_REQUEST_MESSAGE);
}

public void requestNumberOfRounds() {
System.out.println(ROUND_REQUEST_MESSAGE);
}

public void printResultHeader() {
System.out.println(RESULT_HEADER);
}

public void printWinner(String winnerNames) {
System.out.println(winnerNames + WINNER_MESSAGE);
}

public void printCarState(Car car) {
System.out.println(car);
}

public void printNewLine() {
System.out.println();
}
Comment thread
oereo marked this conversation as resolved.

public void printExceptionMessage(Exception e) {
System.out.println(e.getMessage());
}

public void printInputMismatchExceptionMessage(Receiver receiver) {
receiver.clearBuffer();
System.out.println(INPUT_MISMATCH_EXCEPTION_MESSAGE);
}
}
21 changes: 21 additions & 0 deletions src/main/java/racingcar/ui/Receiver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package racingcar.ui;

import java.util.Scanner;

public class Receiver {
private static final Scanner scanner = new Scanner(System.in);

public String receiveCarNames() {
return scanner.nextLine();
}

public int receiveNumberOfRounds() {
return scanner.nextInt();
}

public void clearBuffer() {
if (scanner.hasNextLine()) {
scanner.nextLine();
}
}
}
9 changes: 9 additions & 0 deletions src/main/java/racingcar/util/Discriminator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package racingcar.util;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

자동차의 움직임을 결정하는 클래스가 util성 클래스일까요?
util 클래스엔 어떤 것이 있고 어떤 역할을 할까요?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

util class에 java.util.Arrays, java.util.Collections, java.util.Date, java.util.Calendar 와 같은 class 들이 있는 것 같아요! util class에 대한 명확한 개념과 정의를 찾고 싶었는데 생각보다 잘 안나와서 구글링한 것을 예로 들면 유용한 기능들을 class화 해서 전역적으로 사용할 수 있도록 하는 역할을 하는 것 같아요!
따라서 자동차의 움직임을 결정하는 class는 util성 클래스라고 보기 힘든 점이 generic 하지 않다는 점인 것 같아요! 즉 자동차의 움직임을 경하는 class는 한정적인 목적으로만 사용되는 class이기 때문에 generic 하게 사용이 되지 않을 것 같아요!


public class Discriminator {
private static final int THRESHOLD = 4;

public static boolean isMove(int randomNumber) {
return (randomNumber >= THRESHOLD);
}
}
Loading