-
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 과제제출합니다. #3
base: oereo
Are you sure you want to change the base?
Changes from 22 commits
d9441fe
16b3952
44d3e1a
a6ef619
4a1c382
b6e6587
271acd7
c4bfc6e
76a2518
7c5412b
ab9d320
bdf3cfd
8190d21
6d45ba1
883d44a
114b929
2f01632
8573f20
be95b6a
2b89a23
9e8a76f
53ba8db
8fb68d5
0666ef4
121c28a
7db2cfb
b71e88a
758faba
0036133
d94f4d6
307ecf1
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,54 @@ | ||
package lotto; | ||
|
||
import lotto.domain.LottoMachine; | ||
import lotto.domain.Profit; | ||
import lotto.domain.WinningStatus; | ||
import lotto.domain.lastweekwinninglotto.LastWeekWinningBonusBall; | ||
import lotto.domain.lastweekwinninglotto.LastWeekWinningLotto; | ||
import lotto.domain.lottoticket.LottoTicket; | ||
import lotto.domain.lottoticket.Lottos; | ||
import lotto.domain.lottoticket.NumberOfLottoTicket; | ||
import lotto.domain.strategy.RandomLottoNumberStrategy; | ||
import lotto.ui.Printer; | ||
import lotto.ui.Receiver; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LottoApplication { | ||
private final Printer printer = new Printer(); | ||
private final Receiver receiver = new Receiver(); | ||
private static LottoMachine lottoMachine = new LottoMachine(); | ||
private final RandomLottoNumberStrategy randomLottoNumberStrategy = new RandomLottoNumberStrategy(); | ||
|
||
public void run() { | ||
printer.requestPurchaseAmount(); | ||
NumberOfLottoTicket numberOfLottoTicket = new NumberOfLottoTicket(receiver.receiveLottoTotalAmount()); | ||
Lottos lottos = makeLottos(numberOfLottoTicket); | ||
printer.printAllLotto(lottos); | ||
printer.requestLastWeekLottoWinningNumber(); | ||
List<Integer> LastWeekLottoWinningNumbers = receiver.receiveLastWeekLottoWinningNumbers(); | ||
LastWeekWinningLotto lastWeekWinningLotto = new LastWeekWinningLotto(LastWeekLottoWinningNumbers); | ||
printer.requestLottoBonusBallNumber(); | ||
LastWeekWinningBonusBall lastWeekWinningBonusBall = new LastWeekWinningBonusBall(receiver.receiveLottoBonusBallNumber()); | ||
ArrayList<WinningStatus> getLottoPrices = lottoMachine.Discriminator(lottos, lastWeekWinningLotto, lastWeekWinningBonusBall, numberOfLottoTicket); | ||
Profit profit = new Profit(getLottoPrices); | ||
printer.printLottoProfit(profit.getCalculatedProfit(numberOfLottoTicket)); | ||
} | ||
|
||
private Lottos makeLottos(NumberOfLottoTicket numberOfLottoTicket) { | ||
ArrayList<LottoTicket> lottoDummy = new ArrayList<>(); | ||
for (int i = 0; i < numberOfLottoTicket.getNumberOfLottoTicket(); i++) { | ||
LottoTicket lotto = new LottoTicket(randomLottoNumberStrategy.getRandomLottoNumbers()); | ||
lottoDummy.add(lotto); | ||
} | ||
Lottos lottos = new Lottos(lottoDummy); | ||
return lottos; | ||
} | ||
|
||
public static void main(String[] args) { | ||
LottoApplication app = new LottoApplication(); | ||
app.run(); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package lotto.domain; | ||
|
||
import lotto.domain.lottoticket.NumberOfLottoTicket; | ||
import lotto.domain.lottowinningresult.LottoWinningBonusBallResult; | ||
import lotto.domain.lottowinningresult.LottoWinningResult; | ||
import lotto.ui.Printer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class EnumWinningStatus { | ||
private static final int NOT_MATCH_LOTTO = 0; | ||
private ArrayList<WinningStatus> lottoPrices = new ArrayList<>(); | ||
private Map<WinningStatus, Integer> mappingLottoWithBonusBall = new HashMap<>(); | ||
private Printer printer = new Printer(); | ||
|
||
public ArrayList<WinningStatus> getLottoPrices(LottoFactory lottoFactory, NumberOfLottoTicket numberOfLottoTicket){ | ||
LottoWinningResult lottoWinningResults = lottoFactory.getLottoWinningResult(); | ||
LottoWinningBonusBallResult lottoWinningBonusBallResult = lottoFactory.getLottoWinningBonusBallResult(); | ||
|
||
for (int i = 0; i < numberOfLottoTicket.getNumberOfLottoTicket(); i++) { | ||
int lottoMatchedNumber = lottoWinningResults.getLottoWinningResult().get(i); | ||
Boolean lottoBonusBallNumber = lottoWinningBonusBallResult.getLottoWinningBonusBallResult().get(i); | ||
getWinningLottoTicketPrices(lottoMatchedNumber, lottoBonusBallNumber); | ||
} | ||
printer.printAllMatchedLottoResult(getMappingLottoWithBonusBall()); | ||
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 lottoPrices; | ||
} | ||
|
||
private void getWinningLottoTicketPrices(int lottoMatchedNumber, boolean lottoBonusBallNumber) { | ||
for(WinningStatus winningStatus: WinningStatus.values()){ | ||
int matchedWinningNumberCount = winningStatus.getMatchCount(); | ||
boolean isMatchedBonusBallCount = winningStatus.hasBonusBall(); | ||
makeWinningLottoTicket(lottoMatchedNumber, matchedWinningNumberCount, isMatchedBonusBallCount, lottoBonusBallNumber, winningStatus); | ||
} | ||
} | ||
|
||
private void makeWinningLottoTicket( | ||
int lottoMatchedNumber, | ||
int matchedWinningNumberCount, | ||
boolean isMatchedBonusBallCount, | ||
boolean lottoBonusBallNumber, | ||
WinningStatus winningStatus | ||
){ | ||
if((lottoMatchedNumber == matchedWinningNumberCount) && (isMatchedBonusBallCount == lottoBonusBallNumber)){ | ||
lottoPrices.add(winningStatus); | ||
} | ||
} | ||
|
||
private Map<WinningStatus, Integer> getMappingLottoWithBonusBall() { | ||
for (WinningStatus key: lottoPrices | ||
) { | ||
mappingLottoWithBonusBall.put(key, mappingLottoWithBonusBall.getOrDefault(key, 0)+1); | ||
} | ||
return mappingLottoWithBonusBall; | ||
} | ||
Comment on lines
+40
to
+58
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 분기를 구구절절 쓰지 않고 당첨 통계를 낼 수도 있군요 아주 깔끔하네요!!!👍 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. 저도 이 방식으로 구현하다가 의문이 생겨서 댓글 답니다! WinningStatus를 보면
이런 식으로 돼있는데요 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,23 @@ | ||
package lotto.domain; | ||
|
||
import lotto.domain.lottowinningresult.LottoWinningBonusBallResult; | ||
import lotto.domain.lottowinningresult.LottoWinningResult; | ||
|
||
public class LottoFactory { | ||
private LottoWinningResult lottoWinningResult; | ||
private LottoWinningBonusBallResult lottoWinningBonusBallResult; | ||
|
||
public LottoFactory(LottoWinningResult lottoWinningResults, LottoWinningBonusBallResult lottoWinningBonusBallResults){ | ||
this.lottoWinningResult = lottoWinningResults; | ||
this.lottoWinningBonusBallResult = lottoWinningBonusBallResults; | ||
} | ||
|
||
public LottoWinningResult getLottoWinningResult(){ | ||
return this.lottoWinningResult; | ||
} | ||
|
||
public LottoWinningBonusBallResult getLottoWinningBonusBallResult(){ | ||
return this.lottoWinningBonusBallResult; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package lotto.domain; | ||
|
||
import lotto.domain.lastweekwinninglotto.LastWeekWinningBonusBall; | ||
import lotto.domain.lastweekwinninglotto.LastWeekWinningLotto; | ||
import lotto.domain.lottoticket.LottoTicket; | ||
import lotto.domain.lottoticket.Lottos; | ||
import lotto.domain.lottoticket.NumberOfLottoTicket; | ||
import lotto.domain.lottowinningresult.LottoWinningBonusBallResult; | ||
import lotto.domain.lottowinningresult.LottoWinningResult; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class LottoMachine { | ||
EnumWinningStatus enumWinningStatus = new EnumWinningStatus(); | ||
ArrayList<Integer> lottoWinningResults = new ArrayList<>(); | ||
ArrayList<Boolean> lottoWinningBonusBallResults = new ArrayList<>(); | ||
Comment on lines
+14
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. 또한 LottoMachine 클래스는 전체적으로 구매한 로또 티켓들과 지난주 당첨 번호를 비교해서 결과를 만드는 클래스인 것 같아요
Discriminator()에서 전체 결과(여기서는 lottoFactory인가요)를 반환하는데에서 끝내면 기능 분리가 더 되지 않을까요?? |
||
|
||
public ArrayList<WinningStatus> Discriminator( | ||
Lottos lottos, | ||
LastWeekWinningLotto lastWeekWinningLotto, | ||
LastWeekWinningBonusBall lastWeekWinningBonusBall, | ||
NumberOfLottoTicket numberOfLottoTicket | ||
){ | ||
Comment on lines
+19
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. parameter들이 임의로 줄바꿈 처리되어있고 메서드명이 Discriminator여서 생성자인줄 알았습니다! 메서드명을 lower camel case와 동사를 사용하여 바꿔주세요! 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. Discriminator() 메서드의 가독성을 높이기 위해 이 메서드에서 사용되는 아래의 메서드들을 순서대로 정렬해주면 좋을 것 같아요~ |
||
for (LottoTicket lotto : lottos.getLottos()) | ||
{ | ||
List<Boolean> lottoMatchedResult = getMatchLottoNumber(lotto, lastWeekWinningLotto); | ||
Boolean lottoMatchedBonusBallResult = getMatchLottoBonusBallNumber(lotto, lastWeekWinningBonusBall); | ||
int matchLottoNumberCount = getMatchLottoNumberCount(lottoMatchedResult); | ||
lottoWinningResults.add(matchLottoNumberCount); | ||
lottoWinningBonusBallResults.add(lottoMatchedBonusBallResult); | ||
} | ||
LottoFactory lottoFactory = createLottoFactory(lottoWinningResults, lottoWinningBonusBallResults); | ||
return enumWinningStatus.getLottoPrices(lottoFactory, numberOfLottoTicket); | ||
} | ||
|
||
private LottoFactory createLottoFactory(ArrayList<Integer> lottoWinningResults, ArrayList<Boolean> lottoWinningBonusBallResults) { | ||
LottoWinningBonusBallResult lottoWinningBonusBallResult = new LottoWinningBonusBallResult(lottoWinningBonusBallResults); | ||
LottoWinningResult winningResult = new LottoWinningResult(lottoWinningResults); | ||
|
||
LottoFactory lottoFactory = new LottoFactory(winningResult, lottoWinningBonusBallResult); | ||
return lottoFactory; | ||
} | ||
Comment on lines
+33
to
+43
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. 클래스의 필드를 parameter로 받을 필요가 있을까요? |
||
|
||
private int getMatchLottoNumberCount(List<Boolean> lottoMatchedResult){ | ||
return (int) lottoMatchedResult.stream().filter(index-> (index)).count(); | ||
} | ||
|
||
private List<Boolean> getMatchLottoNumber(LottoTicket lotto, LastWeekWinningLotto lastWeekWinningLotto){ | ||
List<Integer> lottoList = lotto.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. 변수명에 자료형이 들어가지 않게 해주세요! 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> lastWeekWinningLottos = lastWeekWinningLotto.getLotto(); | ||
ArrayList<Boolean> lottoMatchedResult = new ArrayList<>(); | ||
|
||
for (int winningLottoNumber = 0; winningLottoNumber < lastWeekWinningLottos.size(); winningLottoNumber++) { | ||
Boolean isMatchLottoNumber = lottoList.contains(lastWeekWinningLottos.get(winningLottoNumber)); | ||
lottoMatchedResult.add(isMatchLottoNumber); | ||
} | ||
return lottoMatchedResult; | ||
} | ||
Comment on lines
+45
to
+59
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 Boolean getMatchLottoBonusBallNumber(LottoTicket lotto, LastWeekWinningBonusBall lastWeekWinningBonusBall) { | ||
List<Integer> lottoBonusBalls = lotto.getLotto(); | ||
int lastWeekWinningBonusBalls = lastWeekWinningBonusBall.getLastWeekWinningBonusBall(); | ||
Boolean isMatchLottoNumber = lottoBonusBalls.contains(lastWeekWinningBonusBalls); | ||
Comment on lines
+61
to
+64
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. 아 진짜 네이밍 정말 어려운것 같아요 ㅠㅠㅠㅠ 여기에 동의합니다!! |
||
return isMatchLottoNumber; | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package lotto.domain; | ||
|
||
import lotto.domain.lottoticket.NumberOfLottoTicket; | ||
|
||
import java.util.List; | ||
|
||
public class Profit { | ||
private static int totalLottoPrice; | ||
public Profit(List<WinningStatus> lottoPrices) { | ||
int sumLottoPrices = sumLottoPrices(lottoPrices); | ||
totalLottoPrice = sumLottoPrices; | ||
} | ||
|
||
private int sumLottoPrices(List<WinningStatus> lottoPrices){ | ||
return lottoPrices.stream().mapToInt(WinningStatus::getWinningMoney).sum(); | ||
} | ||
|
||
public float getCalculatedProfit(NumberOfLottoTicket numberOfLottoTicket) { | ||
return (float) totalLottoPrice / numberOfLottoTicket.getMoney(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package lotto.domain; | ||
|
||
|
||
public enum WinningStatus { | ||
SIX_MATCH(6, false, 2000000000), | ||
FIVE_MATCH_WITH_BONUS_BALL(5, true, 30000000), | ||
FIVE_MATCH(5, false, 1500000), | ||
FOUR_MATCH(4, false, 50000), | ||
THREE_MATCH(3, false, 5000); | ||
|
||
private final int matchCount; | ||
private final int winningMoney; | ||
private final boolean BonusBall; | ||
|
||
WinningStatus(int matchCount, boolean BonusBall, int winningMoney){ | ||
this.matchCount = matchCount; | ||
this.winningMoney = winningMoney; | ||
this.BonusBall = BonusBall; | ||
} | ||
|
||
public int getMatchCount() { | ||
return this.matchCount; | ||
} | ||
|
||
public boolean hasBonusBall() { | ||
return this.BonusBall; | ||
} | ||
|
||
public int getWinningMoney() { | ||
return this.winningMoney; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package lotto.domain.exception; | ||
|
||
public class NotValidLottoLengthException extends RuntimeException { | ||
private static final String MESSAGE = "번호는 6개를 입력해야 합니다."; | ||
|
||
public NotValidLottoLengthException() { | ||
super(MESSAGE); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package lotto.domain.lastweekwinninglotto; | ||
|
||
public class LastWeekWinningBonusBall { | ||
|
||
private final int bonusBall; | ||
public LastWeekWinningBonusBall(int bonusBall){ | ||
this.bonusBall = bonusBall; | ||
} | ||
|
||
public int getLastWeekWinningBonusBall(){ | ||
return this.bonusBall; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package lotto.domain.lastweekwinninglotto; | ||
|
||
import lotto.domain.lottoticket.Lotto; | ||
|
||
import java.util.List; | ||
|
||
public class LastWeekWinningLotto implements Lotto { | ||
private final List<Integer> winningLotto; | ||
|
||
public LastWeekWinningLotto(List<Integer> winningLotto){ | ||
this.winningLotto = winningLotto; | ||
} | ||
|
||
@Override | ||
public List<Integer> getLotto(){ | ||
return this.winningLotto; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package lotto.domain.lottoticket; | ||
|
||
import java.util.List; | ||
|
||
public interface Lotto { | ||
public List<Integer> getLotto(); | ||
} | ||
Comment on lines
+5
to
+7
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. 음 getter만 가지고 있는 인터페이스가 굳이 필요하나라는 생각이 드네요..! 그냥 Lotto를 구현한 클래스들에서 각자의 게터를 사용해도 될 것 같긴 한데 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. 맞아요 ㅠ 이게 사실 getter만 가지고 있는 인터페이스는 사실 의미가 없어요 ㅠ 원래의 목적은 LastWeekWinningLotto 와 유저가 산 LottoTicket이 결국에는 같은 특징을 가지고 있는 class 라고 생각을 했어요! 원래는 다른 class로 분리해서 사용했는데 validation 체크 로직을 각각 넣을 때 고민이 되더라고요!! 결국에 갯수를 6개로 제한하는 부분도 같고 로또 숫자 범위도 같다는 점에서 interface로 구현하는게 좋을 것 같다는 생각을 했어요! getter만 넣은 것은 일단 저의 큰 실수이긴 해요 ㅠㅠㅠ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package lotto.domain.lottoticket; | ||
|
||
import lotto.domain.exception.NotValidLottoLengthException; | ||
|
||
import java.util.List; | ||
|
||
public class LottoTicket implements Lotto{ | ||
private static final int LOTTO_NUMBER_COUNT = 6; | ||
private final List<Integer> numbers; | ||
|
||
public LottoTicket(List<Integer> numbers ) { | ||
checkLottoLength(numbers); | ||
this.numbers = numbers; | ||
} | ||
|
||
private void checkLottoLength(List<Integer> numbers){ | ||
if(numbers.size() !=LOTTO_NUMBER_COUNT){ | ||
throw new NotValidLottoLengthException(); | ||
} | ||
} | ||
@Override | ||
public List<Integer> getLotto(){ | ||
return this.numbers; | ||
} | ||
Comment on lines
+22
to
+25
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. getter의 이름과 필드의 이름을 동일하게 해주면 |
||
|
||
} |
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.
클래스 이름에 Enum이 들어가네요??