-
Notifications
You must be signed in to change notification settings - Fork 5
[숫자 야구] 공희상 제출합니다. #2
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
base: main
Are you sure you want to change the base?
Conversation
tiemo0708
left a comment
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.
스터디 고생하셨습니다!
| for (int i = 0; i < NUMBERS_SIZE; i++) { | ||
| boolean isStrike = computerNumbers.get(i).equals(playerNumbers.get(i)); | ||
| boolean isBall = !isStrike && computerNumbers.contains(playerNumbers.get(i)); | ||
| if (isStrike) { | ||
| strikes++; | ||
| } | ||
| if (isBall) { | ||
| balls++; | ||
| } | ||
| } |
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.
해당 클래스에 스트라이크, 볼 판정 로직이 있어도 될지 궁금합니다
| RESTART("1", true), | ||
| QUIT("2", false); |
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.
재시작을 이넘으로 처리하셨네요 좋은방법 같아 보입니다
| validateNumber(number); | ||
| return number; | ||
| } catch (NumberFormatException e) { | ||
| 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.
예외처리도 상수화 하시면 좋을것 같습니다
|
|
||
| public class InputView { | ||
|
|
||
| public String getNumber() { |
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.
메서드이름에 get이 들어가는걸 지양해야할것 같습니다
| private List<Integer> parse(String input) { | ||
| List<String> items = List.of(input.split("")); | ||
| List<Integer> numbers = new ArrayList<>(); | ||
| for (String item : items) { | ||
| int number = parseNumber(item); | ||
| numbers.add(number); | ||
| } | ||
| validateNumbers(numbers); | ||
| return numbers; | ||
| } | ||
|
|
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.
파싱 부분은 따로 클래스를 만들어서 빼는게 어떨까요?
jiffyin7
left a comment
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.
스터디 때 뵙겠습니다.
| boolean isFinish = false; | ||
| ComputerNumbers computerNumbers = init(); | ||
| while (!isFinish) { | ||
| PlayerNumbers playerNumbers = input(); | ||
| isFinish = result(computerNumbers, playerNumbers); | ||
| } |
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.
do while로 처리하면 더 좋을것 같습니다.
| private final List<Integer> computerNumbers; | ||
|
|
||
| public ComputerNumbers() { | ||
| this.computerNumbers = createRandomNumbers(); |
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 boolean isCorrect() { | ||
| return strikes == 3; |
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.
NUMBER_SIZE 상수를 써도 좋을것 같네요.
Dompoo
left a comment
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 final static String WHITE_SPACE = " "; | ||
| public final static String STRIKE = "%d스트라이크"; | ||
| public final static String BALL = "%d볼"; | ||
| public final static String NOTHING = "낫싱"; |
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.
이 상수들은 위 상수들과는 조금 다르게 출력에 초점을 맞추고 있는 상수들이에요. 상수도 분리해서 관리하면 어떨까요?
| } catch (IllegalArgumentException e) { | ||
| throw new IllegalArgumentException(e.getMessage()); |
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.
어차피 IllegalArgumentException으로 받아서 똑같은 메시지로 다시 던질거면 여기서 try-catch를 왜 사용하신지 궁금해요!
| play(); | ||
| isContinue = restart(); |
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.
메서드가 아주 보기 좋게 잘려있으니 이 둘을 서비스나 다른 컨트롤러로 분리하기 아주 좋아보입니다. ㅎㅎ.... (츄릅)
어떻게 생각하세요?
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class PlayerNumbers { |
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.
PlayerNumber와 ComputerNumeber가 비슷한 기능을 수행하는 부분이 있어서, 추상클래스로 묶으면 검증등의 로직을 빼볼 수 있을 것 같아요!
|
|
||
| import static camp.nextstep.edu.missionutils.Console.readLine; | ||
|
|
||
| public class InputView { |
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에서 좀 더 적극적으로 List나 boolean을 제공하지 않고, String만 제공하는지 궁금합니다! 너무 역할이 없는 것 같아요.
숫자 야구 미션
고민했던 부분
패키지 구조
classDiagram direction TB class baseball { Application } baseball "1" --> "1" common baseball "1" --> "1" config baseball "1" --> "1" controller baseball "1" --> "1" model baseball "1" --> "1" view class common { <<package>> } common --> constant class constant { Constants } class config { <<package>> GameConfig } class controller { <<package>> GameController } class model { <<package>> } model --> domain class domain { ComputerNumbers GameMenu PlayerNumbers Result } class view { <<package>> InputView OutputView }클래스 다이어그램
classDiagram direction BT class Application { + main(String[]) void + Application() } class ComputerNumbers { - createRandomNumbers() List~Integer~ + compare(PlayerNumbers) Result + ComputerNumbers() } class Constants { + Constants() } class GameConfig { + GameConfig() GameController gameComputer } class GameController { - result(ComputerNumbers, PlayerNumbers) boolean - input() PlayerNumbers - init() ComputerNumbers - restart() boolean - play() void - finish() void + start() void + GameController(InputView, OutputView) } class GameMenu { <<enumeration>> + valueOf(String) GameMenu + from(String) boolean + values() GameMenu[] - GameMenu(String, boolean) boolean countinue - boolean countinue } class InputView { + askRestart() String + InputView() String number } class OutputView { + printRestartPrompt() void + printNumberPrompt() void + printFinishMessage() void + printResultMessage(String) void + printStartMessage() void + printErrorMessage(String) void + OutputView() } class PlayerNumbers { - parse(String) List~Integer~ - parseNumber(String) int - validateNumber(int) int - validateNumbers(List~Integer~) void + PlayerNumbers(String) List~Integer~ playerNumbers - List~Integer~ playerNumbers } class Result { + toString() String + Result(int, int) boolean correct } GameConfig "1" *--> "gameController 1" GameController GameConfig "1" *--> "inputView 1" InputView GameConfig "1" *--> "outputView 1" OutputView GameController "1" *--> "inputView 1" InputView GameController "1" *--> "outputView 1" OutputView플로우 차트
graph TD A[게임 시작] --> B[시작 메시지 출력] B --> C{게임을 계속 진행할까요?} C -->|예| D[컴퓨터 숫자 초기화] D --> E{게임 종료 여부 확인} E -->|아니오| F[플레이어 숫자 입력] F --> G[결과 비교] G --> H[결과 메시지 출력] H --> E E -->|예| I[종료 메시지 출력] I --> J{다시 시작할까요?} J -->|예| C J -->|아니오| K[게임 종료]