Skip to content
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

Open
wants to merge 2 commits into
base: jjanggyu
Choose a base branch
from

Conversation

jjanggyu
Copy link

@jjanggyu jjanggyu commented Apr 2, 2021

로또 1단계 미션 제출합니다!

처음에는 쉬워보였는데, 갈수록 요구조건을 맞추면서 잘 하려다 보니 많이 꼬였어요..

코드는 조금 더 고쳐보도록 하겠습니다!

Comment on lines 22 to 35
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));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

공백을 통해 좀 더 읽기 쉽게 배치해 보는 것은 어떨까요?

Comment on lines 28 to 34
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ArrayList<LottoTicket> lottoDummy = new ArrayList<>();
List<LottoTicket> lottoDummy = new ArrayList<>();

Interface!

Comment on lines 51 to 57
private Map<WinningStatus, Integer> getMappingLottoWithBonusBall() {
for (WinningStatus key: lottoPrices
) {
mappingLottoWithBonusBall.put(key, mappingLottoWithBonusBall.getOrDefault(key, 0)+1);
}
return mappingLottoWithBonusBall;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}

컨벤션 오타가 있네요

Comment on lines +16 to +19
ArrayList<Integer> lottoWinningResults = new ArrayList<>();
ArrayList<Boolean> lottoWinningBonusBallResults = new ArrayList<>();

public ArrayList<WinningStatus> Discriminator(
Copy link
Member

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<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interface!

Comment on lines 14 to 28
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());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수와 메소드 사이, 그리고 메소드와 메소드 사이에 공백을 주어 정리하는 게 좋지 않을까요?

참고 7.3

Comment on lines 32 to 35
private List<Integer> convertStringToInt(List<String> dividedLastWeekLottoWinningNumbers) {
return dividedLastWeekLottoWinningNumbers.stream().map(Integer::parseInt).collect(Collectors.toList());

}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 공백이 들어가있네요 !

Comment on lines 10 to 15
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() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스트링 자체에 포매팅을 해서 깔끔하게 정리하셨군요!!
정말 좋은 방법인 것 같아요!

Comment on lines 10 to 13
public LottoTicket(List<Integer> numbers ) {
checkLottoLength(numbers);
this.numbers = numbers;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

불필요한 공백이 있네요

Comment on lines 13 to 26
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){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Copy link
Member

@songpang songpang Apr 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 전략패턴을 사용하신 것일까요?

전략패턴의 원칙은 바뀌는 부분을 찾아 바뀌지 않는 것으로부터 분리시켜 캡슐화하는 것이라고 정의하고 있습니다.
일전에 공유해주신 링크

어떤 목적을 위해서 전략 패턴을 사용하신 건가요?

}

public float getCalculatedProfit(NumberOfLottoTicket numberOfLottoTicket) {
return (float) totalLottoPrice / numberOfLottoTicket.getMoney();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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<>();
Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로또 매칭 결과값을 List로 따로 관리하셨군요!

사실 저도 이번 미션 진행하면서 결과 값을 관리하는 것에 대해 고민을 많이 했는데 결국 추가적으로 관리하는 것은 이번 미션 목적에 비해 오버 엔지니어링이라는 생각에 결과값 리스트를 따로 관리하지 않았습니다.

이렇게 결과값 리스트 따로 관리하면 이후에 추가적인 로직으로 판단하는 데에 있어서 장점이 있을까요?

Copy link
Member

@songpang songpang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

미션 동안 고생 많으셨습니다 !
역시 다른 분들이 짠 코드를 보면서 많이 배워가는 것 같아요 :)
이번 주도 고생 많으셨습니다

@songpang
Copy link
Member

이번 수동미션도 고생 많으셨습니다!
같은 미션을 어떤 관점으로 각자 풀이했는지 볼 수 있어서 정말 좋은 것 같습니다.

지난 주 미션 때 피드백 받은 부분 중 도움이 될 것 같은 부분 공유해드립니다.

미션 수행하느라 고생하셨습니다!
최대한 원시 타입과 문자열을 포장하는 요구사항이 있었는데 VO를 사용했을때와 사용하지 않았을때 어떤 차이가 있고, 사용할때 장점을 어떻게 하면 살릴 수 있는지 공부해보면 좋을 것 같습니다. 😄

참고1 빈약한 도메인 모델
참고2 VO란 무엇일까?

Comment on lines +13 to +16
// naming 바꾸기
private int setNumberOfLottoTickets(int money) {
return money / LOTTO_PRICE;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번 미션에서는 setter의 사용을 제한하지 않았지만
setter를 사용하여 tickets를 저장하고 그 이후에 getter로 받아 사용하는 것이 그렇지 않을 때에 비해 어떤 장단점이 있을까요?

Comment on lines +20 to +24
Lottos lottos,
LastWeekWinningLotto lastWeekWinningLotto,
LastWeekWinningBonusBall lastWeekWinningBonusBall,
NumberOfLottoTicket numberOfLottoTicket
){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discriminator라는 함수가 받는 인자가 너무 많은 것 같아요.
numberOfLottoTicket의 경우 lottos에 포함되어 있을 수 있지 않을까요?

@songpang
Copy link
Member

리뷰하다가 발견했는데 아직 수동기능을 추가하신 게 아니었군요... 추가 하신 줄 알고 리뷰 남겼는데 제 실수네요 ㅠㅠ
추가하신 이후 다시 리뷰드리겠습니다!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants