-
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 all 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,59 @@ | ||
| package lotto.domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class LottoTicketsFactory { | ||
|
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. 이 객체의 복잡도가 높음 |
||
| public static LottoTickets create(PurchaseAmount purchaseAmount) { | ||
| int count = purchaseAmount.getLottoCount(); | ||
| List<Lotto> lottos = generateAutoLottos(count); | ||
| return new LottoTickets(lottos, new ManualLottos(null)); | ||
| } | ||
|
|
||
| public static LottoTickets create(PurchaseAmount purchaseAmount, ManualLottos manualLottos) { | ||
| validateManualCount(purchaseAmount, manualLottos); | ||
| // List<Lotto> allLottos = createLottos(purchaseAmount, manualLottos); | ||
| List<Lotto> lottos = convertToLottos(manualLottos); | ||
| List<Lotto> allLottos = createLottos(purchaseAmount, lottos, manualLottos.getCount()); | ||
| return new LottoTickets(allLottos, manualLottos); | ||
| } | ||
|
|
||
| private static List<Lotto> convertToLottos(ManualLottos manualLottos) { | ||
| List<Lotto> lottos = new ArrayList<>(); | ||
| for (String input : manualLottos.getManualLottosInput()) { | ||
| lottos.add(parseLotto(input)); | ||
| } | ||
| return lottos; | ||
| } | ||
|
|
||
| private static Lotto parseLotto(String input) { | ||
| String[] tokens = input.split(","); | ||
| List<Integer> numbers = new ArrayList<>(); | ||
| for (String token : tokens) { | ||
| numbers.add(Integer.parseInt(token.trim())); | ||
| } | ||
| return Lotto.from(numbers); | ||
| } | ||
|
|
||
|
|
||
| private static void validateManualCount(PurchaseAmount purchaseAmount, ManualLottos manualLottos) { | ||
| if (manualLottos.getCount() > purchaseAmount.getLottoCount()) { | ||
| throw new IllegalArgumentException("수동로또 개수가 구입 가능한 개수보다 많습니다."); | ||
| } | ||
| } | ||
|
|
||
| private static List<Lotto> createLottos(PurchaseAmount purchaseAmount, List<Lotto> manualLottosList, int manualCount) { | ||
| List<Lotto> lottos = new ArrayList<>(manualLottosList); | ||
| int autoCount = purchaseAmount.getLottoCount() - manualCount; | ||
| lottos.addAll(generateAutoLottos(autoCount)); | ||
| return lottos; | ||
| } | ||
|
|
||
| private static List<Lotto> generateAutoLottos(int count) { | ||
| List<Lotto> lottos = new ArrayList<>(); | ||
| for (int i = 0; i < count; i++) { | ||
| lottos.add(Lotto.from(LottoNumberGenerator.generate())); | ||
| } | ||
| return lottos; | ||
| } | ||
| } | ||
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<String> manualLottosInput; | ||
|
|
||
| public ManualLottos(List<String> manualLottosInput) { | ||
| this.manualLottosInput = Optional.ofNullable(manualLottosInput) | ||
| .orElse(Collections.emptyList()); | ||
| } | ||
|
|
||
| public int getCount() { | ||
| return manualLottosInput.size(); | ||
| } | ||
|
|
||
| public List<String> getManualLottosInput() { | ||
| return List.copyOf(manualLottosInput); | ||
| } | ||
| } |
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)'