-
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
feat: 로또 1단계-자동미션 제출 #4
base: jjanggyu
Are you sure you want to change the base?
Conversation
src/main/java/LottoApplication.java
Outdated
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)); | ||
} |
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.
공백을 통해 좀 더 읽기 쉽게 배치해 보는 것은 어떨까요?
src/main/java/LottoApplication.java
Outdated
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)); |
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<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)); | |
List<Integer> LastWeekLottoWinningNumbers = receiver.receiveLastWeekLottoWinningNumbers(); | |
LastWeekWinningLotto lastWeekWinningLotto = new LastWeekWinningLotto(LastWeekLottoWinningNumbers); | |
printer.requestLottoBonusBallNumber(); | |
LastWeekWinningBonusBall lastWeekWinningBonusBall = new LastWeekWinningBonusBall(receiver.receiveLottoBonusBallNumber()); | |
List<WinningStatus> getLottoPrices = lottoMachine.Discriminator(lottos, lastWeekWinningLotto, lastWeekWinningBonusBall, numberOfLottoTicket); | |
Profit profit = new Profit(getLottoPrices); | |
printer.printLottoProfit(profit.getCalculatedProfit(numberOfLottoTicket)); |
일전에 리뷰받은 내용입니다!
자바의 유명한 규칙중엔 program to interfaces not implementations 라는 부분이 있습니다.
객체 지향 기초 이야기 3, 유연함(Flexibility)
위 글 참고해보시면 좋을것 같아요
} | ||
|
||
private Lottos makeLottos(NumberOfLottoTicket numberOfLottoTicket) { | ||
ArrayList<LottoTicket> lottoDummy = new ArrayList<>(); |
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.
ArrayList<LottoTicket> lottoDummy = new ArrayList<>(); | |
List<LottoTicket> lottoDummy = new ArrayList<>(); |
Interface!
private Map<WinningStatus, Integer> getMappingLottoWithBonusBall() { | ||
for (WinningStatus key: lottoPrices | ||
) { | ||
mappingLottoWithBonusBall.put(key, mappingLottoWithBonusBall.getOrDefault(key, 0)+1); | ||
} | ||
return mappingLottoWithBonusBall; | ||
} |
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.
private Map<WinningStatus, Integer> getMappingLottoWithBonusBall() { | |
for (WinningStatus key: lottoPrices | |
) { | |
mappingLottoWithBonusBall.put(key, mappingLottoWithBonusBall.getOrDefault(key, 0)+1); | |
} | |
return mappingLottoWithBonusBall; | |
} | |
private Map<WinningStatus, Integer> getMappingLottoWithBonusBall() { | |
for (WinningStatus key: lottoPrices) { | |
mappingLottoWithBonusBall.put(key, mappingLottoWithBonusBall.getOrDefault(key, 0)+1); | |
} | |
return mappingLottoWithBonusBall; | |
} |
컨벤션 오타가 있네요
ArrayList<Integer> lottoWinningResults = new ArrayList<>(); | ||
ArrayList<Boolean> lottoWinningBonusBallResults = new ArrayList<>(); | ||
|
||
public ArrayList<WinningStatus> Discriminator( |
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.
여기도 숨어있군요
private List<Boolean> getMatchLottoNumber(LottoTicket lotto, LastWeekWinningLotto lastWeekWinningLotto){ | ||
List<Integer> lottoList = lotto.getLotto(); | ||
List<Integer> lastWeekWinningLottos = lastWeekWinningLotto.getLotto(); | ||
ArrayList<Boolean> lottoMatchedResult = new ArrayList<>(); |
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.
Interface!
src/main/java/ui/Printer.java
Outdated
private static final String PRINT_LOTTO_PROFIT_MESSAGE = "총 수익률은 %f입니다."; | ||
public void requestPurchaseAmount() { | ||
System.out.println(REQUEST_PURCHASE_AMOUNT_MESSAGE); | ||
} | ||
public void requestLastWeekLottoWinningNumber() { | ||
System.out.println(REQUEST_LAST_WEEK_LOTTO_WINNING_NUMBER_MESSAGE); | ||
} | ||
public void requestLottoBonusBallNumber() { | ||
System.out.println(REQUEST_LOTTO_BONUS_BALL_NUMBER_MESSAGE); | ||
} | ||
public void printAllLotto(Lottos lottos){ | ||
for (LottoTicket lotto : lottos.getLottos()) { | ||
System.out.println(lotto.getLotto()); | ||
} | ||
} |
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.
상수와 메소드 사이, 그리고 메소드와 메소드 사이에 공백을 주어 정리하는 게 좋지 않을까요?
src/main/java/ui/Receiver.java
Outdated
private List<Integer> convertStringToInt(List<String> dividedLastWeekLottoWinningNumbers) { | ||
return dividedLastWeekLottoWinningNumbers.stream().map(Integer::parseInt).collect(Collectors.toList()); | ||
|
||
} |
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.
불필요한 공백이 들어가있네요 !
src/main/java/ui/Printer.java
Outdated
private static final String REQUEST_PURCHASE_AMOUNT_MESSAGE = "구입금액을 입력해 주세요."; | ||
private static final String REQUEST_LAST_WEEK_LOTTO_WINNING_NUMBER_MESSAGE = "지난 주 당첨 번호를 입력해 주세요."; | ||
private static final String REQUEST_LOTTO_BONUS_BALL_NUMBER_MESSAGE = "보너스 볼을 입력해주세요"; | ||
private static final String PRINT_FINAL_MATCHED_LOTTO_RESULT_MESSAGE = "%s개 일치 (%s원)- %s개"; | ||
private static final String PRINT_LOTTO_PROFIT_MESSAGE = "총 수익률은 %f입니다."; | ||
public void requestPurchaseAmount() { |
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.
스트링 자체에 포매팅을 해서 깔끔하게 정리하셨군요!!
정말 좋은 방법인 것 같아요!
public LottoTicket(List<Integer> numbers ) { | ||
checkLottoLength(numbers); | ||
this.numbers = 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.
불필요한 공백이 있네요
public List<Integer> getRandomLottoNumbers(){ | ||
List<Integer> lottoNumberRange = setLottoNumberRange(); | ||
return getLottoNumbers(lottoNumberRange); | ||
} | ||
|
||
private List<Integer> setLottoNumberRange(){ | ||
ArrayList<Integer> lottoNumberIndex = new ArrayList<>(); | ||
for (int lottoNumber = LOWER_BOUND; lottoNumber < UPPER_BOUND; lottoNumber++) { | ||
lottoNumberIndex.add(lottoNumber); | ||
} | ||
return lottoNumberIndex; | ||
} | ||
|
||
private List<Integer> getLottoNumbers(List<Integer> lottoNumberRange){ |
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.
public List<Integer> getRandomLottoNumbers(){ | |
List<Integer> lottoNumberRange = setLottoNumberRange(); | |
return getLottoNumbers(lottoNumberRange); | |
} | |
private List<Integer> setLottoNumberRange(){ | |
ArrayList<Integer> lottoNumberIndex = new ArrayList<>(); | |
for (int lottoNumber = LOWER_BOUND; lottoNumber < UPPER_BOUND; lottoNumber++) { | |
lottoNumberIndex.add(lottoNumber); | |
} | |
return lottoNumberIndex; | |
} | |
private List<Integer> getLottoNumbers(List<Integer> lottoNumberRange){ | |
public List<Integer> getRandomLottoNumbers() { | |
List<Integer> lottoNumberRange = setLottoNumberRange(); | |
return getLottoNumbers(lottoNumberRange); | |
} | |
private List<Integer> setLottoNumberRange() { | |
ArrayList<Integer> lottoNumberIndex = new ArrayList<>(); | |
for (int lottoNumber = LOWER_BOUND; lottoNumber < UPPER_BOUND; lottoNumber++) { | |
lottoNumberIndex.add(lottoNumber); | |
} | |
return lottoNumberIndex; | |
} | |
private List<Integer> getLottoNumbers(List<Integer> lottoNumberRange) { |
컨벤션 관련해서 오타가 있네요!
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class RandomLottoNumberStrategy { |
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.
혹시 전략패턴을 사용하신 것일까요?
전략패턴의 원칙은 바뀌는 부분을 찾아 바뀌지 않는 것으로부터 분리시켜 캡슐화하는 것이라고 정의하고 있습니다.
일전에 공유해주신 링크
어떤 목적을 위해서 전략 패턴을 사용하신 건가요?
src/main/java/domain/Profit.java
Outdated
} | ||
|
||
public float getCalculatedProfit(NumberOfLottoTicket numberOfLottoTicket) { | ||
return (float) totalLottoPrice / numberOfLottoTicket.getMoney(); |
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.
return (float) totalLottoPrice / numberOfLottoTicket.getMoney(); | |
return (float)totalLottoPrice / numberOfLottoTicket.getMoney(); |
컨벤션에 의하면 캐스팅괄호 뒤에 공백이 없어야 합니다!
8.6 좋은 예 참조
} | ||
|
||
private int getMatchLottoNumberCount(List<Boolean> lottoMatchedResult){ | ||
return (int) lottoMatchedResult.stream().filter(index-> (index)).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.
return (int) lottoMatchedResult.stream().filter(index-> (index)).count(); | |
return (int)lottoMatchedResult.stream().filter(index-> (index)).count(); |
public class EnumWinningStatus { | ||
private static final int NOT_MATCH_LOTTO = 0; | ||
private ArrayList<WinningStatus> lottoPrices = new ArrayList<>(); | ||
private Map<WinningStatus, Integer> mappingLottoWithBonusBall = new HashMap<>(); |
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.
HashMap을 통해서 관리하셨군요!
좋은 방법인 것 같아요.
){ | ||
for (LottoTicket lotto : lottos.getLottos()) | ||
{ | ||
List<Boolean> lottoMatchedResult = getMatchLottoNumber(lotto, lastWeekWinningLotto); |
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로 따로 관리하셨군요!
사실 저도 이번 미션 진행하면서 결과 값을 관리하는 것에 대해 고민을 많이 했는데 결국 추가적으로 관리하는 것은 이번 미션 목적에 비해 오버 엔지니어링이라는 생각에 결과값 리스트를 따로 관리하지 않았습니다.
이렇게 결과값 리스트 따로 관리하면 이후에 추가적인 로직으로 판단하는 데에 있어서 장점이 있을까요?
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.
미션 동안 고생 많으셨습니다 !
역시 다른 분들이 짠 코드를 보면서 많이 배워가는 것 같아요 :)
이번 주도 고생 많으셨습니다
// naming 바꾸기 | ||
private int setNumberOfLottoTickets(int money) { | ||
return money / LOTTO_PRICE; | ||
} |
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.
이번 미션에서는 setter의 사용을 제한하지 않았지만
setter를 사용하여 tickets를 저장하고 그 이후에 getter로 받아 사용하는 것이 그렇지 않을 때에 비해 어떤 장단점이 있을까요?
Lottos lottos, | ||
LastWeekWinningLotto lastWeekWinningLotto, | ||
LastWeekWinningBonusBall lastWeekWinningBonusBall, | ||
NumberOfLottoTicket numberOfLottoTicket | ||
){ |
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.
Discriminator라는 함수가 받는 인자가 너무 많은 것 같아요.
numberOfLottoTicket의 경우 lottos에 포함되어 있을 수 있지 않을까요?
리뷰하다가 발견했는데 아직 수동기능을 추가하신 게 아니었군요... 추가 하신 줄 알고 리뷰 남겼는데 제 실수네요 ㅠㅠ |
로또 1단계 미션 제출합니다!
처음에는 쉬워보였는데, 갈수록 요구조건을 맞추면서 잘 하려다 보니 많이 꼬였어요..
코드는 조금 더 고쳐보도록 하겠습니다!