-
Notifications
You must be signed in to change notification settings - Fork 26
로또 2단계 미션 제출합니다. #39
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: riroan
Are you sure you want to change the base?
로또 2단계 미션 제출합니다. #39
Changes from all commits
a9c5422
f771d8a
2734bf6
07b45cd
3f2d78e
cffc988
de4c285
510b9c6
8b37c7a
90da4f5
98495f6
fc22f12
cebeca5
2614743
668fa68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package lotto.domain; | ||
|
|
||
| import lotto.generator.ManualLottoGenerator; | ||
| import lotto.generator.RandomLottoGenerator; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class LottoSystem { | ||
| private static final Money LOTTO_PRICE = new Money(1000); | ||
|
|
||
| public List<Lotto> buyAutoLotto(Money money) { | ||
| return generateAutoLottos(money.canBuyCount()); | ||
| } | ||
|
|
||
| public void validateNumberOfManualLotto(int numberOfManualLotto) { | ||
| if (numberOfManualLotto < 0) { | ||
| throw new IllegalArgumentException("유효하지 않은 수동 구매 개수입니다!"); | ||
| } | ||
| } | ||
|
|
||
| public WinningNumber convertToAnswer(List<Integer> answerAndBonusNumber) { | ||
| Lotto lotto = convertNumbersToLotto(answerAndBonusNumber.subList(0, 6)); | ||
| Ball bonusBall = new Ball(answerAndBonusNumber.get(6)); | ||
|
|
||
| return new WinningNumber(lotto, bonusBall); | ||
| } | ||
riroan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public Lotto convertNumbersToLotto(List<Integer> numbers) { | ||
| ManualLottoGenerator generator = new ManualLottoGenerator(numbers); | ||
| return generator.generateLotto(); | ||
| } | ||
|
|
||
| private List<Lotto> generateAutoLottos(long count) { | ||
| RandomLottoGenerator generator = RandomLottoGenerator.getInstance(); | ||
| return generator.generateAutoLottos(count); | ||
| } | ||
|
Comment on lines
+28
to
+36
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. 이 부분은 제가 의도한거랑은 조금 차이가 있는데요. 🙄 List<LottoGenerator> lottoGenerators = List.of(
new RandomLottoGenerator(),
new RandomLottoGenerator(),
new ManualLottoGenerator(List.of(1, 2, 3, 4, 5, 6)),
new ManualLottoGenerator(List.of(1, 2, 3, 4, 5, 6))
);
new Lottos(
lottoGenerators.stream()
.map(it -> it.generate())
.collect(Collectors.toList())
);
이런 느낌을 기대하긴 했어요. 작성해 주신 구조라면 다형성이 크게 의미는 없을 것 같아서요. |
||
|
|
||
| public Result scoreLottos(Lottos lottos, WinningNumber winningNumber) { | ||
| return lottos.scoreLottos(winningNumber); | ||
| } | ||
|
|
||
| public Profit calculateProfit(Result result, Lottos lottos) { | ||
| long reward = result.calculateReward(); | ||
| long seed = lottos.getSeed(); | ||
|
|
||
| return new Profit(reward, seed); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,9 @@ | ||
| package lotto.domain; | ||
|
|
||
| import lotto.domain.Lotto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Lottos { | ||
| private static final Money LOTTO_PRICE = new Money(1000); | ||
| private final List<Lotto> values; | ||
|
|
||
| public Lottos(List<Lotto> values) { | ||
|
|
@@ -18,4 +17,16 @@ public int getSize() { | |
| public Lotto get(int ix) { | ||
| return values.get(ix); | ||
| } | ||
|
|
||
|
Comment on lines
17
to
+20
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. 이 메서드는 view에서 사용하고 있는데요. 웹 환경이라면 해당 메서드는 호출 가능한가요?
Author
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. 이 코멘트는 무슨 의미인지 이해하지 못했습니다.. 🤔 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. https://edu.nextstep.camp/s/MCLQmhAp/ls/DO2AJZZW 젤 아래에 |
||
| public Result scoreLottos(WinningNumber winningNumber) { | ||
| Result result = new Result(); | ||
| for (Lotto lotto : values) { | ||
| result.scoreLotto(lotto, winningNumber); | ||
| } | ||
| return result; | ||
| } | ||
|
Comment on lines
+21
to
+27
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 Result scoreLottos(WinningNumber winningNumber) {
return new Result(
values.stream()
.map(it -> winningNumber.match(it))
.collect(Collectors.groupingBy(it -> it, Collectors.counting()))
);
}이런 방법도 있을 것 같아요. 이 경우 테스트는 더 유연해 지지 않을까요? 테스트 코드는 어떻게 변경될 수 있을까요? 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. Result.reward는 필드에 꼭 필요할까요? 내부 Map 에서 계산할 수 있지 않을까요? |
||
|
|
||
| public long getSeed() { | ||
| return values.size() * LOTTO_PRICE.getValue(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,41 @@ | ||
| package lotto.enums; | ||
|
|
||
| public enum Ranking { | ||
| FAIL(0), FIFTH(1), FOURTH(2), THIRD(3), SECOND(4), FIRST(5); | ||
| FAIL(0, 0), FIFTH(1, 5000), FOURTH(2, 50000), THIRD(3, 1500000), SECOND(4, 30000000), FIRST(5, 2000000000); | ||
|
|
||
| final int value; | ||
| private final int ix; | ||
| private final long value; | ||
|
|
||
| Ranking(int value) { | ||
| Ranking(int ix, long value) { | ||
| this.ix = ix; | ||
| this.value = value; | ||
| } | ||
|
|
||
| public long getReward() { | ||
| if (value == Ranking.FIRST.value) { | ||
| return 2000000000; | ||
| public static Ranking getRank(long answerCount, boolean isCorrectBonusBall) { | ||
| if (answerCount == 6) { | ||
| return Ranking.FIRST; | ||
| } | ||
|
|
||
| if (value == Ranking.SECOND.value) { | ||
| return 30000000; | ||
| if (answerCount == 5 && isCorrectBonusBall) { | ||
| return Ranking.SECOND; | ||
| } | ||
|
|
||
| if (value == Ranking.THIRD.value) { | ||
| return 1500000; | ||
| if (answerCount == 5) { | ||
| return Ranking.THIRD; | ||
| } | ||
|
|
||
| if (value == Ranking.FOURTH.value) { | ||
| return 50000; | ||
| if (answerCount == 4) { | ||
| return Ranking.FOURTH; | ||
| } | ||
|
|
||
| if (value == Ranking.FIFTH.value) { | ||
| return 5000; | ||
| if (answerCount == 3) { | ||
| return Ranking.FIFTH; | ||
| } | ||
|
|
||
| return 0; | ||
| return Ranking.FAIL; | ||
| } | ||
|
|
||
| public long getValue() { | ||
| return value; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package lotto.generator; | ||
|
|
||
| import lotto.domain.Lotto; | ||
|
|
||
| public interface LottoGenerator { | ||
| Lotto generateLotto(); | ||
| } |
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.
lottoSystem의 역할은 무엇인가요? 메서드들을 보니 책임이 하나인 것 같지는 않아서요.
Uh oh!
There was an error while loading. Please reload this page.
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.
로또 플레이할 때 필요한 기능들을 모아둔 클래스입니다. 어떻게 쪼개야할 지 몰라서 한 클래스에 모두 들어간 느낌이네요..