[로또] 표현록 미션 제출합니다.#1
Conversation
- 돈 입력 - 당첨 번호 입력 - 보너스 번호 입력 - 발행된 로또 번호 출력 - 당첨 통계 출력
- 돈이 1000원 단위인가 - 당첨 번호와 보너스 번호가 숫자인가 - 당첨 번호와 보너스 번호가 1~45 사이인가 - 당첨 번호가 중복없이 6개인가 - 보너스 번호가 당첨 번호와 중복 없이 1개인가
- LottoService : Controller 대신 간단한 데이터 가공 로직 구현 - Calculator : 로또 구매 장수와 수익률 계산
daeGULLL
left a comment
There was a problem hiding this comment.
몇몇 보완점이 보이지만 아주 잘 짜신 코드같습니다!! 리뷰하던 도중 깔끔한 서비스 코드를 보고 제가 코딩 중에 컨트롤러에 모델을 노출시켜 코드짠걸 뒤늦게 기억해낼수 있었습니다..ㅋㅋ 덕분에 후딱 수정하러 갑니다 마지막 주차 같이 힘내용~~
There was a problem hiding this comment.
개인적인 취향이긴 한데, messageConstant나 prizeConstant 전부 상품에 관련된 enum이니 이 둘을 한개의 enum으로 합치셔도 좋을 것 같습니다! 상품 관련 메세지는 enum내부 로직으로 생성하게 하셔도 될것 같아유
| public class LottoService { | ||
| private LottoData lottoData; | ||
|
|
||
| public void init(List<List<Integer>> l, List<Integer> n, int bn) { |
There was a problem hiding this comment.
가독성을 위해 파라미터명을 축약어보단 풀네임으로 쓰는게 더 좋을 것 같습니다!
| public static int checkMoney(String input) { | ||
| try { | ||
| double money = Integer.parseInt(input); | ||
| if (!isInteger(money/1000)) { throw new IllegalArgumentException(); } |
There was a problem hiding this comment.
여기 illegalArgumentException에 내용 적는 것을 까먹으신 것 같습니다!!
| } | ||
|
|
||
| public void printStats(int[] results, double profit) { | ||
| System.out.println("당첨 통계\n---"); |
There was a problem hiding this comment.
이런 게임 진행 메세지도 errorConstants처럼 따로 enum으로 빼셔도 좋을 것 같아요!
seulnan
left a comment
There was a problem hiding this comment.
너무 고생하셨습니다!
정말 말그대로 의존성관리에 신경을 쓰신게 보이는 코드라 저도 배운게 많았습니다:)
다만, 전체적으로 몇가지 제안하고싶은점은
- 단위테스트코드를 작성해보시는 건 어때용?저는 이번미션부터 TDD도입을 시도하고있어요..!어렵긴하지만..연습해보면 좋을것같아용
- 중복코드가 있어보여요! 한번 코드흐름을 깔끔하게 정리해보시고 안쓰는 코드는 삭제하는것도 도움될듯합니당
| printResult(); | ||
| } | ||
|
|
||
| private void initialize() { |
There was a problem hiding this comment.
혹시 outputView.newLine()이 너무 반복적으로 호출되는데 한번만 호출하는 방식으로 변경하거나 아니면 아예 출력순서를 담당하는 별도 메서드로 분리하는게 더 좋을 것 같아요!
| } | ||
|
|
||
| public void printStats(int[] results, double profit) { | ||
| System.out.println("당첨 통계\n---"); |
| for (int i = 0; i < results.length; i++) { | ||
| System.out.println(m[i].getMessage() + " - " + results[i] + "개"); | ||
| } | ||
| System.out.println("총 수익률은 " + String.format("%.1f", profit) + "%입니다."); |
| } | ||
|
|
||
| // TODO: 추가 기능 구현 | ||
| public List<Integer> getNumbers() { |
There was a problem hiding this comment.
LottoData.java에서도 똑같은 getNumbers가 있던데 LottoData만 service에서 사용하고있더라구요 여기에 있는 lotto의 중복코드를 삭제해도 되지않을까요??
| data.lottos.addAll(l.stream().map(Lotto::new).toList()); | ||
| data.numbers.addAll(n); | ||
| data.bonusNumber = bn; | ||
| data.numbers.add(data.bonusNumber); |
There was a problem hiding this comment.
numebrs에서 보너스번호와 당첨번호를 둘다 관리하는데 따로 관리하는게 명확한 데이터구조를 유지하고 확장성면에서 더 좋지 않을까요??
| public void matchNumber() { | ||
| List<Integer> intersectionList; | ||
| for (Lotto l : lottoData.getLottos()) { | ||
| intersectionList = l.getNumbers().stream().filter(n -> lottoData.getNumbers().contains(n)).toList(); | ||
| if (intersectionList.size() < 3) continue; | ||
| if (intersectionList.size() == 6 && !isContainBonus(intersectionList)) { | ||
| lottoData.addPrize(4); | ||
| continue; | ||
| } | ||
| lottoData.addPrize(intersectionList.size() - 3); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
| public void matchNumber() { | |
| List<Integer> intersectionList; | |
| for (Lotto l : lottoData.getLottos()) { | |
| intersectionList = l.getNumbers().stream().filter(n -> lottoData.getNumbers().contains(n)).toList(); | |
| if (intersectionList.size() < 3) continue; | |
| if (intersectionList.size() == 6 && !isContainBonus(intersectionList)) { | |
| lottoData.addPrize(4); | |
| continue; | |
| } | |
| lottoData.addPrize(intersectionList.size() - 3); | |
| } | |
| } | |
| public void matchNumber() { | |
| for (Lotto lotto : lottoData.getLottos()) { | |
| int matchCount = (int) lotto.getNumbers().stream() | |
| .filter(lottoData.getNumbers()::contains) | |
| .count(); | |
| if (matchCount >= 3) { | |
| int index = (matchCount == 6 && !isContainBonus(lotto.getNumbers())) ? 4 : matchCount - 3; | |
| lottoData.addPrize(index); | |
| } | |
| } | |
| } | |
여기 if문에서 .size()를 계속 중복호출하고있는것같아요 matchCount라는 변수에 담아서 사용하는것은 어떨까요??
|
|
||
| private final int value; | ||
|
|
||
| PrizeConstants(String value) { |
There was a problem hiding this comment.
첨부터 int로 선언하면 string value를 굳이 int로 변환하지않아도 되지않을까요??
🎰 로또 💸
신경써서 구현한 부분
피드백이 필요한 부분
고려한 예외