-
Notifications
You must be signed in to change notification settings - Fork 1.1k
4단계 - 로또(수동) #4236
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
username0w
wants to merge
16
commits into
next-step:username0w
Choose a base branch
from
username0w:step4
base: username0w
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단계 - 로또(수동) #4236
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dd8555e
docs: 수동 번호 관련 요구사항 추가
username0w 456cc9d
feat: 문자열 리스트로 수동 Lottos 생성하는 메서드 추가
username0w 49cf45f
feat: 수동 자동을 합치기 위한 merge 메서드 추가
username0w ca456e5
feat: 수동 입력 처리 및 로직 개선
username0w cb79cd6
feat: 수동, 자동 로또 출력 형식 개선
username0w fa8b67b
feat: 입력/출력 형식 및 메서드 개선
username0w 0a3f5e6
refactor: 캐싱에 Map 사용
username0w 91ff04e
refactor: rank 비교를 직접 연산자 대신 메서드로 처리
username0w 5c88ab7
feat: 수동 구매 수량 객체 추가
username0w 225ec41
feat: ManualLottoCount 도입
username0w f9454ab
feat: 음수 입력 예외 추가
username0w 1cedd9d
feat: 로또 번호 중복 시 예외 처리
username0w 7da001c
feat: 재입력 처리 로직 추가
username0w 6e21790
refactor: 예외 메시지 상수화
username0w 642f982
feat: LottosGenerator 인터페이스 도입 및 Auto/Manual 구현체 추가
username0w 01f26c6
refactor: LottoApplication에서 LottosGenerator 적용
username0w 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
Some comments aren't visible on the classic Files Changed page.
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
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,23 @@ | ||
| package lotto; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class AutoLottosGenerator implements LottosGenerator { | ||
|
|
||
| private final int count; | ||
|
|
||
| public AutoLottosGenerator(int count) { | ||
| this.count = count; | ||
| } | ||
|
|
||
| @Override | ||
| public Lottos generate() { | ||
| List<Lotto> lottos = new ArrayList<>(); | ||
| for (int i = 0; i < count; i++) { | ||
| lottos.add(LottoMachine.randomLotto()); | ||
| } | ||
| return new Lottos(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,19 @@ | ||
| package lotto; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| public class InputRetry { | ||
|
|
||
| private InputRetry() { | ||
| } | ||
|
|
||
| public static <T> T retry(Supplier<T> action) { | ||
| while (true) { | ||
| try { | ||
| return action.get(); | ||
| } catch (IllegalArgumentException e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
| } |
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 |
|---|---|---|
| @@ -1,25 +1,54 @@ | ||
| package lotto; | ||
|
|
||
| import java.util.List; | ||
| import lotto.view.InputView; | ||
| import lotto.view.ResultView; | ||
|
|
||
| public class LottoApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
|
|
||
| int input = InputView.readPurchaseAmount(); | ||
| PurchaseAmount amount = new PurchaseAmount(input); | ||
| PurchaseAmount amount = createPurchaseAmount(); | ||
|
|
||
| Lottos lottos = LottoMachine.randomLottos(amount.ticketCount()); | ||
| ResultView.printPurchasedLottos(lottos); | ||
| ManualLottoCount manualCount = createManualLottoCount(amount); | ||
| Lottos manualLottos = createManualLottos(manualCount); | ||
| Lottos autoLottos = new AutoLottosGenerator(amount.autoCount(manualCount)).generate(); | ||
|
|
||
| Lotto winningNumbers = new Lotto(InputView.readWinningNumbers()); | ||
| LottoNumber bonusNumber = LottoNumber.of(InputView.readBonusNumber()); | ||
| Lottos purchased = manualLottos.merge(autoLottos); | ||
| ResultView.printPurchasedLottos(purchased, manualCount); | ||
|
|
||
| LottoMatchResult matchResult = lottos.matchResult( | ||
| new WinningNumbers(winningNumbers, bonusNumber)); | ||
| WinningNumbers winningNumbers = createWinningNumbers(); | ||
| LottoMatchResult matchResult = purchased.matchResult(winningNumbers); | ||
| ProfitRate profitRate = new ProfitRate(matchResult.totalPrize(), amount); | ||
|
|
||
| ResultView.printLottoResult(matchResult, profitRate); | ||
| } | ||
|
|
||
| private static PurchaseAmount createPurchaseAmount() { | ||
| return InputRetry.retry(() -> | ||
| new PurchaseAmount(InputView.readPurchaseAmount()) | ||
| ); | ||
| } | ||
|
|
||
| private static ManualLottoCount createManualLottoCount(PurchaseAmount amount) { | ||
| return InputRetry.retry(() -> | ||
| new ManualLottoCount(InputView.readManualLottoCount(), amount) | ||
| ); | ||
| } | ||
|
|
||
| private static Lottos createManualLottos(ManualLottoCount manualCount) { | ||
| return InputRetry.retry(() -> { | ||
| List<String> manualNumbers = InputView.readManualLottos(manualCount.count()); | ||
| LottosGenerator generator = new ManualLottosGenerator(manualNumbers); | ||
| return generator.generate(); | ||
| }); | ||
| } | ||
|
|
||
| private static WinningNumbers createWinningNumbers() { | ||
| return InputRetry.retry(() -> { | ||
| Lotto winning = new Lotto(InputView.readWinningNumbers()); | ||
| LottoNumber bonus = LottoNumber.of(InputView.readBonusNumber()); | ||
| return new WinningNumbers(winning, bonus); | ||
| }); | ||
| } | ||
| } |
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,6 @@ | ||
| package lotto; | ||
|
|
||
| public interface LottosGenerator { | ||
|
|
||
| Lottos generate(); | ||
| } |
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,35 @@ | ||
| package lotto; | ||
|
|
||
| public class ManualLottoCount { | ||
|
|
||
| private static final String ERROR_NEGATIVE_COUNT = "수동 로또 수량은 0 이상이어야 합니다."; | ||
| private static final String ERROR_EXCEED_PURCHASE = "수동 장수는 구입 가능한 수량을 초과할 수 없습니다."; | ||
| private final int count; | ||
|
|
||
| public ManualLottoCount(int count, int purchaseAmount) { | ||
| this(count, new PurchaseAmount(purchaseAmount)); | ||
| } | ||
|
|
||
| public ManualLottoCount(int count, PurchaseAmount amount) { | ||
| validateNonNegativeCount(count); | ||
| validateNotExceedPurchaseAmount(count, amount); | ||
| this.count = count; | ||
| } | ||
|
|
||
| public int count() { | ||
| return count; | ||
| } | ||
|
|
||
| private static void validateNonNegativeCount(int count) { | ||
| if (count < 0) { | ||
| throw new IllegalArgumentException(ERROR_NEGATIVE_COUNT); | ||
| } | ||
| } | ||
|
|
||
| private static void validateNotExceedPurchaseAmount(int count, PurchaseAmount amount) { | ||
| if (amount.ticketCount() < count) { | ||
| throw new IllegalArgumentException(ERROR_EXCEED_PURCHASE); | ||
| } | ||
| } | ||
|
|
||
| } |
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,17 @@ | ||
| package lotto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ManualLottosGenerator implements LottosGenerator { | ||
|
|
||
| private final List<String> manualNumbers; | ||
|
|
||
| public ManualLottosGenerator(List<String> manualNumbers) { | ||
| this.manualNumbers = manualNumbers; | ||
| } | ||
|
|
||
| @Override | ||
| public Lottos generate() { | ||
| return new Lottos(manualNumbers.stream().map(Lotto::new).toList()); | ||
| } | ||
| } |
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.
👍