-
Notifications
You must be signed in to change notification settings - Fork 1.1k
4단계 로또 수정 #4208
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
Open
yangseungin
wants to merge
10
commits into
next-step:yangseungin
Choose a base branch
from
yangseungin:step4
base: yangseungin
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
4단계 로또 수정 #4208
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a54e864
refactor: 피드백 반영
yangseungin 0b5b2ae
docs: 4단계 요구사항 추가
yangseungin 60760c4
feat: 수동로또 구현
yangseungin 793141c
feat: 로또티켓에 수동로또 추가
yangseungin 26f42dc
feat: InputView, OutputView 수정
yangseungin db1459b
refactor: 음수나 0을 입력했을떄의 조건 처리
yangseungin cc9dea7
refactor: 방어적 복사를 하도록 수정
yangseungin a46f546
refactor: 에러로 인해 중단되는 부분을 수정
yangseungin ea1704c
refactor: LottoTicketsFactory로 생성의 책임 분리
yangseungin 01c19dc
refactor: ManualLottos가 사용자가 입력한 값만 저장하도록 변경
yangseungin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # 로또 구현 | ||
|
|
||
| ## 기능 요구사항 | ||
|
|
||
| ## 입력 | ||
|
|
||
| - [x] 수동으로 구매할 로또 수를 입력받는다 | ||
| - [x] 수동 구매 장수는 음수일수 없다. | ||
| - [x] 0개 입력시 전부 자동으로 구매한다. | ||
| - [x] 공백 입력 시 재입력받도록 한다. | ||
| - [x] 수동번호를 수동 갯수만큼 로또를 입력받는다. | ||
|
|
||
| ## 수동 로또 | ||
|
|
||
| - [x] 입력받은 로또 리스트를 받아서 생성한다. | ||
| - [x] 빈List이거나 null인경우 빈 값으로 판단한다. | ||
| - [x] 수동로또가 비어있으면 빈 리스트를 반환한다. | ||
|
|
||
| ## 로또 티켓 | ||
|
|
||
| - [x] 구입금액과 수동 로또를 받아서 생성한다. | ||
| - [x] 수동로또를 추가하고 남은 금만큼 자동 로또를 생성한다. | ||
|
|
||
| ## 출력 | ||
|
|
||
| - [x] 수동, 자동 장수를 출력한다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||
| package lotto.domain; | ||||||
|
|
||||||
| import java.util.Collections; | ||||||
| import java.util.List; | ||||||
| import java.util.Optional; | ||||||
|
|
||||||
| public class ManualLottos { | ||||||
| private final List<Lotto> manualLottos; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
위와 같이 사용자가 입력한 값을 String으로 저장하는 역할만 담당해도 되지 않을까? |
||||||
|
|
||||||
| public ManualLottos(List<Lotto> manualLottos) { | ||||||
| this.manualLottos = Optional.ofNullable(manualLottos) | ||||||
| .orElse(Collections.emptyList()); | ||||||
| } | ||||||
|
|
||||||
| public int getCount() { | ||||||
| return manualLottos.size(); | ||||||
| } | ||||||
|
|
||||||
| public List<Lotto> getManualLottos() { | ||||||
| return List.copyOf(manualLottos); | ||||||
| } | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||
|
|
||||||
| import lotto.domain.Lotto; | ||||||
| import lotto.domain.LottoNumber; | ||||||
| import lotto.domain.ManualLottos; | ||||||
|
|
||||||
| import java.util.ArrayList; | ||||||
| import java.util.List; | ||||||
|
|
@@ -11,8 +12,16 @@ public class InputView { | |||||
| private static final Scanner scanner = new Scanner(System.in); | ||||||
|
|
||||||
| public static int inputPurchaseAmount() { | ||||||
| System.out.println("구입금액을 입력해 주세요."); | ||||||
| return Integer.parseInt(scanner.nextLine()); | ||||||
| while (true) { | ||||||
| try { | ||||||
| System.out.println("구입금액을 입력해 주세요."); | ||||||
| String input = scanner.nextLine(); | ||||||
| validateNotEmpty(input); | ||||||
| return Integer.parseInt(input.trim()); | ||||||
| } catch (IllegalArgumentException e) { | ||||||
| System.out.println(e.getMessage()); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public static Lotto inputWinningNumbers() { | ||||||
|
|
@@ -33,6 +42,46 @@ private static Lotto parseWinningNumbers(String input) { | |||||
| public static LottoNumber inputBonusNumber() { | ||||||
| System.out.println("보너스 볼을 입력해 주세요."); | ||||||
| return LottoNumber.of(Integer.parseInt(scanner.nextLine())); | ||||||
| } | ||||||
|
|
||||||
| public static int inputManualLottoCount() { | ||||||
| while (true) { | ||||||
| try { | ||||||
| System.out.println("\n수동으로 구매할 로또 수를 입력해 주세요."); | ||||||
| String input = scanner.nextLine(); | ||||||
| validateNotEmpty(input); | ||||||
| return Integer.parseInt(input.trim()); | ||||||
| } catch (IllegalArgumentException e) { | ||||||
| System.out.println(e.getMessage()); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| public static ManualLottos inputManualLottos(int count) { | ||||||
| validateCount(count); | ||||||
| if (count == 0) { | ||||||
| return new ManualLottos(null); | ||||||
| } | ||||||
|
|
||||||
| System.out.println("수동으로 구매할 번호를 입력해 주세요."); | ||||||
| List<Lotto> manualLottos = new ArrayList<>(); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
앞에서 피드백한 바와 같이 String으로 저장하고 반환하는 것은 어떨까? |
||||||
| for (int i = 0; i < count; i++) { | ||||||
| String input = scanner.nextLine(); | ||||||
| validateNotEmpty(input); | ||||||
| manualLottos.add(parseWinningNumbers(input)); | ||||||
| } | ||||||
| return new ManualLottos(manualLottos); | ||||||
| } | ||||||
|
|
||||||
| private static void validateCount(int count) { | ||||||
| if (count < 0) { | ||||||
| throw new IllegalArgumentException("음수를 입력할 수 없습니다."); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private static void validateNotEmpty(String input) { | ||||||
| if (input == null || input.trim().isEmpty()) { | ||||||
| throw new IllegalArgumentException("빈 값을 입력할 수 없습니다."); | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이 객체가 담당하는 책임이 많아지고 있다.
Lotto 목록을 관리하면서 매칭 책임과 Lotto 목록을 생성하는 책임으로 두 가지 이상을 담당하고 있는 것 같다.
Lotto 목록을 생성하는 책임을 LottosFactory와 같은 다른 객체를 생성해 분리하면 어떨까?
'LottoTickets tickets = LottosFactory.createLottos(int purchaseAmount, List manualLottos)'