-
Notifications
You must be signed in to change notification settings - Fork 326
[2단계 - 로또(수동)] 기론(김규철) 미션 제출합니다. #444
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
Changes from all commits
873a9f4
1210aad
d823a1f
9ea144d
b9dfe71
8116b94
15432f7
a23c181
7497f85
a79cbb9
2bc1eec
d41a985
069301c
62b2a54
b4c3ec5
f17eaa4
291d619
fa9501a
cee97de
449a848
f66270d
71d6380
85e822b
7366195
b69e4e9
4d67be0
94361e3
cc117ce
83a01c7
6a8eefa
9875d20
4764515
6680172
35ab131
43d82c9
dd4362c
a38645c
0287e78
fb575e0
70a69f2
9cbc911
46417a0
6faef49
4987375
f37b823
7519d44
c89bff0
4574bf5
f538071
ac1cb12
c9a174b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,30 @@ | ||
| import controller.LottoController; | ||
| import controller.dto.LottosDto; | ||
| import controller.dto.StatisticDto; | ||
| import domain.Money; | ||
| import service.LottoService; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| LottoMachine lottoMachine = new LottoMachine(); | ||
| lottoMachine.start(); | ||
| LottoController lottoController = new LottoController(new LottoService()); | ||
| int inputMoney = InputView.askInputMoney(); | ||
| int manualLottoCount = InputView.askManualLottoCount(); | ||
| List<String[]> manualLottoNumbers = InputView.askManualLottoNumbers(manualLottoCount); | ||
| LottosDto lottosDto = lottoController.purchase(inputMoney, manualLottoCount, manualLottoNumbers); | ||
| OutputView.printCountOfLotto(lottosDto.getSize(), manualLottoCount); | ||
|
|
||
| OutputView.printLottos(lottosDto); | ||
| String[] inputWinningNumber = InputView.askInputWinningNumber(); | ||
| int inputBonusBall = InputView.askInputBonusBall(); | ||
|
|
||
| StatisticDto statisticDto = lottoController.winningResult(inputWinningNumber, inputBonusBall, | ||
| manualLottoNumbers, inputMoney); | ||
|
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. 수동 로또 번호만 입력하고 있어요 😭 |
||
| OutputView.printStatistics(statisticDto); | ||
| OutputView.printProfitRate(statisticDto.getProfitRate()); | ||
|
|
||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||
| package controller; | ||||||
|
|
||||||
| import controller.dto.LottosDto; | ||||||
| import controller.dto.StatisticDto; | ||||||
| import domain.*; | ||||||
| import service.LottoService; | ||||||
|
|
||||||
| import java.util.List; | ||||||
|
|
||||||
| public class LottoController { | ||||||
|
|
||||||
| private final LottoService lottoService; | ||||||
|
|
||||||
| public LottoController(LottoService lottoService) { | ||||||
| this.lottoService = lottoService; | ||||||
| } | ||||||
|
|
||||||
| public LottosDto purchase(int inputMoney, int manualLottoCount, List<String[]> manualLottoNumbers) { | ||||||
|
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. 로또 구입할 때 구입 금액과 선택한 로또 번호만 주면 구입할 수 있지 않나요? |
||||||
| Money money = lottoService.createMoney(inputMoney); | ||||||
| int autoLottoCount = lottoService.getAutoLottoCount(money, manualLottoCount); | ||||||
| Lottos lottos = lottoService.generateLottos(manualLottoNumbers, autoLottoCount); | ||||||
|
Comment on lines
+19
to
+21
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. 서비스 로직이 응집도가 낮은 것 같아요. 로또 구입 기능을 제공하는 서비스가 되어야 하지 않을까요?
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. 그렇네요 서비스에서 모든 것을 처리하고 결과만 반환하니 더욱 깔끔해진 것 같습니다! 여기서 서비스 로직이 응집도가 낮다는 것은 어떤 이유인지 알 수 있을까요?
|
||||||
|
|
||||||
| return LottosDto.from(lottos, lottos.size()); | ||||||
| } | ||||||
|
|
||||||
| public StatisticDto winningResult(String[] inputWinningNumber, | ||||||
| int inputBonusBall, | ||||||
| List<String[]> manualLottoNumbers, | ||||||
|
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
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. 아예 로또들 Dto를 받도록 수정했습니다! List<String[]>으로 하려면 만들어진 Lottos를 다시 돌면서 List<String[]> 에 맞는 형으로 바꿔야 할것 같아서 Dto로 넘겼습니다. 그런데 이렇게하니 |
||||||
| int inputMoney) { | ||||||
| WinningLotto winningLotto = lottoService.generateWinningLotto( | ||||||
| new ManualLottoGenerator(inputWinningNumber), | ||||||
| inputBonusBall); | ||||||
|
|
||||||
| Lottos lottos = lottoService.generateLottos(manualLottoNumbers, 0); | ||||||
| Statistic winningStatistics = lottos.getWinningStatistics(winningLotto); | ||||||
| Money money = lottoService.createMoney(inputMoney); | ||||||
| return StatisticDto.from(winningStatistics, winningStatistics.getProfitRate(money)); | ||||||
|
Comment on lines
+30
to
+37
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. 이 부분도 마찬가지로 서비스 로직의 응집도가 낮은 것 같습니다! |
||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package controller.dto; | ||
|
|
||
| import domain.Lotto; | ||
| import domain.LottoNumber; | ||
|
|
||
| import java.util.LinkedHashSet; | ||
| import java.util.Set; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class LottoDto { | ||
| private final Set<Integer> numbers; | ||
|
|
||
| public LottoDto(Set<Integer> numbers) { | ||
| this.numbers = new LinkedHashSet<>(numbers); | ||
| } | ||
|
|
||
| public static LottoDto from(Lotto lotto) { | ||
| Set<LottoNumber> lottoNumbers = lotto.getNumbers(); | ||
|
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. 변수로 담을 필요 없지 않을까요? |
||
| return lottoNumbers.stream() | ||
| .map(LottoNumber::getLottoNumber) | ||
| .collect(Collectors.collectingAndThen(Collectors.toUnmodifiableSet(), LottoDto::new)); | ||
|
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. unmodifiableSet으로 변환할 필요가 있을까요? |
||
| } | ||
|
|
||
| public Set<Integer> getNumbers() { | ||
| return numbers; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package controller.dto; | ||
|
|
||
| import domain.Lottos; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class LottosDto { | ||
| private final List<LottoDto> lottoDtos; | ||
| private final int size; | ||
|
|
||
| public LottosDto(List<LottoDto> lottoDtos, int size) { | ||
| this.lottoDtos = new ArrayList<>(lottoDtos); | ||
| this.size = size; | ||
| } | ||
|
|
||
| public List<LottoDto> getLottoDtos() { | ||
| return lottoDtos; | ||
| } | ||
|
|
||
| public int getSize() { | ||
| return size; | ||
| } | ||
|
|
||
| public static LottosDto from(Lottos lottos, int size) { | ||
| return lottos.getLottos() | ||
| .stream() | ||
| .map(LottoDto::from) | ||
| .collect(Collectors.collectingAndThen( | ||
| Collectors.toUnmodifiableList(), | ||
| lottoDtos -> new LottosDto(lottoDtos, size) | ||
| )); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package controller.dto; | ||
|
|
||
| import domain.Rank; | ||
|
|
||
| public class RankDto { | ||
| private final int count; | ||
| private final int winningPrice; | ||
| private final boolean hasBonusBall; | ||
|
|
||
| public RankDto(int count, int winningPrice, boolean hasBonusBall) { | ||
| this.count = count; | ||
| this.winningPrice = winningPrice; | ||
| this.hasBonusBall = hasBonusBall; | ||
| } | ||
|
|
||
|
|
||
| public static RankDto from(Rank rank) { | ||
| return new RankDto( | ||
| rank.getCount(), | ||
| rank.getWinningPrice(), | ||
| rank.hasBonusBall() | ||
| ); | ||
| } | ||
|
|
||
| public int getCount() { | ||
| return count; | ||
| } | ||
|
|
||
| public int getWinningPrice() { | ||
| return winningPrice; | ||
| } | ||
|
|
||
| public boolean hasBonusBall() { | ||
| return hasBonusBall; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package controller.dto; | ||
|
|
||
| import domain.Statistic; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class StatisticDto { | ||
| private final Map<RankDto, Integer> statisticDto; | ||
| private final double profitRate; | ||
|
|
||
| public StatisticDto(Map<RankDto, Integer> statisticDto, double profitRate) { | ||
| this.statisticDto = new LinkedHashMap<>(statisticDto); | ||
| this.profitRate = profitRate; | ||
| } | ||
|
|
||
| public static StatisticDto from(Statistic statistics, double profitRate) { | ||
| return statistics.getStatistics().entrySet() | ||
| .stream() | ||
| .collect(Collectors.collectingAndThen(Collectors.toMap( | ||
| statistic -> RankDto.from(statistic.getKey()), | ||
| Map.Entry::getValue, | ||
| (key, value) -> key, | ||
| LinkedHashMap::new | ||
| ), statisticDto1 -> new StatisticDto(statisticDto1, profitRate)) | ||
| ); | ||
| } | ||
|
|
||
| public Map<RankDto, Integer> getStatisticDto() { | ||
| return new LinkedHashMap<>(statisticDto); | ||
| } | ||
|
|
||
| public double getProfitRate() { | ||
| return profitRate; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package domain; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static domain.Lotto.LOTTO_LENGTH; | ||
|
|
||
| public class AutoLottoGenerator implements LottoGenerator { | ||
|
|
||
| @Override | ||
| public Lotto generateLotto() { | ||
| List<LottoNumber> numbers = LottoNumber.values(); | ||
| Collections.shuffle(numbers); | ||
| return new Lotto(numbers.stream() | ||
| .limit(LOTTO_LENGTH) | ||
| .collect(Collectors.toSet())); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| package domain; | ||
|
|
||
| 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.
코멘트가 안달려 여기다가 답변해둘게요.
Q. #444 (comment)
기론이 생각하신 부분이 맞고, 더 나아가서 view 패키지를 완전히 독립적인 다른 애플리케이션(프론트엔드)라고 생각하고 의존성을 끊어내보면 더 많이 고민하고 연습이 되지 않을까 싶은 의도가 있었습니다!
Q. #444 (comment)
LottoNumber를 의존하고 있고 LottoNumber가 캐싱하고 있기 때문에 메서드로 제공하여 중복을 제거하면 좋겠다는 의도로 드린 코멘트입니다:)