-
Notifications
You must be signed in to change notification settings - Fork 2
미션4_로또 게임 수동 #12
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: psh
Are you sure you want to change the base?
The head ref may contain hidden characters: "\uBBF8\uC158_4-\uB85C\uB610\uAC8C\uC784_\uC218\uB3D9"
미션4_로또 게임 수동 #12
Changes from 1 commit
b4287d6
d6529c2
02dde32
e25d0e0
9dc4cce
f0e2d5c
2338e36
5dbd0e7
c6429fb
6576481
e94b114
2a6e1b6
e3c822c
ab04122
0471dfb
442c41c
d3d0aba
167e34a
37aa7fb
51a569e
eb6d329
a913957
6d38f29
032c611
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 |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package lotto.domain.purchaseStrategy; | ||
|
|
||
| import static lotto.domain.LottoTicket.LOTTO_PRICE; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lotto.domain.LottoConsumer; | ||
| import lotto.domain.LottoTicket; | ||
| import lotto.domain.LottoTicketGenerator; | ||
| import lotto.dto.LottoPurchaseDto; | ||
|
|
||
| public class AutoStrategy implements PurchaseStrategy { | ||
|
|
||
| @Override | ||
| public void buyLottoTicket(LottoConsumer consumer, LottoPurchaseDto purchaseDto, LottoTicketGenerator generator) { | ||
| List<LottoTicket> lottoTickets = new ArrayList<>(); | ||
|
|
||
| int purchasedCount = purchaseDto.getMoney() / LOTTO_PRICE; | ||
| int autoPurchasedCount = purchasedCount - consumer.getManualTicketCount(); | ||
|
|
||
| for (int i = 0 ; i < autoPurchasedCount ; i++) { | ||
| lottoTickets.add(generator.autoGenerate()); | ||
| } | ||
|
|
||
| // 로또 티켓 추가 | ||
| consumer.addAutoLottoTickets(lottoTickets); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package lotto.domain.purchaseStrategy; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lotto.domain.LottoConsumer; | ||
| import lotto.domain.LottoTicket; | ||
| import lotto.domain.LottoTicketGenerator; | ||
| import lotto.dto.LottoPurchaseDto; | ||
|
|
||
| public class ManualStrategy implements PurchaseStrategy { | ||
|
|
||
| @Override | ||
| public void buyLottoTicket(LottoConsumer consumer, LottoPurchaseDto purchaseDto, LottoTicketGenerator generator) { | ||
| List<LottoTicket> lottoTickets = new ArrayList<>(); | ||
|
|
||
| for (String[] lottoNumber : purchaseDto.getLottoNumbers()) { | ||
| lottoTickets.add(generator.manualGenerate(lottoNumber)); | ||
| } | ||
|
|
||
| // 로또 티켓 추가 | ||
| consumer.addManualLottoTickets(lottoTickets); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package lotto.domain.purchaseStrategy; | ||
|
|
||
| import lotto.domain.LottoConsumer; | ||
| import lotto.domain.LottoTicketGenerator; | ||
| import lotto.dto.LottoPurchaseDto; | ||
|
|
||
| public interface PurchaseStrategy { | ||
|
Member
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. 오호... 구매행위에 대한 전략을 취하셨군요! 사실 의도한건 로또번호에 대한 전략을 말한거긴 한데 좋습니다 |
||
|
|
||
| void buyLottoTicket(LottoConsumer consumer, LottoPurchaseDto purchaseDto, LottoTicketGenerator generator); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package lotto.dto; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class LottoPurchaseDto { | ||
|
|
||
| private final int money; | ||
|
|
||
| private final List<String[]> lottoNumbers; | ||
|
|
||
| public LottoPurchaseDto(int money, List<String[]> lottoNumbers) { | ||
| this.money = money; | ||
| this.lottoNumbers = new ArrayList<>(); | ||
| if (lottoNumbers != null) { | ||
|
Member
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. 디폴트 변수를 못넣는 자바의 숙명 ㅠㅠ |
||
| this.lottoNumbers.addAll(lottoNumbers); | ||
| } | ||
| } | ||
|
|
||
| public int getMoney() { | ||
| return money; | ||
| } | ||
|
|
||
| public List<String[]> getLottoNumbers() { | ||
| return lottoNumbers; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,8 @@ | |
| import lotto.domain.LottoPrize; | ||
| import lotto.domain.LottoTicket; | ||
| import lotto.domain.LottoTicketGenerator; | ||
| import lotto.domain.purchaseStrategy.PurchaseStrategy; | ||
| import lotto.dto.LottoPurchaseDto; | ||
| import lotto.view.OutputView; | ||
|
|
||
| public class LottoService { | ||
|
|
@@ -18,29 +20,29 @@ public class LottoService { | |
| /** 로또 번호 생성기 */ | ||
| private final LottoTicketGenerator generator; | ||
|
|
||
| /** 로또 구매 전략 */ | ||
| private PurchaseStrategy strategy; | ||
|
|
||
| public LottoService(LottoCalculator calculator, LottoTicketGenerator generator) { | ||
| this.calculator = calculator; | ||
| this.generator = generator; | ||
| } | ||
|
|
||
| /** | ||
| * 로또 티켓을 구매합니다. | ||
| * | ||
| * @param consumer 로또 구매자 객체 | ||
| * @param money 구매 금액 | ||
| * 구매 전략 세팅 | ||
| */ | ||
| public void buyLotto(LottoConsumer consumer, int money) { | ||
| consumer.buyLotto(money, generator); | ||
| public void setPurchaseStrategy(PurchaseStrategy strategy) { | ||
|
Member
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 void buyLottoTicket(/*PurchaseStrategy strategy*/ LottoConsumer consumer, LottoPurchaseDto dto) { |
||
| this.strategy = strategy; | ||
| } | ||
|
|
||
| /** | ||
| * 수동 로또 티켓을 구매합니다. | ||
| * 로또 티켓을 구매합니다. | ||
| * | ||
| * @param consumer LottoConsumer | ||
| * @param lottoNumbers 로또 번호 목록 | ||
| * @param consumer 구매자 | ||
| * @param dto 구매정보 DTO | ||
| */ | ||
| public void buyManualLotto(LottoConsumer consumer, List<String[]> lottoNumbers) { | ||
| consumer.buyManualLotto(lottoNumbers, generator); | ||
| public void buyLottoTicket(LottoConsumer consumer, LottoPurchaseDto dto) { | ||
| strategy.buyLottoTicket(consumer, dto, generator); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
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.
어쩌피 lottoTicketGenerator는 항상 써야 하니까 필수 파라미터로 두고 메서드에서는 제거 할거 같네요.