Skip to content

Commit

Permalink
refactor: InputUtils 책임 재정의
Browse files Browse the repository at this point in the history
  • Loading branch information
Livenow14 committed Feb 23, 2021
1 parent d534d61 commit 562e9c7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 44 deletions.
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


## 매세지 정의
- 로또 금액을 반환하라
- 로또를 구매하라
- 로또를 생성하라
- 로또 갯수만큼 로또 번호를 생성하라
Expand Down Expand Up @@ -41,6 +42,7 @@
- [x] 수익률을 출력한다.

## 리펙토링 목록 정리
### step1 1차 피드백
- [x] DTO 제거기(DTO 없이 view에 값을 전달 할 수 있다.)
- [x] 책임에 대해 한번더 생각하기
- [x] BonusBall 제거
Expand All @@ -54,6 +56,9 @@
- [x] 제네릭 빠진 것 확인
- [x] DisplayName 의도를 더 정확히 드러내

### step1 2차 피드백
- [x] GameManageApplication 메서드 순서 변경 - d534d61
- [x] InputUtils 책임 재정의

## 프로그래밍 요구사항
- indent(인덴트, 들여쓰기) depth를 2단계에서 1단계로 줄여라.
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/Application.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import domain.LottoGameMachine;
import service.LottoService;
import view.LottoGameScreen;
import view.MainScreen;

public class Application {
public static void main(String[] args) {
LottoGameMachine lottoGameMachine = new LottoGameMachine();
LottoService lottoService = new LottoService(lottoGameMachine);
GameManageApplication gameManageApplication = new GameManageApplication(new MainScreen(), new LottoGameScreen(), lottoService);
GameManageApplication gameManageApplication = new GameManageApplication(new LottoGameScreen(), lottoService);
gameManageApplication.run();
}
}
10 changes: 3 additions & 7 deletions src/main/java/GameManageApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,23 @@
import service.LottoService;
import util.InputUtil;
import view.LottoGameScreen;
import view.MainScreen;
import view.dto.LottoGameResultDto;

import java.util.Set;

public class GameManageApplication {
private final MainScreen mainScreen;
private final LottoGameScreen lottoGameScreen;
private final LottoService lottoService;

public GameManageApplication(final MainScreen mainScreen, final LottoGameScreen lottoGameScreen, LottoService lottoService) {
this.mainScreen = mainScreen;
public GameManageApplication(final LottoGameScreen lottoGameScreen, LottoService lottoService) {
this.lottoGameScreen = lottoGameScreen;
this.lottoService = lottoService;
}

public void run() {
BettingMoney bettingMoney = getBettingMoney();
TicketCount ticketCount = getTicketCount(bettingMoney);
mainScreen.showTicketCount(ticketCount);
lottoGameScreen.showTicketCount(ticketCount);
LottoTickets lottoTickets = lottoService.getLottoTickets(bettingMoney);
lottoGameScreen.showAllLottoStatus(lottoTickets.getLottoTickets());
WinningLotto winningLotto = getWinningLotto();
Expand All @@ -36,8 +33,7 @@ public void run() {
}

private BettingMoney getBettingMoney() {
mainScreen.showInputMoney();
int input = InputUtil.nextInt();
int input = InputUtil.inputBettingMoney();
return BettingMoney.of(input);
}

Expand Down
25 changes: 16 additions & 9 deletions src/main/java/util/InputUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@
public class InputUtil {
private static final Scanner SCANNER = new Scanner(System.in);
private static final String DELIMITER = ",";
private static final String WRONG_NUMBER_EXCEPTION_MESSAGE = "자연수만 입력 가능합니다. 현재 입력 값 : %s.";
private static final String BETTING_MONEY_MESSAGE = "구입금액을 입력해 주세요.";

private InputUtil() {
}

public static int nextInt() {
String inputValue = SCANNER.nextLine();
try {
return Integer.parseInt(inputValue);
} catch (NumberFormatException numberFormatException) {
throw new IllegalArgumentException(String.format("자연수만 입력 가능합니다. | 현재 입력 값 : %s ", inputValue));
}
}

public static Set<Integer> inputWinningNumbers() {
String winningNumbersText = SCANNER.nextLine();
return Arrays.stream(winningNumbersText.split(DELIMITER))
Expand All @@ -32,4 +25,18 @@ public static Set<Integer> inputWinningNumbers() {
public static int inputBonusNumber() {
return nextInt();
}

public static int inputBettingMoney() {
System.out.println(BETTING_MONEY_MESSAGE);
return nextInt();
}

private static int nextInt() {
String inputValue = SCANNER.nextLine();
try {
return Integer.parseInt(inputValue);
} catch (NumberFormatException numberFormatException) {
throw new IllegalArgumentException(String.format(WRONG_NUMBER_EXCEPTION_MESSAGE, inputValue));
}
}
}
26 changes: 16 additions & 10 deletions src/main/java/view/LottoGameScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import domain.ball.LottoBall;
import domain.lotto.LottoTicket;
import domain.lotto.TicketCount;
import domain.result.LottoRank;
import util.OutputUtil;
import view.dto.LottoGameResultDto;
Expand All @@ -14,16 +15,21 @@
import java.util.stream.Collectors;

public class LottoGameScreen {
public static final String LOTTO_PREFIX = "[";
public static final String LOTTO_POSTFIX = "]";
public static final String DELIMITER = ", ";
public static final String WINNING_LOTTO_CONFIRMATION = "\n지난 주 당첨 번호를 입력해 주세요.";
public static final String BONUS_LOTTO_CONFIRMATION = "보너스 볼을 입력해 주세요.";
public static final String RESULT = "당첨통계";
public static final String LINE = "----------";
public static final String LOTTO_RESULT_MESSAGE = "%s개 일치 (%d원)- %d개";
public static final String SECOND_PRIZE_RESULT_MESSAGE = "%d개 일치, 보너스 볼 일치 (%d)원- %d";
public static final String REVENUE_RESULT_FORMATTER = "총 수익률은 %.2f입니다.";
private static final String LOTTO_TICKET_COUNT = "%d개를 구매했습니다.";
private static final String LOTTO_PREFIX = "[";
private static final String LOTTO_POSTFIX = "]";
private static final String DELIMITER = ", ";
private static final String WINNING_LOTTO_CONFIRMATION = "\n지난 주 당첨 번호를 입력해 주세요.";
private static final String BONUS_LOTTO_CONFIRMATION = "보너스 볼을 입력해 주세요.";
private static final String RESULT = "당첨통계";
private static final String LINE = "----------";
private static final String LOTTO_RESULT_MESSAGE = "%s개 일치 (%d원)- %d개";
private static final String SECOND_PRIZE_RESULT_MESSAGE = "%d개 일치, 보너스 볼 일치 (%d)원- %d";
private static final String REVENUE_RESULT_FORMATTER = "총 수익률은 %.2f입니다.";

public void showTicketCount(final TicketCount lottoCount) {
OutputUtil.printMessage(String.format(LOTTO_TICKET_COUNT, lottoCount.getTicketCount()));
}

public void showAllLottoStatus(final List<LottoTicket> lottoTickets) {
lottoTickets.stream()
Expand Down
16 changes: 0 additions & 16 deletions src/main/java/view/MainScreen.java

This file was deleted.

0 comments on commit 562e9c7

Please sign in to comment.