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

Oereo 과제제출합니다. #3

Open
wants to merge 31 commits into
base: oereo
Choose a base branch
from
Open

Oereo 과제제출합니다. #3

wants to merge 31 commits into from

Conversation

oereo
Copy link
Member

@oereo oereo commented Apr 2, 2021

과제가 정말 전보다 어려워진 느낌인것 같아요... 아마 제약조건이 붙어서 더 그런 것 같습니다!
아직 테스트케이스와 예외처리가 다 되지 않아서 정말 죄송합니다.. 이제 회사를 퇴사했기 때문에 하루종일 자바과제를 보면서 공부하고 고치도록 하겠습니다!
코드리뷰는 쌍욕만 아니면 다 괜찮으니 많이많이 달아주세요!

oereo added 22 commits April 1, 2021 16:17
Copy link

@Jummi10 Jummi10 left a comment

Choose a reason for hiding this comment

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

binary file들이 열 개 정도가 같이 올라와 있네요
제가 구현한 당첨자 통계를 결정하는 부분이 마음에 들지 않아 고민이었는데 세훈님 코드에는 Map<WinningStatus, Integer>으로 구현하여 깔끔하다고 느껴져서 좋았습니다. 노란 박스 뜨는 부분이 있던데 이 부분들과 변수, 메서드명, 필드과 메서드간 구분(띄어쓰기?)만 신경 써주시면 될 것 같습니다. 리뷰 단 부분 중에 이건 아니다라 느끼거나 이해 안 가는 부분 있으시면 댓글 달아주세요

수고하셨습니다~!

Comment on lines 13 to 14
private static final String PRINT_FINAL_MATCHED_LOTTO_RESULT_MESSAGE = "%s개 일치 (%s원)- %s개";
private static final String PRINT_LOTTO_PROFIT_MESSAGE = "총 수익률은 %f입니다.";
Copy link

Choose a reason for hiding this comment

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

오호 저는 "개 일치", "원", "개" 이런 식으로 다 나눠놨는데 이렇게 %s와 %f 로 하니까 너무 깔끔하고 좋네요!! 이 부분은 저도 참고해야겠네요!!

Copy link
Member Author

Choose a reason for hiding this comment

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

감사합니다!!!!!^^

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

Choose a reason for hiding this comment

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

필드와 메서드 사이를 한 칸씩 띄어주면 더 읽기 좋을 것 같아요~

Copy link
Member Author

Choose a reason for hiding this comment

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

앗앗 그러네요!!! 정렬을 한번씩 잘 했어야 했는데 못한 것 같아요 ㅠㅠㅠ

Comment on lines 33 to 34
return dividedLastWeekLottoWinningNumbers.stream().map(Integer::parseInt).collect(Collectors.toList());

Copy link

Choose a reason for hiding this comment

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

return dividedLastWeekLottoWinningNumbers.stream()
    .map(Integer::parseInt)
    .collect(Collectors.toList());

이렇게 줄바꿈 하는게 더 보기 좋을 것 같아요~

Copy link
Member Author

Choose a reason for hiding this comment

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

좋습니당!!!!

Comment on lines +4 to +6
private final static int LOTTO_PRICE = 1000;
private final int tickets;
private final int money;
Copy link

Choose a reason for hiding this comment

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

정적 필드와 인스턴스 필드를 한 줄 띄어서 구분해주면 좋을 것 같아요

Copy link
Member Author

Choose a reason for hiding this comment

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

넵넵!!!

Comment on lines +12 to +23
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;
}
Copy link

Choose a reason for hiding this comment

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

lottoNumberRange를 Application에서 for문을 도는 동안 매번 생성을 해주어야 할까요??

Copy link
Member Author

Choose a reason for hiding this comment

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

죄송해요 ㅠㅠ 저 이해를 못한 것 같아요!!! 1~45 까지의 로또에서 찍을 수 있는 번호들을 하나하나 리스트에서 담아주는 역할인데 매번 생성이 된다는 게 어떤건지 다시 설명해주실수 있으신가요??

Copy link

Choose a reason for hiding this comment

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

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);
        }
        // ~~
}

Application.makeLottos()에서 randomLottoNumberStrategy.getRandomLottoNumbers()를 로또 티켓 개수만큼 for문을 돌면, 로또 티켓 하나를 만들 때마다 또 for문을 돌면서 1부터 45까지의 번호인 lottoNumberRange를 생성하는 방식이잖아요! 그리고 이렇게 로또 티켓을 만들 때마다 매번 생성된 lottoNumberRange를 셔플시키고 6개씩 잘라서 반환해주면 로또 티켓 하나가 만들어지구요.

제 말은 RandomLottoStrategy가 생성될 때 1~45의 lottoNumberRange를 맨 처음 한 번만 필드로 만들어두고
ApplicationmakeLottos()에서 randomLottoNumberStrategy.getLottoNumbers()만 해도 되지 않을까 라는 말이었습니다..!

글로 쓰려니 전달이 어렵긴 하네요 😥 혹시 이해하기 어려우시다면 다시 물어봐주세요!!

Copy link
Member Author

Choose a reason for hiding this comment

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

아아아아아아아아 진짜 이해했습니다!!! 아아아 감사합니다!!!

Copy link

Choose a reason for hiding this comment

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

이렇게 설명은 썼지만 사실 세훈님이 원래 짜신대로 해도 무방할것 같습니다!! 그냥 코드 보다가 생각이 나서 말씀드린거였습니다!

Copy link
Member Author

Choose a reason for hiding this comment

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

아 근데 확실히 정미님 말씀이 맞는 것 같아요! 굳이 계속 생성할 필요가 없을것 같아요!!

import java.util.HashMap;
import java.util.Map;

public class EnumWinningStatus {
Copy link

Choose a reason for hiding this comment

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

클래스 이름에 Enum이 들어가네요??

Comment on lines +12 to +13
return this.lottoWinning;

Copy link

Choose a reason for hiding this comment

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

this.를 쓰지 않아도 충분히 표현이 잘 될 것 같고 13번 라인같이 불필요한 라인은 삭제하는게 깔끔할 것 같아요

Boolean lottoBonusBallNumber = lottoWinningBonusBallResult.getLottoWinningBonusBallResult().get(i);
getWinningLottoTicketPrices(lottoMatchedNumber, lottoBonusBallNumber);
}
printer.printAllMatchedLottoResult(getMappingLottoWithBonusBall());
Copy link

Choose a reason for hiding this comment

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

비즈니스 로직 사이에 뷰 로직이 들어갔네요!

Comment on lines +39 to +57
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;
}
Copy link

Choose a reason for hiding this comment

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

오호 이런 방식으로 if 분기를 구구절절 쓰지 않고 당첨 통계를 낼 수도 있군요 아주 깔끔하네요!!!👍
(parameter와 for문 줄바꿈만 바꿔주면 될 것 같습니다 ㅎㅎ)

Copy link

Choose a reason for hiding this comment

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

저도 이 방식으로 구현하다가 의문이 생겨서 댓글 답니다!

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);

이런 식으로 돼있는데요
혹시 lottoMatchedNumber = 3, isMatchedBonusBallCount = true인 경우에는 어떻게 하나요??
이 경우는 THREE_MATCH가 lottoPrices에 add가 안 되지 않나요??! 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

앗 이 부분 다시 한번 해볼게요 ㅠㅠ 제가 지금 다시 엎고 정미님이 리뷰해주신 것을 바탕으로 짜고 있어서요!!!! 빠르게 오늘 해보고 공유를 드릴게요!!

Copy link
Member Author

Choose a reason for hiding this comment

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

이번에 새롭게 구조를 다시 짜면서 이 부분을 봤는데 체크로직을 따로 두어야 할 것 같아요 ㅠㅠㅠㅠ

@Test
void 로또_객체를_생성한다(){
//given
List<Integer> numbers = List.of(6,7,8,9,10,11);
Copy link

Choose a reason for hiding this comment

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

Suggested change
List<Integer> numbers = List.of(6,7,8,9,10,11);
List<Integer> numbers = new ArrayList<>(Arrays.asList(6,7,8,9,10,11));

빨간 줄이 뜨네용

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.

2 participants