-
Notifications
You must be signed in to change notification settings - Fork 6
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
oereo 2차과제 제출합니다! #7
base: oereo
Are you sure you want to change the base?
Changes from all commits
d9441fe
16b3952
44d3e1a
a6ef619
3314074
d58b466
c0f662f
d1d653f
a159daa
086390e
468a962
7154d90
abe5f75
4b16472
2fdafea
626d3ce
8d7bcfb
6c7f169
810e10d
410dd30
105b982
400a17f
b93c455
e679a21
ff36d2f
84bce7b
eb4c72e
dd367b9
da70a37
a6dc029
a0d13ba
1d12786
5859dc5
5287a42
d7e838b
31a24f1
a4ce239
26d61ed
e48382c
5ef4133
57a0cee
655004a
87274f7
7feae6d
b67f680
1eacddf
7a26eff
bd9ad04
c162ffd
d92e3ef
589959e
3a9bc9e
11ee54c
e850955
6c97b6e
1e60a5d
e1773ee
67041a0
a6cc6fa
3dddc32
3205eca
9aaabfa
e2d5526
6b432c5
9fb25c1
36d6809
80d552f
3d82bb6
fc06755
082fb66
7c0aec0
8eca2f2
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,3 +1,4 @@ | ||
.idea/ | ||
.gradle/ | ||
build/ | ||
out |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package lotto; | ||
|
||
import lotto.domain.LottoStore; | ||
import lotto.domain.NumberOfLottoTicket; | ||
import lotto.domain.PurchaseAmount; | ||
import lotto.domain.lotto.LastWeekWinningBonusBall; | ||
import lotto.domain.lotto.LastWeekWinningLotto; | ||
import lotto.domain.lotto.LottoAutomaticTickets; | ||
import lotto.domain.lotto.LottoManualTickets; | ||
|
||
public class LottoApplication { | ||
private final LottoStore lottoStore = new LottoStore(); | ||
|
||
public void run() { | ||
PurchaseAmount purchaseAmount = lottoStore.inputLottoPurchaseAmount(); | ||
int lottoManualTicketNumber = lottoStore.inputLottoManualTicketNumber(); | ||
LottoManualTickets lottoManualTickets = lottoStore.inputLottoManualTickets(lottoManualTicketNumber); | ||
NumberOfLottoTicket numberOfLottoTicket = lottoStore.informNumberOfLottoTicket(purchaseAmount, lottoManualTicketNumber); | ||
LottoAutomaticTickets lottoAutomaticTickets = lottoStore.informLottoAutomaticTickets(lottoManualTickets, numberOfLottoTicket); | ||
LastWeekWinningLotto lastWeekWinningLotto = lottoStore.inputLastWeekWinningLotto(); | ||
LastWeekWinningBonusBall lastWeekWinningBonusBall = lottoStore.inputLastWeekWinningBonusBall(); | ||
lottoStore.informLottoStatistics(numberOfLottoTicket, lottoManualTickets, lottoAutomaticTickets, lastWeekWinningLotto, lastWeekWinningBonusBall); | ||
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. 수정하기 -> method에 4개이상의 인자 받지 않기 -> 객체로 빼기
Comment on lines
+15
to
+22
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. 다양한 객체에게 역할을 위임하고 값을 리턴 받으면서 로직이 진행되어야 하는데, 그리고 한 가지 객체(LottoStore)에게만 값을 요청한다는 것은 그 객체가 갖고 있는 책임이 많다는 것을 의미하기도 해요. |
||
} | ||
|
||
public static void main(String[] args) { | ||
LottoApplication app = new LottoApplication(); | ||
app.run(); | ||
Comment on lines
+26
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. Application이 Application을 생성해서 실행시키는 것이 어색하게 느껴지네요. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,146 @@ | ||||||||||||||||||||||||||||
package lotto.domain; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import lotto.domain.lotto.*; | ||||||||||||||||||||||||||||
import lotto.domain.strategy.RandomLottoNumberGenerator; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
import java.util.ArrayList; | ||||||||||||||||||||||||||||
import java.util.HashMap; | ||||||||||||||||||||||||||||
import java.util.List; | ||||||||||||||||||||||||||||
import java.util.Map; | ||||||||||||||||||||||||||||
import java.util.stream.Collectors; | ||||||||||||||||||||||||||||
import java.util.stream.IntStream; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public class LottoMachine { | ||||||||||||||||||||||||||||
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. 빈약한 도메인모델의 문제점을 해결하면서 method들도 최대한 분리 시키고 LottoMachine 의 역할을 명확하게 다시 바꿔볼게요! |
||||||||||||||||||||||||||||
private final static int LOTTO_SIZE = 6; | ||||||||||||||||||||||||||||
private final static int WINNING_LOTTO_WITH_BONUS_BALL_MATCHED_COUNT = 5; | ||||||||||||||||||||||||||||
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. 상수명을 보너스 볼 없이 5개의 matchedCount를 가진 경우도 포함될 수 있게 해주세요! 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. 보너스 볼이 있는 경우의 |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private final RandomLottoNumberGenerator randomLottoNumberGenerator = new RandomLottoNumberGenerator(); | ||||||||||||||||||||||||||||
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. LottoMachine에 대한 테스트가 없어서 체감을 못하셨을텐데, 랜덤으로 인해 |
||||||||||||||||||||||||||||
private final ArrayList<WinningStatus> lottoPrices = new ArrayList<>(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public LottoAutomaticTickets generateLottoAutomaticTicket(NumberOfLottoTicket numberOfLottoTicket) { | ||||||||||||||||||||||||||||
int numberOfLottoAutomaticTicket = numberOfLottoTicket.getAutomaticLottoTicketOfNumber(); | ||||||||||||||||||||||||||||
List<LottoAutomaticTicket> lottoAutomaticTicket = IntStream.range(0, numberOfLottoAutomaticTicket). | ||||||||||||||||||||||||||||
mapToObj(lottoTicket -> new LottoAutomaticTicket(randomLottoNumberGenerator.getRandomLottoNumbers())). | ||||||||||||||||||||||||||||
collect(Collectors.toList()); | ||||||||||||||||||||||||||||
return new LottoAutomaticTickets(lottoAutomaticTicket); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public List<LottoMatchStatus> lottoManualTicketsDiscriminator( | ||||||||||||||||||||||||||||
LottoManualTickets lottoManualTickets, | ||||||||||||||||||||||||||||
LastWeekWinningLotto lastWeekWinningLotto, | ||||||||||||||||||||||||||||
LastWeekWinningBonusBall lastWeekWinningBonusBall) { | ||||||||||||||||||||||||||||
List<LottoMatchStatus> lottoMatchStatuses = new ArrayList<>(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
for (LottoManualTicket lottoManualTicket : lottoManualTickets.getLottoManualTickets()) { | ||||||||||||||||||||||||||||
int matchedLottoManualTicketCount = calculateMatchedLottoManualTicket(lottoManualTicket, lastWeekWinningLotto); | ||||||||||||||||||||||||||||
Boolean isMatchedBonusBall = calculateMatchedBonusBallManualTicket(lottoManualTicket, lastWeekWinningBonusBall); | ||||||||||||||||||||||||||||
LottoMatchStatus lottoMatchStatus = new LottoMatchStatus(matchedLottoManualTicketCount, isMatchedBonusBall); | ||||||||||||||||||||||||||||
lottoMatchStatuses.add(lottoMatchStatus); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+34
to
+39
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. LottoManualTicket를 get()해서 처리하고 있다는 것은 이 로직이 LottoManualTicket의 역할이란 의미에요. |
||||||||||||||||||||||||||||
return lottoMatchStatuses; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public List<LottoMatchStatus> lottoAutomaticTicketsDiscriminator( | ||||||||||||||||||||||||||||
LottoAutomaticTickets lottoAutomaticTickets, | ||||||||||||||||||||||||||||
LastWeekWinningLotto lastWeekWinningLotto, | ||||||||||||||||||||||||||||
LastWeekWinningBonusBall lastWeekWinningBonusBall) { | ||||||||||||||||||||||||||||
List<LottoMatchStatus> lottoMatchStatuses = new ArrayList<>(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
for (LottoAutomaticTicket lottoAutomaticTicket : lottoAutomaticTickets.getLottoAutomaticTickets()) { | ||||||||||||||||||||||||||||
int matchedLottoAutomaticTicketCount = calculateMatchedLottoAutomaticTicket(lottoAutomaticTicket, lastWeekWinningLotto); | ||||||||||||||||||||||||||||
Boolean isMatchedBonusBall = calculateMatchedBonusBallAutomaticTicket(lottoAutomaticTicket, lastWeekWinningBonusBall); | ||||||||||||||||||||||||||||
LottoMatchStatus lottoMatchStatus = new LottoMatchStatus(matchedLottoAutomaticTicketCount, isMatchedBonusBall); | ||||||||||||||||||||||||||||
lottoMatchStatuses.add(lottoMatchStatus); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+49
to
+54
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. 마찬가지로 lottoAutomaticTickets의 역할로 변경해보세요 :) |
||||||||||||||||||||||||||||
return lottoMatchStatuses; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private Boolean calculateMatchedBonusBallAutomaticTicket( | ||||||||||||||||||||||||||||
LottoAutomaticTicket lottoAutomaticTicket, | ||||||||||||||||||||||||||||
LastWeekWinningBonusBall lastWeekWinningBonusBall) { | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
List<Integer> lottoTicket = lottoAutomaticTicket.getLotto(); | ||||||||||||||||||||||||||||
int WinningBonusBalls = lastWeekWinningBonusBall.getLastWeekWinningBonusBall(); | ||||||||||||||||||||||||||||
return lottoTicket.contains(WinningBonusBalls); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+58
to
+65
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. 오 이부분을 진짜 어떻게 해야될지 고민을 많이 했는데 다형성을 이용해야겠네요! |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private int calculateMatchedLottoAutomaticTicket( | ||||||||||||||||||||||||||||
LottoAutomaticTicket lottoAutomaticTicket, | ||||||||||||||||||||||||||||
LastWeekWinningLotto lastWeekWinningLotto) { | ||||||||||||||||||||||||||||
Comment on lines
+67
to
+69
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. 맞아요. 동일한 기능을 하는 객체를 추출하는 방식으로 변경해보는건 어떨까요? |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
List<Integer> lottoTicket = lottoAutomaticTicket.getLotto(); | ||||||||||||||||||||||||||||
List<Integer> lastWeekWinningLottoTicket = lastWeekWinningLotto.getLotto(); | ||||||||||||||||||||||||||||
int matchedCount = 0; | ||||||||||||||||||||||||||||
for (int lottoNumber = 0; lottoNumber < LOTTO_SIZE; lottoNumber++) { | ||||||||||||||||||||||||||||
Boolean isMatchLottoNumber = lottoTicket.contains(lastWeekWinningLottoTicket.get(lottoNumber)); | ||||||||||||||||||||||||||||
matchedCount += countMatchedLottoNumber(isMatchLottoNumber); | ||||||||||||||||||||||||||||
Comment on lines
+75
to
+76
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
이렇게 하고 |
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return matchedCount; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private Boolean calculateMatchedBonusBallManualTicket( | ||||||||||||||||||||||||||||
LottoManualTicket lottoManualTicket, | ||||||||||||||||||||||||||||
LastWeekWinningBonusBall lastWeekWinningBonusBall) { | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
List<Integer> lottoTicket = lottoManualTicket.getLotto(); | ||||||||||||||||||||||||||||
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. 이곳 뿐만 아니라 대부분의 코드에서, 원시값을 포장하고, 관련된 로직을 해당 객체 안에서 처리하는 방식으로 변경하면 좋을 것 같아요 :) |
||||||||||||||||||||||||||||
int WinningBonusBalls = lastWeekWinningBonusBall.getLastWeekWinningBonusBall(); | ||||||||||||||||||||||||||||
return lottoTicket.contains(WinningBonusBalls); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private int calculateMatchedLottoManualTicket( | ||||||||||||||||||||||||||||
LottoManualTicket lottoManualTicket, | ||||||||||||||||||||||||||||
LastWeekWinningLotto lastWeekWinningLotto) { | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
List<Integer> lottoTicket = lottoManualTicket.getLotto(); | ||||||||||||||||||||||||||||
List<Integer> lastWeekWinningLottoTicket = lastWeekWinningLotto.getLotto(); | ||||||||||||||||||||||||||||
int matchedCount = 0; | ||||||||||||||||||||||||||||
for (int lottoNumber = 0; lottoNumber < LOTTO_SIZE; lottoNumber++) { | ||||||||||||||||||||||||||||
Boolean isMatchLottoNumber = lottoTicket.contains(lastWeekWinningLottoTicket.get(lottoNumber)); | ||||||||||||||||||||||||||||
matchedCount += countMatchedLottoNumber(isMatchLottoNumber); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+98
to
+101
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 matchedCount; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private int countMatchedLottoNumber(Boolean isMatchLottoNumber) { | ||||||||||||||||||||||||||||
if (isMatchLottoNumber) { | ||||||||||||||||||||||||||||
return 1; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return 0; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public List<WinningStatus> getStatistics(List<LottoMatchStatus> lottoAllTicketMatchStatuses) { | ||||||||||||||||||||||||||||
for (LottoMatchStatus lottoMatchStatus : lottoAllTicketMatchStatuses) { | ||||||||||||||||||||||||||||
mappingLottoTicketWithBonusBall(lottoMatchStatus); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return lottoPrices; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private void mappingLottoTicketWithBonusBall(LottoMatchStatus lottoMatchStatus) { | ||||||||||||||||||||||||||||
for (WinningStatus winningStatus : WinningStatus.values()) { | ||||||||||||||||||||||||||||
compareWinningStatus(winningStatus, lottoMatchStatus.getMatchedCount(), lottoMatchStatus.getHasBonusBall()); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+119
to
+123
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. matchedCount와 hasBonusBall 두 개를 비교하는데 메서드 이름은 |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
private void compareWinningStatus(WinningStatus winningStatus, int lottoMatchedCount, Boolean hasBonusBall) { | ||||||||||||||||||||||||||||
if ((winningStatus.getMatchCount() == lottoMatchedCount) && (lottoMatchedCount != WINNING_LOTTO_WITH_BONUS_BALL_MATCHED_COUNT)) { | ||||||||||||||||||||||||||||
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. if문이 길어질땐 if문의 조건 식을 메소드로 추출해서 직관적으로 표현하는 것이 좋습니다 :) |
||||||||||||||||||||||||||||
lottoPrices.add(winningStatus); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
if ((winningStatus.hasBonusBall() == hasBonusBall) && (lottoMatchedCount == WINNING_LOTTO_WITH_BONUS_BALL_MATCHED_COUNT)) { | ||||||||||||||||||||||||||||
lottoPrices.add(winningStatus); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+125
to
+132
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
if문 안을 메서드로 분리하여 이렇게 통일할 수 있겠어요 |
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public Map<WinningStatus, Integer> getMappingLottoWithBonusBall() { | ||||||||||||||||||||||||||||
Map<WinningStatus, Integer> mappingLottoWithBonusBall = new HashMap<>(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
for (WinningStatus key : lottoPrices) { | ||||||||||||||||||||||||||||
mappingLottoWithBonusBall.put(key, mappingLottoWithBonusBall.getOrDefault(key, 0) + 1); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
return mappingLottoWithBonusBall; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
public Profit getProfitInformation(List<WinningStatus> lottoStatistics, NumberOfLottoTicket numberOfLottoTicket) { | ||||||||||||||||||||||||||||
return new Profit(lottoStatistics, numberOfLottoTicket); | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package lotto.domain; | ||
|
||
public class LottoMatchStatus { | ||
private final int matchedCount; | ||
private final Boolean hasBonusBall; | ||
|
||
public LottoMatchStatus(int matchedCount, Boolean hasBonusBall) { | ||
this.matchedCount = matchedCount; | ||
this.hasBonusBall = hasBonusBall; | ||
} | ||
|
||
public int getMatchedCount() { | ||
return matchedCount; | ||
} | ||
|
||
public Boolean getHasBonusBall() { | ||
return hasBonusBall; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package lotto.domain; | ||
|
||
import lotto.domain.lotto.*; | ||
import lotto.ui.Printer; | ||
import lotto.ui.Receiver; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LottoStore { | ||
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. 어플리케이션의 전체적인 흐름을 담당하는 클래스군요 |
||
private final Printer printer = new Printer(); | ||
private final Receiver receiver = new Receiver(); | ||
private final LottoMachine lottoMachine = new LottoMachine(); | ||
|
||
public PurchaseAmount inputLottoPurchaseAmount() { | ||
printer.requestPurchaseAmount(); | ||
int lottoPurchaseAmount = receiver.receiveLottoPurchaseAmount(); | ||
|
||
return new PurchaseAmount(lottoPurchaseAmount); | ||
} | ||
|
||
public int inputLottoManualTicketNumber() { | ||
printer.requestLottoManualTicketNumber(); | ||
return receiver.receiverLottoManualTicketNumber(); | ||
} | ||
|
||
public LottoManualTickets inputLottoManualTickets(int lottoManualTicketNumber) { | ||
ArrayList<LottoManualTicket> lottoManualTicketDummy = new ArrayList<>(); | ||
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. (이펙티브 자바) 규칙64. 객체는 인터페이스를 사용해 참조하라 를 참고해보세요! |
||
printer.requestLottoManualTicket(); | ||
for (int lottoTicket = 0; lottoTicket < lottoManualTicketNumber; lottoTicket++) { | ||
LottoManualTicket lottoManualTicket = new LottoManualTicket(receiver.receiverLottoManualTicket()); | ||
lottoManualTicketDummy.add(lottoManualTicket); | ||
} | ||
return new LottoManualTickets(lottoManualTicketDummy); | ||
} | ||
|
||
public LottoAutomaticTickets informLottoAutomaticTickets(LottoManualTickets lottoManualTickets, NumberOfLottoTicket numberOfLottoTicket) { | ||
printer.printLottoManualTickets(lottoManualTickets); | ||
LottoAutomaticTickets lottoAutomaticTickets = lottoMachine.generateLottoAutomaticTicket(numberOfLottoTicket); | ||
printer.printLottoAutomaticTickets(lottoAutomaticTickets); | ||
return lottoAutomaticTickets; | ||
} | ||
Comment on lines
+37
to
+42
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 NumberOfLottoTicket informNumberOfLottoTicket(PurchaseAmount purchaseAmount, int lottoManualTicketNumber) { | ||
NumberOfLottoTicket numberOfLottoTicket = new NumberOfLottoTicket(purchaseAmount, lottoManualTicketNumber); | ||
printer.printNumberOfEachLottoTicket(numberOfLottoTicket); | ||
return numberOfLottoTicket; | ||
} | ||
Comment on lines
+37
to
+48
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. app의 전체적인 흐름을 담당하는 클래스이므로 메서드도 그 흐름 순서대로면 좋을 것 같아요~ |
||
|
||
public LastWeekWinningLotto inputLastWeekWinningLotto() { | ||
printer.requestLastWeekLottoWinningNumber(); | ||
List<Integer> LastWeekLottoWinningNumbers = receiver.receiveLastWeekLottoWinningNumbers(); | ||
return new LastWeekWinningLotto(LastWeekLottoWinningNumbers); | ||
} | ||
|
||
public LastWeekWinningBonusBall inputLastWeekWinningBonusBall() { | ||
printer.requestLottoBonusBallNumber(); | ||
int BonusBall = receiver.receiveLottoBonusBallNumber(); | ||
return new LastWeekWinningBonusBall(BonusBall); | ||
} | ||
|
||
public void informLottoStatistics( | ||
NumberOfLottoTicket numberOfLottoTicket, | ||
LottoManualTickets lottoManualTickets, | ||
LottoAutomaticTickets lottoAutomaticTickets, | ||
LastWeekWinningLotto lastWeekWinningLotto, | ||
LastWeekWinningBonusBall lastWeekWinningBonusBall) { | ||
Comment on lines
+62
to
+67
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<LottoMatchStatus> lottoAllTicketMatchStatuses = new ArrayList<>(); | ||
List<LottoMatchStatus> lottoManualTicketMatchStatuses = lottoMachine.lottoManualTicketsDiscriminator(lottoManualTickets, lastWeekWinningLotto, lastWeekWinningBonusBall); | ||
List<LottoMatchStatus> lottoAutomaticTicketMatchStatuses = lottoMachine.lottoAutomaticTicketsDiscriminator(lottoAutomaticTickets, lastWeekWinningLotto, lastWeekWinningBonusBall); | ||
lottoAllTicketMatchStatuses.addAll(lottoManualTicketMatchStatuses); | ||
lottoAllTicketMatchStatuses.addAll(lottoAutomaticTicketMatchStatuses); | ||
List<WinningStatus> lottoStatistics = lottoMachine.getStatistics(lottoAllTicketMatchStatuses); | ||
printer.printAllMatchedLottoResults(lottoMachine.getMappingLottoWithBonusBall()); | ||
Profit profit = lottoMachine.getProfitInformation(lottoStatistics, numberOfLottoTicket); | ||
printer.printLottoProfit(profit.getProfit()); | ||
printer.printIsLottoProfit(profit.isProfit()); | ||
Comment on lines
+69
to
+78
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.
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package lotto.domain; | ||
|
||
import lotto.domain.validation.LottoTicketOfNumberValidation; | ||
|
||
public class NumberOfLottoTicket { | ||
private final static int LOTTO_TICKET_PRICE = 1000; | ||
|
||
private final int totalNumberOfLottoTicket; | ||
private final int numberOfManualLottoTicket; | ||
private final int automaticLottoTicketOfNumber; | ||
|
||
public NumberOfLottoTicket(PurchaseAmount purchaseAmount, int purchaseManualLottoOfNumber) { | ||
LottoTicketOfNumberValidation lottoTicketOfNumberValidation = new LottoTicketOfNumberValidation(); | ||
this.totalNumberOfLottoTicket = calculateLottoTicketOfNumber(purchaseAmount.getPurchaseAmount()); | ||
this.numberOfManualLottoTicket = purchaseManualLottoOfNumber; | ||
this.automaticLottoTicketOfNumber = calculateAutomaticLottoTicketOfNumber(totalNumberOfLottoTicket, numberOfManualLottoTicket); | ||
lottoTicketOfNumberValidation.checkLottoTicketOfNumber(this.totalNumberOfLottoTicket); | ||
Comment on lines
+13
to
+17
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. 그 저번주에 코드진행으로 보여주신 것에서 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. 음 아뇨 값을 주입한 후에 validate를 진행하는 순서에 대해 얘기한 것이 아니라
에서
|
||
} | ||
|
||
private int calculateLottoTicketOfNumber(int purchaseAmount) { | ||
return purchaseAmount / LOTTO_TICKET_PRICE; | ||
} | ||
|
||
private int calculateAutomaticLottoTicketOfNumber(int lottoTicketOfTotalNumber, int manualLottoTicketOfNumber) { | ||
return lottoTicketOfTotalNumber - manualLottoTicketOfNumber; | ||
} | ||
|
||
public int getLottoTicketPrice() { | ||
return LOTTO_TICKET_PRICE; | ||
} | ||
Comment on lines
+28
to
+30
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. static이면 getter가 아니라 public으로 열어두고 사용해도 될 것 같아요 |
||
|
||
public int getNumberOfManualLottoTicket() { | ||
return numberOfManualLottoTicket; | ||
} | ||
|
||
public int getAutomaticLottoTicketOfNumber() { | ||
return automaticLottoTicketOfNumber; | ||
} | ||
|
||
public int getTotalNumberOfLottoTicket() { | ||
return totalNumberOfLottoTicket; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package lotto.domain; | ||
|
||
import java.util.List; | ||
|
||
public class Profit { | ||
private static final int PROFIT_THRESHOLD = 1; | ||
|
||
private final int sumLottoPrices; | ||
private final NumberOfLottoTicket numberOfLottoTicket; | ||
private final float calculatedProfit; | ||
|
||
public Profit(List<WinningStatus> lottoPrices, NumberOfLottoTicket numberOfLottoTicket) { | ||
this.sumLottoPrices = sumLottoPrices(lottoPrices); | ||
this.numberOfLottoTicket = numberOfLottoTicket; | ||
this.calculatedProfit = CalculatedProfit(); | ||
} | ||
|
||
private int sumLottoPrices(List<WinningStatus> lottoPrices) { | ||
return lottoPrices.stream().mapToInt(WinningStatus::getWinningMoney).sum(); | ||
} | ||
|
||
private float CalculatedProfit() { | ||
return (float) sumLottoPrices / (numberOfLottoTicket.getTotalNumberOfLottoTicket() * numberOfLottoTicket.getLottoTicketPrice()); | ||
} | ||
Comment on lines
+22
to
+24
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. 메서드명은 lower camel case! |
||
|
||
public boolean isProfit() { | ||
if (calculatedProfit < PROFIT_THRESHOLD) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
Comment on lines
+26
to
+31
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. 쿄쿄쿄쿄.... 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. 넵 :) calculatedProfit 이 PROFIT_THRESHOLD보다 작은게 아니다 보다는 |
||
|
||
public float getProfit() { | ||
return calculatedProfit; | ||
} | ||
} |
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.
기능목록을 구현하면 - [x]로 채워주는게 더 좋을것 같아요!