-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
๐ 4๋จ๊ณ - ๋ก๋(์๋) #3763
base: hhhhhwi
Are you sure you want to change the base?
Changes from all commits
f2a6f58
05deee5
aa0d9a6
4bc2b2a
c255146
705c0ad
5b5d737
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,17 +1,27 @@ | ||
import lotto.domain.LottoMarket; | ||
import lotto.domain.LottoPrice; | ||
import lotto.domain.LottoResult; | ||
import lotto.domain.WinningNumbers; | ||
import lotto.domain.*; | ||
import lotto.domain.strategy.AutoLottoNumberStrategy; | ||
import lotto.domain.strategy.ManualLottoNumberStrategy; | ||
import lotto.io.InputView; | ||
import lotto.io.PrintView; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
LottoPrice lottoPrice = new LottoPrice(InputView.inputPurchasePrice()); | ||
int numberOfLotto = lottoPrice.getNumberOfLotto(); | ||
PrintView.printNumberOfLotto(numberOfLotto); | ||
LottoPrice lottoPrice = new LottoPrice(InputView.inputPurchasePrice(), InputView.inputNumberOfManualLotto()); | ||
int numberOfAutoLotto = lottoPrice.getNumberOfAutoLotto(); | ||
int numberOfManualLotto = lottoPrice.getNumberOfManualLotto(); | ||
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.
๋ค๋ง LottoMarket์ lottoPrice๋ฅผ ์ ๋ฌํด์ LottoMarket์์ ์๋๋ก๋๋ฅผ ์ฌ๋ ์ญํ ์ ํ๋ฉด ์ด๋จ๊น์?? ์ฐจ๋ผ๋ฆฌ ์ฌ์ฉ์๋ก๋ถํฐ ์๋๋ก๋๋ฒํธ๋ฅผ ๋ค ๋ฐ์ ๊ฐ๊ณผ , |
||
|
||
LottoMarket lottoMarket = new LottoMarket(numberOfAutoLotto, new AutoLottoNumberStrategy()); | ||
|
||
if(numberOfManualLotto > 0) { | ||
PrintView.printAutoLottoGuide(); | ||
} | ||
|
||
for(int i = 0; i < numberOfManualLotto; i++) { | ||
lottoMarket.addLotto(new ManualLottoNumberStrategy(InputView.inputLottoNumber())); | ||
} | ||
|
||
PrintView.printNumberOfLotto(numberOfManualLotto, numberOfAutoLotto); | ||
|
||
LottoMarket lottoMarket = new LottoMarket(numberOfLotto); | ||
PrintView.printLottos(lottoMarket.getLottos()); | ||
|
||
WinningNumbers winningNumbers = new WinningNumbers(InputView.inputWinningNumbers(), InputView.inputBonusNumber()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,27 @@ | ||
package lotto.domain; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static lotto.domain.strategy.LottoNumberStrategy.*; | ||
|
||
public class LottoNumbers { | ||
private final List<Integer> lottoNumbers; | ||
|
||
public LottoNumbers(List<Integer> lottoNumbers) { | ||
if(new HashSet<>(lottoNumbers).size() != LOTTO_NUMBER_COUNT) { | ||
throw new IllegalArgumentException("๋ฒํธ๋ ์ค๋ณต๋ ์ ์์ต๋๋ค."); | ||
} | ||
|
||
if(lottoNumbers.size() != LOTTO_NUMBER_COUNT) { | ||
throw new IllegalArgumentException("๋ฒํธ๋ " + LOTTO_NUMBER_COUNT + "๊ฐ๋ฅผ ์ ๋ ฅํด์ผ ํฉ๋๋ค."); | ||
} | ||
|
||
if(lottoNumbers.stream().anyMatch(x -> x < LOTTO_NUMBER_MIN || x > LOTTO_NUMBER_MAX)) { | ||
throw new IllegalArgumentException("๋ฒํธ๋ " + LOTTO_NUMBER_MIN + " ๋ฏธ๋ง " + LOTTO_NUMBER_MAX + " ์ด๊ณผ์ธ ์๋ฅผ ์ ๋ ฅํ ์ ์์ต๋๋ค."); | ||
} | ||
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. ๊ฒ์ฆํ์ ๋ถ๋ถ ์ข์ต๋๋ค ๐ // AS IS
List<Integer> lottoNumbers;
// TO BE
List<LottoNumber> lottoNumbers; ์ด ๋ถ๋ถ ํ๋ฒ ๊ฐ์ ๊ฒํ ํด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ๐ |
||
|
||
this.lottoNumbers = lottoNumbers.stream() | ||
.sorted() | ||
.collect(Collectors.toList()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package lotto.domain.strategy; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ManualLottoNumberStrategy implements LottoNumberStrategy{ | ||
private final List<Integer> numbers; | ||
|
||
public ManualLottoNumberStrategy(List<Integer> numbers) { | ||
this.numbers = numbers; | ||
} | ||
|
||
public ManualLottoNumberStrategy(String[] numbers) { | ||
this(Arrays.stream(numbers) | ||
.map(Integer::parseInt) | ||
.collect(Collectors.toList())); | ||
} | ||
|
||
@Override | ||
public List<Integer> generateLottoNumber() { | ||
return this.numbers; | ||
} | ||
} |
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.
์๊ตฌ์ฌํญ ์ ๋ฆฌ ๐ฏ