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
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d9441fe
docs(guide): 구현할 기능 목록과 예외 처리 목록 작성
oereo Apr 1, 2021
16b3952
feat: Lotto 객체 생성 및 테스트 케이스 작성, NotValidLottoLengthException 예외처리 추가
oereo Apr 1, 2021
44d3e1a
feat: 로또 넘버를 랜덤으로 생성해주는 RandomLottoNumberStrategy class 추가
oereo Apr 1, 2021
a6ef619
feat: RandomLottoNumberStrategy class 생성 및 shuffle을 통해서 중복되지 않는 랜덤숫자 …
oereo Apr 1, 2021
4a1c382
feat: add business logic
oereo Apr 1, 2021
b6e6587
delete: LottoFactory class 에서 사용하지 않는 class 삭제
oereo Apr 1, 2021
271acd7
refactor: Discriminator method에 numberOfLottoTicket 파라미터를 받을 수 있도록 수정
oereo Apr 1, 2021
c4bfc6e
feat: LottoFactory class 에서 LottoWinningResult 객체와 LottoWinningBonusB…
oereo Apr 1, 2021
76a2518
refactor: numberOfLottoTicket 이 로또ㅗㄹ 맞았는지에 대한 여부를 체크하기 위해 numberOfLo…
oereo Apr 1, 2021
7c5412b
feat: 맞춘 로또 티켓의 당첨금액을 리스트로 만드는 WinningLottoTicketPrices method 구현
oereo Apr 1, 2021
ab9d320
feat: 메시지를 출력하는 Printer class 생성
oereo Apr 1, 2021
bdf3cfd
feat: receiveLastWeekLottoWinningNumbers method 구현
oereo Apr 1, 2021
8190d21
feat: receiverLottoBonusBallNumber method 구현
oereo Apr 1, 2021
6d45ba1
feat: requestLottoBonusBallNumber method 와 printAllLotto method 구현
oereo Apr 1, 2021
883d44a
refactor: LottoMachine class 에서 convention 에 위배되는 사항들 수정
oereo Apr 1, 2021
114b929
refactor: run() method 구조 변경 및 makeLottos method 분리
oereo Apr 1, 2021
2f01632
feat: 로또 당첨을 통해 계산되는 이익률을 담당하는 Profile class 추가
oereo Apr 2, 2021
8573f20
feat: NumberOfLottoTicket class 안에 getMoney method 구현
oereo Apr 2, 2021
be95b6a
refactor: 사용하지 않는 모듈 삭제와 구조 변경
oereo Apr 2, 2021
2b89a23
feat: printAllMatchedLottoResult method 구현 및 printLottoProfit method 구현
oereo Apr 2, 2021
9e8a76f
refactor: 기존 Integer type 에서 WinningStatus type 으로 수정하여 map 구성
oereo Apr 2, 2021
53ba8db
docs(guide): class 구조와 method 대한 부분 수정
oereo Apr 2, 2021
8fb68d5
delete: binary 파일 삭제
oereo Apr 3, 2021
0666ef4
refactor: Printer class 안 재정렬
oereo Apr 3, 2021
121c28a
refactor: Receiver class 안 재정렬
oereo Apr 3, 2021
7db2cfb
feat: profit이 1보다 큰지 작은지 여부 파악 method 구현
oereo Apr 3, 2021
b71e88a
docs(refactor): 불필요한 리스트 제거
oereo Apr 3, 2021
758faba
refactor: 로또 최종 결과값 출력 method 수정 및 Printer class 수정
oereo Apr 3, 2021
0036133
feat: out file 제외
oereo Apr 3, 2021
d94f4d6
refactor: profit 객체 관련 로직 수정
oereo Apr 3, 2021
307ecf1
refactor: 코드리뷰를 통한 구조 수정
oereo Apr 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# 🚀 로또 1단계 - 자동

## 구현할 기능 목록
- [ ] 구입금액을 입력받을 수 있다.
- [ ] 구입금액에 따라 몇개의 로또를 구입했는지 알려준다.
- [ ] 로또의 갯수에 맞추어 1~45까지 6개의 랜덤 숫자 리스트를 만든다.
- [ ] 지난 주 담청 번호를 입력받을 수 있다.
- [ ] 보너스 볼을 입력받을 수 있다.
- [ ] 담청 통계를 출력한다.
- [ ] 로또와 담청 번호를 비교하여 각 몇개의 숫자가 맞았는지 출력한다.
- [ ] 총 수익률을 소숫점 2번째 자리까지 출력한다.

## 예외 처리 목록
- [ ] 구입금액이 0원일 경우 로또 한장의 가격이 1000원이라는 메시지와 함께 `구입금액을 입력해주세요` 라는 메시지를 출력한다.
- [ ] 로또 넘버의 범위는 1~45까지로 제한하며 이외의 숫자는 허용하지 않는다.
- [ ] 담청번호와 보너스 번호가 같은 상황은 허용하지 않는다.
- [ ] 저번주 담청번호들이 2개 이상 중복되는 것을 허용하지 않는다.

## 기능 요구사항
- 로또 구입 금액을 입력하면 구입 금액에 해당하는 로또를 발급해야 한다.
- 로또 1장의 가격은 1000원이다.
Expand Down Expand Up @@ -27,7 +43,13 @@
1, 2, 3, 4, 5, 6
보너스 볼을 입력해 주세요.
7

class 3개
lastweek ()
bonusnumbe()
lastweekWinnerLotto
.method(lastweek, bonus)
if(5개 맞을 시에)

당첨 통계
---------
3개 일치 (5000원)- 1개
Expand All @@ -53,4 +75,4 @@
## 힌트
- 로또 자동 생성은 Collections.shuffle() 메소드 활용한다.
- Collections.sort() 메소드를 활용해 정렬 가능하다.
- ArrayList의 contains() 메소드를 활용하면 어떤 값이 존재하는지 유무를 판단할 수 있다.
- ArrayList의 contains() 메소드를 활용하면 어떤 값이 존재하는지 유무를 판단할 수 있다.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file removed src/main/java/empty.txt
Empty file.
54 changes: 54 additions & 0 deletions src/main/java/lotto/LottoApplication.java
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();
}
}

59 changes: 59 additions & 0 deletions src/main/java/lotto/domain/EnumWinningStatus.java
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 {
Copy link

Choose a reason for hiding this comment

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

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

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

Choose a reason for hiding this comment

The 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
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.

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


}
23 changes: 23 additions & 0 deletions src/main/java/lotto/domain/LottoFactory.java
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;
}

}
68 changes: 68 additions & 0 deletions src/main/java/lotto/domain/LottoMachine.java
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
Copy link

Choose a reason for hiding this comment

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

이 클래스에서 해당 인스턴스 필드들을 굳이 들고 있을 필요가 없어보입니다! 아래 이미지는 자바 레이싱카 미션에서 경준님이 공유해주셨는데 도움이 될 것 같아 첨부합니다 :)

image

Copy link

Choose a reason for hiding this comment

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

또한 LottoMachine 클래스는 전체적으로 구매한 로또 티켓들과 지난주 당첨 번호를 비교해서 결과를 만드는 클래스인 것 같아요

LottoFactory lottoFactory = createLottoFactory(lottoWinningResults, lottoWinningBonusBallResults);
return enumWinningStatus.getLottoPrices(lottoFactory, numberOfLottoTicket);

Discriminator()에서 전체 결과(여기서는 lottoFactory인가요)를 반환하는데에서 끝내면 기능 분리가 더 되지 않을까요??


public ArrayList<WinningStatus> Discriminator(
Lottos lottos,
LastWeekWinningLotto lastWeekWinningLotto,
LastWeekWinningBonusBall lastWeekWinningBonusBall,
NumberOfLottoTicket numberOfLottoTicket
){
Comment on lines +19 to +24
Copy link

Choose a reason for hiding this comment

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

parameter들이 임의로 줄바꿈 처리되어있고 메서드명이 Discriminator여서 생성자인줄 알았습니다! 메서드명을 lower camel case와 동사를 사용하여 바꿔주세요!

Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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();
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.

앗 ㅠㅠㅠㅠㅠ 네엡!!

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
Copy link

Choose a reason for hiding this comment

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

List<Boolean>을 반환해서 count를 세지 않고
contains가 된 횟수를 세서 int matchLottoNumberCount를 바로 반환할 수도 있을 것 같아요

Copy link
Member Author

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

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

lottoBonusBalls라는 이름을 보면 로또 티켓 하나가 보너스 볼이라는 숫자들을 가지고 있어야 할 것 같아요..

Copy link
Member Author

Choose a reason for hiding this comment

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

아 진짜 네이밍 정말 어려운것 같아요 ㅠㅠㅠㅠ 여기에 동의합니다!!

return isMatchLottoNumber;

}
}
21 changes: 21 additions & 0 deletions src/main/java/lotto/domain/Profit.java
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();
}
}
32 changes: 32 additions & 0 deletions src/main/java/lotto/domain/WinningStatus.java
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;
}
}
7 changes: 7 additions & 0 deletions src/main/java/lotto/domain/lottoticket/Lotto.java
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
Copy link

Choose a reason for hiding this comment

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

음 getter만 가지고 있는 인터페이스가 굳이 필요하나라는 생각이 드네요..! 그냥 Lotto를 구현한 클래스들에서 각자의 게터를 사용해도 될 것 같긴 한데 LastWeekWinningLottoLottoTicket이 비슷한 구조라는걸 나타내고 싶었던 의도인가요?

Copy link

Choose a reason for hiding this comment

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

Lotto 인터페이스를 살리고 싶다면 LastWeekWinningLotto의 개수도 6개여야하는데 Lotto 인터페이스를 abstract class 로 만들고 lotto length 를 check하는 로직을 공통으로 가지게 하는 것도 좋을 것 같아요 (이렇게 바꿔라는 아니고 그저 작은 의견입니다!)

Copy link
Member Author

Choose a reason for hiding this comment

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

맞아요 ㅠ 이게 사실 getter만 가지고 있는 인터페이스는 사실 의미가 없어요 ㅠ 원래의 목적은 LastWeekWinningLotto 와 유저가 산 LottoTicket이 결국에는 같은 특징을 가지고 있는 class 라고 생각을 했어요! 원래는 다른 class로 분리해서 사용했는데 validation 체크 로직을 각각 넣을 때 고민이 되더라고요!! 결국에 갯수를 6개로 제한하는 부분도 같고 로또 숫자 범위도 같다는 점에서 interface로 구현하는게 좋을 것 같다는 생각을 했어요! getter만 넣은 것은 일단 저의 큰 실수이긴 해요 ㅠㅠㅠ

26 changes: 26 additions & 0 deletions src/main/java/lotto/domain/lottoticket/LottoTicket.java
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
Copy link

Choose a reason for hiding this comment

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

getter의 이름과 필드의 이름을 동일하게 해주면 LottoTicket.getLotto() 보다 LottoTicket.getNumbers()가 더 의미가 정확해지고 메서드가 불리는 곳에서도 무슨 필드를 가져오는건지 헷갈리지 않을 것 같아요


}
Loading