Skip to content
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
33a7d0d
docs: initial commit
jiwoo-kimm Jul 3, 2021
e9d2001
docs: 기능 구현 목록 작성
jiwoo-kimm Jul 3, 2021
05fbeba
feat:1000원 미만 입력 시 테스트메서드 작성
jiwoo-kimm Jul 3, 2021
538e6b8
feat: 1000의 배수 아닌 값 테스트메서드 작성
jiwoo-kimm Jul 3, 2021
96e6d63
feat: 금액 입력에 문자열 입력시 예외 처리 테스트 메서드 작성
jiwoo-kimm Jul 3, 2021
fd24a8d
refactor: perchasePrice, LottoController 생성
jiwoo-kimm Jul 3, 2021
862c243
refactor: 테스트 메서드 리팩토링
jiwoo-kimm Jul 3, 2021
27424d2
test: 공백 입력 처리 테스트 메서드 추가
jiwoo-kimm Jul 3, 2021
39be046
refactor: PurchasePrice -> PurchaseCount 변경
jiwoo-kimm Jul 3, 2021
c983156
feat: Lotto 클래스, 테스트클래스 생성
jiwoo-kimm Jul 3, 2021
f89c53e
feat: 로또 구매 개수만큼 생성해서 LottoSet에 저장
jiwoo-kimm Jul 3, 2021
27e69ac
feat: 당첨 번호 클래스 생성
jiwoo-kimm Jul 3, 2021
9680ee3
test: 숫자 개수 6개 확인 테스트 메서드 작성
chunghyeon-kimm Jul 5, 2021
8bd4e7f
test: 숫자가 아닌 값 입력 테스트 메서드 작성
chunghyeon-kimm Jul 5, 2021
3ee2d11
test: 로또 번호 입력범위 1~45 테스트 메서드 작성
chunghyeon-kimm Jul 5, 2021
0f0a9aa
feat: 당첨 조건 테스트 메서드 작성
chunghyeon-kimm Jul 5, 2021
6cb70d4
feat: 통계 클래스, 통계 테스트 클래스 추가
chunghyeon-kimm Jul 5, 2021
dcf4842
refactor: 패키지 구조 및 클래스 이름 변경
chunghyeon-kimm Jul 6, 2021
c512869
test: 보너스 번호 확인 테스트 작성
chunghyeon-kimm Jul 6, 2021
a6ef7de
feat: 로또 1 게임의 등수 계산
chunghyeon-kimm Jul 6, 2021
078bf69
feat: 로또 당첨 개수 구하기
chunghyeon-kimm Jul 7, 2021
4a83ad0
refactor: 테스트용 로또 클래스 생성
chunghyeon-kimm Jul 7, 2021
f8da3c5
feat: 총 상금액 계산 테스트 메서드 및 클래스 생성
chunghyeon-kimm Jul 7, 2021
a84a57e
feat: Controller, InputView, OutputView 1차 완성
chunghyeon-kimm Jul 7, 2021
016863a
refactor: DefaultNumbers 한 번만 생성하도록 수정
chunghyeon-kimm Jul 7, 2021
3b93395
refactor: Test 메서드 DisplayName 정리
chunghyeon-kimm Jul 7, 2021
ddff79a
refactor: DefaultNumbers 지네릭스 수정, 필요없는 클래스파일 삭제
chunghyeon-kimm Jul 7, 2021
e0d1880
refactor: View 로직과 가독성 개선
jiwoo-kimm Jul 7, 2021
f4d2c40
refactor: 리팩토링
jiwoo-kimm Jul 7, 2021
eaac136
refactor: 에러 메시지 출력 시 헤더 추가
jiwoo-kimm Jul 7, 2021
674ae96
refactor: Prize enum 하나로 합치기
jiwoo-kimm Jul 17, 2021
a0173ea
refactor: move Prize from constant package into domain package
jiwoo-kimm Jul 17, 2021
1bf5325
refactor: rename abbreviation calc into calculate
jiwoo-kimm Jul 17, 2021
ffed907
refactor: change parameter of WinningLotto constructor
jiwoo-kimm Jul 17, 2021
c48c8e1
refactor: abstract InputView and OutputView
jiwoo-kimm Jul 17, 2021
2c6da43
refactor: remove DTO postfix
jiwoo-kimm Jul 19, 2021
3e67178
refactor: remove unnecessary method wrapping
jiwoo-kimm Jul 19, 2021
8d185da
refactor: remove unncessary constants
jiwoo-kimm Jul 19, 2021
60c4c70
refactor: unwrap DefaultNumbers class into constant field of RandomLotto
jiwoo-kimm Jul 19, 2021
2119239
test: change Exception class type
jiwoo-kimm Jul 19, 2021
41d2147
refactor: rename non-negative integer validation
jiwoo-kimm Jul 19, 2021
36c204b
refactor: seperate exception cases of input for PurchaseCount
jiwoo-kimm Jul 19, 2021
1084404
refactor: merge RandomLottoSet into LottoSet
jiwoo-kimm Jul 19, 2021
2056c66
fix: prevent duplication of Lottos in LottoSet
jiwoo-kimm Jul 19, 2021
a44450b
refactor: validate input type at InputView not domain
jiwoo-kimm Jul 19, 2021
fb57be6
feat: validate duplication of LottoNumber in one Lotto
jiwoo-kimm Jul 19, 2021
a4809aa
refactor: rename fields of PrizeCount
jiwoo-kimm Jul 19, 2021
4357c37
refactor: remove unnecessary throws Exception
jiwoo-kimm Jul 19, 2021
d1e6740
test: move tests from WinningLottoTest to LottoTest and add validatio…
jiwoo-kimm Jul 19, 2021
0f0371e
refactor: add LottoMatcher to compare LottoSet and WinningLotto
jiwoo-kimm Jul 19, 2021
42ddc76
refactor: rename findPrize into getMatchPrize
jiwoo-kimm Jul 19, 2021
b65a98a
refactor: remove dependency between view and controller
jiwoo-kimm Jul 19, 2021
0f2c076
refactor: make Lotto unmodifiable
jiwoo-kimm Jul 19, 2021
eda9666
refactor: exception handling and print exception message
jiwoo-kimm Jul 19, 2021
ca56354
refactor: count match numbers with stream api
jiwoo-kimm Jul 19, 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
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
# java-lotto 게임
# java-Lotto 게임

# 구현 기능 목록
Copy link
Contributor

Choose a reason for hiding this comment

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

구현 기능 목록 작성 👍


- [x] 구입금액 입력받기
- [x] 1000원 미만 입력 시 처리
- [x] 1000의 배수 아닌 값 입력 시 처리
- [x] 숫자가 아닌 값 (문자열)
- [x] 정상값 처리
- [x] 공백 처리
- [x] 구매 개수 구하기
- [x] 랜덤 로또번호 구매 개수만큼 만들기
- [x] defaultNumberSet 1번만 생성되도록 변경
- [x] RandomLottoTest 상수 리팩토링
- [x] PurchaseCount의 1000 접근
- [x] 지난 주 당첨 번호 입력받기
- [x] WinningNumbers 멤버변수 ArrayList 클래스 확인
- [x] 숫자 개수 6개 확인
- [x] 숫자가 아닌 값 포함
- [x] 범위 (1~45) 확인
- [x] 공백 처리
- [x] 보너스 볼 입력받기
- [x] 당첨 통계
- [x] 당첨 조건을 enum 처리
- [x] 일치 개수 찾기
- [x] 5개 일치 시 보너스 볼 일치 여부 확인
- [x] 로또 당첨 개수 구하기
- [x] 당첨값의 합 구하기
- [x] 수익률 구하기
- [x] 결과 출력
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ repositories {
dependencies {
testImplementation('org.junit.jupiter:junit-jupiter:5.6.0')
testImplementation('org.assertj:assertj-core:3.15.0')

compileOnly 'org.projectlombok:lombok:1.18.20'
Copy link
Contributor

Choose a reason for hiding this comment

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

롬복 플러그인을 활용하셨네요!

Copy link
Author

Choose a reason for hiding this comment

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

넵! getter와 빌더 패턴을 사용하려고 활용했습니다

annotationProcessor 'org.projectlombok:lombok:1.18.20'

testCompileOnly 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'

}

test {
Expand Down
Empty file removed src/main/java/empty.txt
Empty file.
18 changes: 18 additions & 0 deletions src/main/java/lotto/LottoApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package lotto;

import lotto.controller.LottoController;
import lotto.view.ConsoleInputView;
import lotto.view.ConsoleOutputView;
import lotto.view.View;

public class LottoApplication {

public static void main(String[] args) {
View view = View.builder()
.inputView(new ConsoleInputView())
.outputView(new ConsoleOutputView())
.build();
LottoController lottoController = new LottoController(view);
lottoController.start();
}
}
33 changes: 33 additions & 0 deletions src/main/java/lotto/controller/LottoController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package lotto.controller;

import lotto.domain.dto.PurchasePriceInputDTO;
import lotto.domain.dto.PurchaseResultDTO;
import lotto.domain.dto.StatisticsResultDTO;
import lotto.domain.dto.WinningLottoInputDTO;
import lotto.service.LottoService;
import lotto.view.View;

public class LottoController {

private final View view;
private final LottoService lottoService;

public LottoController(View view) {
this.view = view;
this.lottoService = new LottoService();
}

public void start() throws IllegalArgumentException {
Copy link
Contributor

Choose a reason for hiding this comment

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

MVC 패턴을 이용해 문제를 풀려고 시도하셨네요!
다만 Model - View - Controller 역할 분리가 명확하게 되어있지 않아
현재 Controller가 View를 직접 활용하는 방식으로 코드 구현이 되어있는데요.
각자의 역할과 책임은 무엇이고, 이를 어떻게 독립적으로 분리해낼 수 있을 지, 또 왜 그러하여야 하는지 고민해보시면 좋겠습니다. 현재는 LottoController.start()LottoApplication의 main과 같은 역할로 보이네요.

Copy link
Author

Choose a reason for hiding this comment

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

Controller가 View를 직접 활용하는 방식이 왜 바람직하지 않은지 이해가 가지 않습니다. MVC 패턴에서 Controller는 View와 Model(Service) 사이의 연결 역할을 해주기 때문에 둘 다 참조하고 있어야 하지 않나요?
만약 이게 웹 어플리케이션이라면 Controller에서 request를 받아서 처리한 후 model이나 view를 만들어 리턴해줄텐데, 그 view를 만든다는 것과 view 객체의 메서드를 호출하는 것의 차이점이 뭔지 모르겠습니다.

또한, LottoApplication.main()LottoController.start()의 역할을 분리하기 위해 LottoControllerView에 의존하지 않도록 수정했습니다. 대신, LottoApplicationViewController를 가지고 그 흐름을 관리하는 것으로 수정했습니다. 하지만 이렇게 하면 Controller가 하는 일은 input 데이터를 받아서 output 데이터를 넘겨주는 일 뿐이잖아요? 그러면 mvc 패턴에서의 Controller 역할이 아니라, Service 도메인 역할이 되지 않나 싶습니다. 실제로 제가 수정한 코드에서 Controller가 하는 일은 Service의 메서드를 호출하는 일 뿐이니까요..!

try {
PurchasePriceInputDTO purchasePriceInputDTO = view.getPurchaseCost();
PurchaseResultDTO purchaseResultDTO = lottoService.purchase(purchasePriceInputDTO);
view.printLottoPurchaseResult(purchaseResultDTO);

WinningLottoInputDTO winningLottoInputDTO = view.getWinningLottoAndBonus();
StatisticsResultDTO statisticsResultDTO = lottoService.calculateResult(purchaseResultDTO, winningLottoInputDTO);
view.printLottoStatistics(statisticsResultDTO);
} catch (IllegalArgumentException e) {
view.printException(e.getMessage());
}
}
}
17 changes: 17 additions & 0 deletions src/main/java/lotto/domain/DefaultNumbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package lotto.domain;

import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.IntStream;

public class DefaultNumbers {
Copy link
Contributor

Choose a reason for hiding this comment

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

어떤 의도로 생성되었는지는 알겠습니다만, 과한 포장은 아닐까요?

Copy link
Author

Choose a reason for hiding this comment

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

넵! RandomLotto 클래스에서 로또 생성 할 때만 사용하기 때문에 RandomLotto 클래스의 상수로 unwrap 했습니다


@Getter
private static final List<Integer> defaultNumbers = Collections.unmodifiableList(new ArrayList<Integer>() {{
IntStream.range(LottoNumber.LOWER_BOUND, LottoNumber.UPPER_BOUND)
.forEach(this::add);
}});
}
18 changes: 18 additions & 0 deletions src/main/java/lotto/domain/Lotto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package lotto.domain;

import lombok.Getter;

import java.util.List;

public class Lotto {

public static final int PRICE = 1000;
public static final int LOTTO_NUMBER_SIZE = 6;

@Getter
protected List<LottoNumber> lottoNumbers;

public Lotto(List<LottoNumber> lottoNumbers) {
this.lottoNumbers = lottoNumbers;
}
}
56 changes: 56 additions & 0 deletions src/main/java/lotto/domain/LottoNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package lotto.domain;

import lombok.Getter;

import java.util.Objects;

import static lotto.exception.ExceptionMessage.NON_INTEGER_INPUT_FOR_LOTTO_NUMBER;
import static lotto.exception.ExceptionMessage.OUT_OF_BOUND_INPUT_FOR_LOTTO_NUMBER;
import static lotto.util.NumberValidateUtils.isInteger;

public class LottoNumber {

public static final int LOWER_BOUND = 1;
public static final int UPPER_BOUND = 45;

@Getter
private final int lottoNumber;

public LottoNumber(String input) throws IllegalArgumentException {
Copy link
Contributor

Choose a reason for hiding this comment

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

LottoNumber를 생성할 때 String으로 생성할 필요가 있을까요?
String type으로 받다보니 형변환까지 책임져야하는 상황이 되었네요.

Copy link
Author

Choose a reason for hiding this comment

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

LottoNumber의 생성자 파라미터로 int값을 받고, 값의 범위만 검증하도록 수정했습니다!

validate(input);

this.lottoNumber = Integer.parseInt(input);
}

private void validate(String input) throws IllegalArgumentException {
if (!isInteger(input)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isInteger 는 직독하면 정수인가? 는 판단문입니다.
다만 내용을 보니 0~9까지 숫자 즉 음이 아닌 정수인지를 정규표현식을 이용해 판단하고 있네요.
isNonNegativeInteger 정도로 더 정확하게 표현해보면 어떨까요?

Suggested change
if (!isInteger(input)) {
if (!isNonNegativeInteger(input)) {

Copy link
Author

Choose a reason for hiding this comment

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

넵! 더 명확하게 표현하도록 수정했습니다.

throw new IllegalArgumentException(NON_INTEGER_INPUT_FOR_LOTTO_NUMBER.getMessage());
}

int lottoNumber = Integer.parseInt(input);
if (isOutOfBound(lottoNumber)) {
throw new IllegalArgumentException(OUT_OF_BOUND_INPUT_FOR_LOTTO_NUMBER.getMessage());
}
}

private boolean isOutOfBound(int lottoNumber) {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

return lottoNumber < LOWER_BOUND || lottoNumber > UPPER_BOUND;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
LottoNumber that = (LottoNumber) o;
return lottoNumber == that.lottoNumber;
}

@Override
public int hashCode() {
return Objects.hash(lottoNumber);
}
}
16 changes: 16 additions & 0 deletions src/main/java/lotto/domain/LottoSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package lotto.domain;

import lombok.Getter;

import java.util.Collections;
import java.util.Set;

public class LottoSet {

@Getter
private final Set<Lotto> lottoSet;

public LottoSet(Set<Lotto> lottoSet) {
this.lottoSet = Collections.unmodifiableSet(lottoSet);
}
}
22 changes: 22 additions & 0 deletions src/main/java/lotto/domain/LottoStatistics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lotto.domain;

import lombok.Builder;
import lombok.Getter;

public class LottoStatistics {
Copy link
Contributor

Choose a reason for hiding this comment

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

통계를 담는 객체를 만든 것 아주 좋습니다 👍


@Getter
private final PrizeCount prizeCount;
private final PurchaseCount purchaseCount;

@Builder
public LottoStatistics(PrizeCount prizeCount, PurchaseCount purchaseCount) {
this.prizeCount = prizeCount;
this.purchaseCount = purchaseCount;
}

public double calculateProfitRate() {
return (double) Prize.sumOfPrizeMoney(prizeCount)
/ (purchaseCount.getPurchaseCount() * Lotto.PRICE);
}
}
55 changes: 55 additions & 0 deletions src/main/java/lotto/domain/Prize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package lotto.domain;

import lombok.Getter;

@Getter
public enum Prize {
Copy link
Contributor

Choose a reason for hiding this comment

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

Enum 활용 👏


FIRST(6, false, 2000000000),
SECOND(5, true, 30000000),
THIRD(5, false, 1500000),
FOURTH(4, false, 50000),
FIFTH(3, false, 5000),
LOSE(2, false, 0);

private final int matchNumbersCount;
private final boolean isBonus;
private final long prizeMoney;

Prize(int matchNumbersCount, boolean isBonus, long prizeMoney) {
this.matchNumbersCount = matchNumbersCount;
this.isBonus = isBonus;
this.prizeMoney = prizeMoney;
}

public static Prize findPrize(int matchNumbersCount, boolean isBonus) {
if (matchNumbersCount <= LOSE.matchNumbersCount) {
return LOSE;
}
if (matchNumbersCount == FIFTH.matchNumbersCount) {
return FIFTH;
}
if (matchNumbersCount == FOURTH.matchNumbersCount) {
return FOURTH;
}
if (matchNumbersCount == FIRST.matchNumbersCount) {
return FIRST;
}
return dissolveSecondOrThird(isBonus);
}

private static Prize dissolveSecondOrThird(boolean isBonus) {
if (isBonus) {
return Prize.SECOND;
}
return Prize.THIRD;
}

public static long sumOfPrizeMoney(PrizeCount prizeCount) {
return prizeCount.getCountFirst() * FIRST.prizeMoney
+ prizeCount.getCountSecond() * SECOND.prizeMoney
+ prizeCount.getCountThird() * THIRD.prizeMoney
+ prizeCount.getCountFourth() * FOURTH.prizeMoney
+ prizeCount.getCountFifth() * FIFTH.prizeMoney;
}
}
43 changes: 43 additions & 0 deletions src/main/java/lotto/domain/PrizeCount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lotto.domain;

import lombok.Builder;
import lombok.Getter;

@Getter
public class PrizeCount {

private int countFirst;
Copy link
Contributor

Choose a reason for hiding this comment

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

이 클래스의 이름이 PrizeCount이니
line 9 to 13 count 는 중복처럼 느껴지네요. 더 단순하게 네이밍해도 의미 전달에 무리 없어보입니다.

Copy link
Author

Choose a reason for hiding this comment

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

넵 count를 빼고 순위만 남겨서 수정했습니다!

private int countSecond;
private int countThird;
private int countFourth;
private int countFifth;

@Builder
public PrizeCount(LottoSet lottoset, WinningLotto winningLotto) {
for (Lotto lotto : lottoset.getLottoSet()) {
updateCounts(winningLotto.findPrizeCondition(lotto));
Copy link
Contributor

Choose a reason for hiding this comment

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

LottoApplication에서 가장 핵심적인 로직이 이 클래스의 객체의 생성자에 들어있습니다.
LottoService에서 해당 객체를 만들고 있으나 핵심 로직이 밖으로 드러나있지 않아
우승 번호를 계산할 것이라는 유추가 쉽지 않았습니다.
PrizeCount라는 객체를 한 눈에 봤을 때(at a glance) 전체 로또 셋을 들고와 우승 로또 번호와 비교 계산하는 역할을
하는 것이 자연스럽다고 볼 수 있을지 다시 고민해보면 좋겠습니다.

Copy link
Author

Choose a reason for hiding this comment

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

넵! LottoMatcher 도메인을 생성해서 그 안에서 비교 역할을 수행하게 하고, LottoService에서 이를 호출하도록 수정했습니다.

}
}

private void updateCounts(Prize prize) {
if (prize.equals(Prize.FIRST)) {
countFirst++;
return;
}
if (prize.equals(Prize.SECOND)) {
countSecond++;
return;
}
if (prize.equals(Prize.THIRD)) {
countThird++;
return;
}
if (prize.equals(Prize.FOURTH)) {
countFourth++;
return;
}
if (prize.equals(Prize.FIFTH)) {
countFifth++;
}
}
}
43 changes: 43 additions & 0 deletions src/main/java/lotto/domain/PurchaseCount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lotto.domain;

import lombok.Builder;
import lombok.Getter;

import static lotto.exception.ExceptionMessage.NON_INTEGER_INPUT_FOR_PURCHASE_MONEY;
import static lotto.exception.ExceptionMessage.NON_MULTIPLE_OF_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY;
import static lotto.util.NumberValidateUtils.isInteger;

public class PurchaseCount {

private static final int MINIMUM_INPUT = 1000;

@Getter
private final int purchaseCount;

@Builder
public PurchaseCount(String input) {
input = input.trim();
validate(input);

this.purchaseCount = Integer.parseInt(input) / Lotto.PRICE;
}

private void validate(String input) {
if (!isInteger(input)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

isInteger 는 직독하면 정수인가? 는 판단문입니다.
다만 내용을 보니 0~9까지 숫자 즉 음이 아닌 정수인지를 정규표현식을 이용해 판단하고 있네요.
isNonNegativeInteger 정도로 더 정확하게 표현해보면 어떨까요?

Suggested change
if (!isInteger(input)) {
if (!isNonNegativeInteger(input)) {

throw new IllegalArgumentException(NON_INTEGER_INPUT_FOR_PURCHASE_MONEY.getMessage());
}

int purchaseCount = Integer.parseInt(input);
if (notMatchesCondition(purchaseCount)) {
throw new IllegalArgumentException(NON_MULTIPLE_OF_LOTTO_PRICE_INPUT_FOR_PURCHASE_MONEY.getMessage());
}
}

private boolean notMatchesCondition(int input) {
Copy link
Contributor

Choose a reason for hiding this comment

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

notMatchesCondition 표현이 모호하고 두 가지 서로 다른 일을 하고 있습니다.

  1. 입력이 로또를 구매할 수 있는 최소 값(1000)미만인지 검증
  2. 정확히 티켓 가격의 배수인지 검증

1의 상황을 2의 부분집합으로 생각하여 구현하신 것으로 추측되는데,
사용자에게 실패에 대한 더 정확한 에러를 구분하여 노출하는 것이 좋지 않을까요?

Copy link
Author

Choose a reason for hiding this comment

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

넵 부분집합으로 생각했던 것인데, 분리하는 게 더 명확하네요! 두 예외 분리해서 처리하도록 수정했습니다

return input < MINIMUM_INPUT || notMultipleOfLottoPrice(input);
}

private boolean notMultipleOfLottoPrice(int input) {
return input % Lotto.PRICE != 0;
}
}
Loading