-
Notifications
You must be signed in to change notification settings - Fork 39
[스프링 목요일 4팀] (홍지섭) 미션 제출합니다. #48
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: main
Are you sure you want to change the base?
Changes from all commits
23414b1
4027ed1
d38b158
4af8198
220545c
ad45736
f1d63d8
a508587
1d43200
cc4931e
1a6d159
7f4160b
a91b071
cd06328
df03229
1f0b5cc
5d8dc4d
7b7f22a
b40e679
637a55b
732ee71
069c6ed
bf567b0
d7898a4
bca3179
ecdd30c
f1293a9
335f427
350bc32
e8aefb4
34e069e
2d84842
31b5a5b
77ee38c
a555419
28a9df4
983aea9
951d99d
73c2f98
301f7a7
0b3d0fa
6b8f860
3e8e6ad
27a7511
062556a
e1eebd2
d563c1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # JAVA - LOTTO | ||
|
|
||
| https://github.com/TEAM-ALOM/java-lotto | ||
|
|
||
| ## 🗂️ Package 구조(MVC) | ||
|
|
||
| ### **Model** | ||
|
|
||
| #### LottoUser | ||
|
|
||
| - 역할 : (int)`money`, `Lottos`과 `LottosWinningStatus`를 가지고 있는 객체 | ||
|
|
||
| #### Lotto | ||
|
|
||
| - 역할 : 로또의 실질적 데이터 | ||
|
|
||
| #### Lottos | ||
|
|
||
| - 역할 : 구매한 `Lotto`들의 묶음(`List`) 실질적 데이터 | ||
|
|
||
| #### LottoGenerator | ||
|
|
||
| - 역할 : `LottoUser.money`에 따라 `Lotto`들을 생성 | ||
|
|
||
| #### LottosWinningChecker | ||
|
|
||
| - 역할 : `Lottos`의 당첨 계산 후 `LottosWinningStatus` 생성 | ||
|
|
||
| #### LottosWinningStatus | ||
|
|
||
| - 역할 : `WinningNumbers`,`WinningType`를 바탕으로 `Lottos`의 당쳠 계산 `LottoWinningChecker` 결과를 담은 실질적 데이터 | ||
|
|
||
| #### WinningNumbers | ||
|
|
||
| - 역할 : 보너스 번호와 당첨 번호들(하나의 로또 객체)의 실질적 데이터 | ||
|
|
||
| #### WinningType | ||
|
|
||
| - 역할 : 등수 별 당첨 조건 목록의 실질적 데이터 | ||
|
|
||
| ### Controller | ||
|
|
||
| #### LottoSystemController | ||
|
|
||
| - 역할 : 로또 시스템을 실행 | ||
|
|
||
| ### **View** | ||
|
|
||
| #### InputView | ||
|
|
||
| - 역할 : 사용자의 입력을 받는다. | ||
|
|
||
| #### OutputView | ||
|
|
||
| - 역할 : 입력 문구 및 결과 출력한다. | ||
|
|
||
| ### **Validation** | ||
|
|
||
| #### Validation | ||
|
|
||
| #### ErrorMessage | ||
|
|
||
| - 역할 : 에러 메세지 모음 | ||
|
|
||
| ## Test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| package lotto; | ||
|
|
||
| import lotto.controller.LottoSystemController; | ||
| import lotto.model.domain.LottoUser; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| LottoSystemController lottoSystemController = new LottoSystemController(new LottoUser()); | ||
| lottoSystemController.runLottoSystem(); | ||
| } | ||
| } | ||
| } |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package lotto.controller; | ||
|
|
||
| import java.util.List; | ||
| import lotto.model.domain.LottoUser; | ||
| import lotto.model.domain.WinningNumbers; | ||
| import lotto.model.service.LottosGenerator; | ||
| import lotto.model.service.LottosWinningChecker; | ||
| import lotto.view.InputView; | ||
| import lotto.view.OutputView; | ||
|
|
||
| public class LottoSystemController { | ||
|
|
||
| private final LottoUser lottoUser; | ||
|
|
||
| public LottoSystemController(LottoUser lottoUser) { | ||
| this.lottoUser = lottoUser; | ||
| } | ||
|
|
||
| public void runLottoSystem() { | ||
| try { | ||
| buyLottos(); | ||
|
|
||
| WinningNumbers winningNumbers = inputWinningNumbers(); | ||
|
|
||
| winningResult(winningNumbers); | ||
| } catch (IllegalArgumentException e) { | ||
| OutputView.displayErrorMessage(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| private void buyLottos() { | ||
| OutputView.moneyForPurchaseInputMessage(); | ||
| int userMoney = InputView.moneyForPurchaseInput(); | ||
|
|
||
| lottoUser.setMoney(userMoney); | ||
|
|
||
| LottosGenerator.generateLottosAndInput(lottoUser, userMoney); | ||
|
|
||
| OutputView.userLottos(lottoUser.getLottos().getLottoBundle()); | ||
| } | ||
|
|
||
| private WinningNumbers inputWinningNumbers() { | ||
| OutputView.winningNumbersInputMessage(); | ||
| List<Integer> winningNumbersInput = InputView.winningNumbersInput(); | ||
|
|
||
| OutputView.bonusNumberInputMessage(); | ||
| int bonusNumberInput = InputView.bonusNumberInput(); | ||
|
|
||
| return new WinningNumbers( | ||
| winningNumbersInput, bonusNumberInput | ||
| ); | ||
| } | ||
|
|
||
| private void winningResult(WinningNumbers winningNumbers) { | ||
| LottosWinningChecker.generateWinningStatusAndInput(lottoUser, winningNumbers); | ||
| OutputView.winningStatusMessage(lottoUser.getLottosWinningStatus()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package lotto.model.domain; | ||
|
|
||
| import java.util.List; | ||
| import lotto.validation.Validation; | ||
|
|
||
| public class Lotto { | ||
|
|
||
| private final List<Integer> numbers; | ||
|
|
||
| public Lotto(List<Integer> numbers) { | ||
| Validation.validationLotto(numbers); | ||
| this.numbers = numbers; | ||
| } | ||
|
|
||
| public List<Integer> getNumbers() { | ||
| return numbers; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package lotto.model.domain; | ||
|
|
||
| import lotto.validation.Validation; | ||
|
|
||
| public class LottoUser { | ||
| private Lottos lottos; | ||
| private int money; | ||
| private LottosWinningStatus lottosWinningStatus; | ||
|
|
||
| public LottoUser() { | ||
|
|
||
| } | ||
|
|
||
| public LottoUser(int money) { | ||
| this.money = money; | ||
| } | ||
|
|
||
| public LottoUser(Lottos lottos, int money) { | ||
| this.lottos = lottos; | ||
| this.money = money; | ||
| } | ||
|
|
||
| public LottoUser(Lottos lottos, int money, LottosWinningStatus lottosWinningStatus) { | ||
| this.lottos = lottos; | ||
| Validation.validationMoney(money); | ||
| this.money = money; | ||
| this.lottosWinningStatus = lottosWinningStatus; | ||
| } | ||
|
|
||
| public Lottos getLottos() { | ||
| return lottos; | ||
| } | ||
|
|
||
| public int getMoney() { | ||
| return money; | ||
| } | ||
|
|
||
| public LottosWinningStatus getLottosWinningStatus() { | ||
| return lottosWinningStatus; | ||
| } | ||
|
|
||
| public void setLottos(Lottos lottos) { | ||
| this.lottos = lottos; | ||
| } | ||
|
|
||
| public void setLottosWinningStatus(LottosWinningStatus lottosWinningStatus) { | ||
| this.lottosWinningStatus = lottosWinningStatus; | ||
| } | ||
|
|
||
| public void setMoney(int money) { | ||
| this.money = money; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package lotto.model.domain; | ||
|
|
||
| import java.util.List; | ||
| import lotto.validation.Validation; | ||
|
|
||
| public class Lottos { | ||
| private final int count; | ||
| private final List<Lotto> lottoBundle; | ||
|
|
||
| public Lottos(int count, List<Lotto> lottoBundle) { | ||
| Validation.validationCount(count); | ||
| this.count = count; | ||
| Validation.validationLottos(count, lottoBundle); | ||
| this.lottoBundle = lottoBundle; | ||
| } | ||
|
|
||
| public List<Lotto> getLottoBundle() { | ||
| return lottoBundle; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package lotto.model.domain; | ||
|
|
||
| import lotto.validation.Validation; | ||
|
|
||
| public class LottosWinningStatus { | ||
| private final int matchesThree; | ||
| private final int matchesFour; | ||
| private final int matchesFive; | ||
| private final int matchesFiveWithBonus; | ||
| private final int matchesSix; | ||
| private final double profitRatio; | ||
|
|
||
| public LottosWinningStatus(int matchesThree, int matchesFour, int matchesFive, int matchesFiveWithBonus, | ||
|
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. 우테코 클린코드 방향성중 인자가 3개를 넘지 않는것을 권장하는 사항이 있습니다 |
||
| int matchesSix, double profitRatio) { | ||
| this.matchesThree = matchesThree; | ||
| this.matchesFour = matchesFour; | ||
| this.matchesFive = matchesFive; | ||
| this.matchesFiveWithBonus = matchesFiveWithBonus; | ||
| this.matchesSix = matchesSix; | ||
| Validation.validationProfitRatio(profitRatio); | ||
| this.profitRatio = profitRatio; | ||
| } | ||
|
|
||
| public double getProfitRatio() { | ||
| return profitRatio; | ||
| } | ||
|
|
||
| public int getMatchesThree() { | ||
| return matchesThree; | ||
| } | ||
|
|
||
| public int getMatchesFour() { | ||
| return matchesFour; | ||
| } | ||
|
|
||
| public int getMatchesFive() { | ||
| return matchesFive; | ||
| } | ||
|
|
||
| public int getMatchesFiveWithBonus() { | ||
| return matchesFiveWithBonus; | ||
| } | ||
|
|
||
| public int getMatchesSix() { | ||
| return matchesSix; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package lotto.model.domain; | ||
|
|
||
| import java.util.List; | ||
| import lotto.validation.Validation; | ||
|
|
||
| public class WinningNumbers { | ||
| private final Lotto winningLotto; | ||
| private final int bonusNumber; | ||
|
|
||
| public WinningNumbers(List<Integer> winningLotto, int bonusNumber) { | ||
| this.winningLotto = new Lotto(winningLotto); | ||
| Validation.validationBonusNumber(winningLotto, bonusNumber); | ||
| this.bonusNumber = bonusNumber; | ||
| } | ||
|
|
||
| public Lotto getWinningLotto() { | ||
| return winningLotto; | ||
| } | ||
|
|
||
| public int getBonusNumber() { | ||
| return bonusNumber; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package lotto.model.domain; | ||
|
|
||
| public enum WinningType { | ||
| MATCHES_SIX("6개 일치 (2,000,000,000원)", 2_000_000_000), | ||
| MATCHES_FIVE_WITH_BONUS("5개 일치, 보너스 볼 일치 (30,000,000원)", 30_000_000), | ||
| MATCHES_FIVE("5개 일치 (1,500,000원)", 1_500_000), | ||
| MATCHES_FOUR("4개 일치 (50,000원)", 50_000), | ||
| MATCHES_THREE("3개 일치 (5,000원)", 5_000); | ||
|
|
||
| private final String message; | ||
| private final long profitMoney; | ||
|
|
||
| WinningType(String message, long profitMoney) { | ||
| this.message = message; | ||
| this.profitMoney = profitMoney; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return message; | ||
| } | ||
|
|
||
| public long getProfitMoney() { | ||
| return profitMoney; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package lotto.model.service; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lotto.model.domain.Lotto; | ||
| import lotto.model.domain.LottoUser; | ||
| import lotto.model.domain.Lottos; | ||
| import org.kokodak.Randoms; | ||
|
|
||
| public class LottosGenerator { | ||
| private static final int MIN_LOTTO_NUMBER = 1; | ||
| private static final int MAX_LOTTO_NUMBER = 45; | ||
| private static final int LOTTO_COUNT = 6; | ||
|
|
||
|
|
||
| public static void generateLottosAndInput(LottoUser lottoUser, int userMoney) { | ||
| int count = userMoney / 1000; | ||
|
|
||
| lottoUser.setLottos(new Lottos(count, generateLottos(count))); | ||
| } | ||
|
|
||
| private static List<Lotto> generateLottos(int count) { | ||
| List<Lotto> userLottos = new ArrayList<>(); | ||
| for (int i = 0; i < count; i++) { | ||
| userLottos.add(generateLotto()); | ||
| } | ||
| return userLottos; | ||
| } | ||
|
|
||
| private static Lotto generateLotto() { | ||
| return new Lotto(Randoms.pickUniqueNumbersInRange(MIN_LOTTO_NUMBER, MAX_LOTTO_NUMBER, LOTTO_COUNT)); | ||
| } | ||
|
|
||
| } |
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.
List 컬렉션에 이미 .size 메서드가 포함되어 있으니 count 변수 대신, 이를 활용하는 방법을 고려하는 것도 좋을 것 같습니다