-
Notifications
You must be signed in to change notification settings - Fork 122
[완두콩] 박주희 로또 미션 제출합니다 (1단계-4단계) #202
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
base: juhee0223
Are you sure you want to change the base?
Changes from 48 commits
12bedd7
601eb71
7d6e0c4
5bc1190
809289d
8a8fe2b
ba04b5d
2746792
bc789de
7298be7
ef22e91
c7b2252
07dfdff
abc19c4
de6a9bd
7aa9f9f
af23a2a
b59ec31
be8d61a
c86563a
922eb10
047f5fd
d569fd4
4095f4f
1dd8f86
11d0438
f8fdd96
e9513b6
2096b3c
7aa2362
793fefe
0bb6ac2
cd808b3
8a34a79
aa09b3f
6322c11
5b11507
daddef8
f8053a0
576427f
1dd8354
0db8025
d574ef3
82d8d69
d6361ea
3b6dd3f
954fb8b
b6546b2
8616304
423146b
0aca2e0
d19037c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # 로또 (Lotto) 미션 | ||
|
|
||
| ## 프로젝트 소개 | ||
|
|
||
| 이 프로그램은 주어진 기능 및 프로그래밍 요구사항을 만족하는 콘솔 기반의 로또 게임을 구현하는 것을 목표로 합니다. | ||
| 사용자는 로또를 수동 또는 자동으로 구매하고, 당첨 번호와 비교하여 당첨금 관련 결과를 확인할 수 있습니다. | ||
|
|
||
| --- | ||
|
|
||
| ## 기능 요구사항 | ||
|
|
||
| - 로또 구입 금액을 입력하면 구입 금액에 해당하는 로또 티켓을 발급합니다. | ||
| - 사용자가 수동으로 로또 번호를 입력할 수 있어야 합니다. | ||
| - 수동으로 구매할 로또 수를 입력받고, 그 수만큼 로또 번호를 입력받습니다. | ||
| - 수동 구매 후 남은 금액만큼 자동으로 로또를 발급합니다. | ||
| - 지난 주 당첨 번호 6개와 보너스 볼 1개를 입력받습니다. | ||
| - 로또 번호와 당첨 번호를 비교하여 당첨 결과를 결정합니다. | ||
| - 최종적으로 당첨 통계와 수익률을 계산하여 출력합니다. | ||
| - 수익률이 1 미만일 경우 손해임을 명시합니다. | ||
| - 수익률이 1 이상일 경우 이득임을 명시합니다. (임의 설정) | ||
|
|
||
| --- | ||
|
|
||
| ## 비즈니스 규칙 | ||
|
|
||
| - **로또 구매 규칙** | ||
| - 로또 1장의 가격은 1,000원입니다. | ||
| - 구매 금액은 1,000원 단위로 입력해야 합니다. | ||
| - **로또 번호 규칙** | ||
| - 로또 번호는 1부터 45 사이의 숫자입니다. | ||
| - 로또 한 장은 중복되지 않는 6개의 숫자로 구성됩니다. | ||
| - 수동으로 로또를 구매할 때 6개의 번호를 입력하지 않으면 오류가 발생합니다. | ||
| - **당첨 조건 및 상금** | ||
| - 1등: 6개 번호 일치 (2,000,000,000원) | ||
| - 2등: 5개 번호 일치 + 보너스 볼 일치 (30,000,000원) | ||
| - 3등: 5개 번호 일치 (1,500,000원) | ||
| - 4등: 4개 번호 일치 (50,000원) | ||
| - 5등: 3개 번호 일치 (5,000원) | ||
|
|
||
| --- | ||
|
|
||
| ## 프로그래밍 요구사항 | ||
|
|
||
| - **코드 컨벤션**: 자바 코드 컨벤션을 지키면서 프로그래밍합니다. | ||
| - **들여쓰기**: `indent`(인덴트, 들여쓰기) depth를 1까지만 허용합니다. (메서드 분리로 해결) | ||
| - **`else` 사용 금지**: `else` 예약어, `switch/case`, 3항 연산자를 사용하지 않습니다. (if문에서 값 반환으로 해결) | ||
| - **메서드 분리**: | ||
| - 함수(또는 메서드)의 길이는 10라인을 넘어가지 않도록 구현합니다. | ||
| - 함수(또는 메서드)가 한 가지 일만 하도록 최대한 작게 만듭니다. | ||
| - **자료구조**: 배열이 아닌 컬렉션을 사용합니다. | ||
| - **축약 금지**: 변수명, 클래스명, 메서드명 등에 축약을 사용하지 않습니다. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import static view.InputView.lottoScanner; | ||
|
|
||
| import domain.LottoChecker; | ||
| import domain.LottoResult; | ||
| import domain.LottoStatistics; | ||
| import domain.LottoTicketCount; | ||
| import domain.LottoTickets; | ||
| import domain.LottoWinningType; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import view.InputView; | ||
| import view.OutputView; | ||
|
|
||
| public class Application { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
사용자 입장으로 볼 때 어떠신가요? 6개로 입력을 잘 했고, 콤마로 구분 잘 한 것 같아요. 1000원 미만으로 구매하면 안내 문구를 띄워주면 좋을 것 같아요 자동차 경주 미션의 핵심 키워드는 예외 처리였던 것 같아요. 아무리 코드를 잘 작성했더라도, 실제 사용하는 입장에서 불편함이 생긴다면 그 코드가 충분한 가치를 제공한다고 보기 어려울 수 있어요.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. 생각해보니 아예 1000원 단위로 구매하도록 수정해볼까 합니다!2. [1,2,3,4,5,6] 과 같은 형식일 경우도 처리 가능하도록 구현해보는 방향을 떠올려봤습니다
이는 쉼표 뒤에 0개 이상의 공백(\s*)이 올 때 이를 기준으로 문자열을 쪼개주는 방식으로, 지금 간단하게 적용하기에 좋은 방법같아서 이렇게 해보았습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 기존은 수동 구매 개수를 사용자로부터 입력받을 때, 해당 입력값이 총 구매 금액으로 구매 가능한 로또의 총 개수(totalCount)를 초과할 수 있는지에 대한 검증이 없었습니다. 그래서 수동 구매 개수를 입력받는 시점에 총 구매 가능 개수를 초과하는지 검증하는 로직을 추가했습니다. |
||
|
|
||
| public static void main(String[] args) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| LottoTicketCount lottoTicketCount = new LottoTicketCount(); | ||
| int totalCount = lottoTicketCount.convertLottoPriceToTicketCount(InputView.inputLottoTotalPrice()); | ||
|
|
||
| int manualCount = InputView.inputUserSelectedLottoCount(); | ||
| List<String> userSelectedNumbersInput = InputView.inputUserSelectedLottoNumbers(manualCount); | ||
|
|
||
| int autoCount = totalCount - manualCount; | ||
|
|
||
| OutputView.printLottoCount(manualCount, autoCount); | ||
|
|
||
| LottoTickets lottoTickets = new LottoTickets(); | ||
| lottoTickets.addUserSelectedLottos(userSelectedNumbersInput); | ||
| lottoTickets.addAutoLottos(autoCount); | ||
|
|
||
| OutputView.printLottoNumbers(lottoTickets); | ||
|
|
||
| String[] winningNumbers = InputView.inputWinningLottoNumbers().split(",\\s*"); | ||
| String bonusNumber = InputView.inputBonusBallNumber(); | ||
|
|
||
| LottoChecker lottoChecker = new LottoChecker(winningNumbers, lottoTickets, bonusNumber); | ||
| ArrayList<LottoWinningType> checkedTickets = lottoChecker.checkAllTickets(); | ||
|
|
||
| LottoStatistics lottoStatistics = new LottoStatistics(); | ||
| Map<LottoWinningType, Integer> countedMatches = lottoStatistics.countMatches(checkedTickets); | ||
|
|
||
| OutputView.printMatchCount(countedMatches); | ||
|
|
||
| LottoResult lottoResult = new LottoResult(lottoStatistics, (totalCount * LottoTicketCount.PRICE_PER_ONE_LOTTO_TICKET)); | ||
| OutputView.printRateOfReturn(lottoResult.calculateProfitRate()); | ||
|
|
||
| InputView.closeScanner(lottoScanner); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package domain; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Random; | ||
| import java.util.TreeSet; | ||
|
|
||
| public class Lotto { | ||
| public static final int LOTTO_NUMBER_LOWER_BOUND = 1; | ||
| public static final int LOTTO_NUMBER_BOUND = 45; | ||
| public static final int LOTTO_NUMBER_COUNT = 6; | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 클래스에서만 사용되는데, 접근 제어자를
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public을 해서 다른 클래스에서 사용할수있도록 하려고 했었는데, 제가 그렇게 안썼더라구요....
다만 LOTTO_NUMBER_COUNT 는 해당 클래스에서만 사용하기때문에 private으로 고쳐두었습니다 |
||
|
|
||
| TreeSet<Integer> randomNumberSet = new TreeSet<>(); | ||
| Random random = new Random(); | ||
|
|
||
| public Lotto() { | ||
| setLottoNumber(); | ||
| } | ||
|
|
||
| public Lotto(List<Integer> userSelectedNumbers) { | ||
| if (userSelectedNumbers.size() != LOTTO_NUMBER_COUNT) { | ||
| throw new IllegalArgumentException("로또 번호는" + LOTTO_NUMBER_COUNT + "개여야 합니다."); | ||
| } | ||
| this.randomNumberSet.addAll(userSelectedNumbers); | ||
| if (this.randomNumberSet.size() != LOTTO_NUMBER_COUNT) { | ||
| throw new IllegalArgumentException("로또 번호는 중복될 수 없습니다."); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 Lotto 생성자는 전달받은 번호의 개수와 중복 여부만 검증하고 있습니다. Lotto는 항상 유효한 로또 번호만 가지도록 1~45 범위 검증도 생성자 내부에서 함께 수행하는 것이 좋겠네요.
List<Integer> lottoNumbers = List.of(-1, 2, 3, 4, 5, 50);
Lotto lotto = new Lotto(lottoNumbers);
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자동로또 생성자를 만들 당시에는 어차피 주어진 범위내에서 랜덤번호가 만들어졌다보니 로또번호 범위검증을 안넣었습니다. 수동로또 생성자에 번호 범위 검증을 추가했습니다! |
||
|
|
||
| public TreeSet<Integer> getRandomNumberSet() { | ||
| return this.randomNumberSet; | ||
| } | ||
|
|
||
| private void setLottoNumber(){ | ||
| while (randomNumberSet.size() < LOTTO_NUMBER_COUNT) { | ||
| randomNumberSet.add(random.nextInt(LOTTO_NUMBER_LOWER_BOUND, LOTTO_NUMBER_BOUND + 1)); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class LottoChecker { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생성자에 메서드를 호출하는 순서와 실제 메서드 선언 순서가 다릅니다. public LottoChecker(...) {
wrappingToIntegerLottoNumbers(...);
validateBonusNumber(...);
}
private void wrappingToIntegerLottoNumbers(...) {
}
private void validateBonusNumber(...) {
}또한 일반적으로 클래스 내부에서는 public, protected, private처럼 접근 범위가 넓은 메서드부터 좁은 메서드 순으로 배치하는 관례를 많이 따릅니다.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 생성자 내 호출순서와 접근제어자 |
||
|
|
||
| private final ArrayList<Integer> winningLottoNumbers; | ||
| private final LottoTickets lottoTickets; | ||
|
|
||
| private final int bonusNumber; | ||
|
|
||
| public LottoChecker(String[] lastWeekWinnerLottoNumbers, LottoTickets lottoTickets, String bonusNumber) { | ||
| this.winningLottoNumbers = wrappingToIntegerLottoNumbers(lastWeekWinnerLottoNumbers); | ||
| this.lottoTickets = lottoTickets; | ||
| validateBonusNumber(bonusNumber); | ||
| this.bonusNumber = Integer.parseInt(bonusNumber); | ||
| } | ||
|
|
||
| public ArrayList<LottoWinningType> checkAllTickets() { | ||
| ArrayList<LottoWinningType> winningTypes = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < lottoTickets.getSize(); i++) { | ||
| int matchCount = calculateMatchCountForTicket(i); | ||
| boolean matchBonus = hasBonusNumber(i); | ||
|
|
||
| winningTypes.add(LottoWinningType.valueOf(matchCount, matchBonus)); | ||
| } | ||
| return winningTypes; | ||
| } | ||
|
|
||
| public boolean hasBonusNumber(int lottoTicketIndex) { | ||
| return lottoTickets.getLottoTreeSet(lottoTicketIndex).contains(this.bonusNumber); | ||
| } | ||
|
|
||
| private ArrayList<Integer> wrappingToIntegerLottoNumbers(String[] stringWinnerNumbers) { | ||
| return (ArrayList<Integer>) Arrays.stream(stringWinnerNumbers) | ||
| .map(Integer::parseInt) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| private void validateBonusNumber(String bonusNumber) { | ||
| try { | ||
| int number = Integer.parseInt(bonusNumber); | ||
| if (number < Lotto.LOTTO_NUMBER_LOWER_BOUND || number > Lotto.LOTTO_NUMBER_BOUND) { | ||
| throw new IllegalArgumentException( | ||
| "보너스 볼은" + Lotto.LOTTO_NUMBER_LOWER_BOUND + "과" + Lotto.LOTTO_NUMBER_BOUND + "사이의 숫자여야 합니다."); | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| throw new IllegalArgumentException("보너스 볼은 숫자여야 합니다."); | ||
| } | ||
| } | ||
|
|
||
| private int calculateMatchCountForTicket(int lottoTicketIndex) { | ||
| int matchCount = 0; | ||
| for (int winningNumber : winningLottoNumbers) { | ||
| matchCount += getMatchScore(lottoTicketIndex, winningNumber); | ||
| } | ||
| return matchCount; | ||
| } | ||
|
|
||
| private int getMatchScore(int lottoTicketIndex, int winningNumber) { | ||
| if (lottoTickets.getLottoTreeSet(lottoTicketIndex).contains(winningNumber)) { | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package domain; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| public class LottoResult { | ||
|
|
||
| private final LottoStatistics lottoStatistics; | ||
| private final int purchaseAmount; | ||
|
|
||
| public LottoResult(LottoStatistics lottoStatistics, int purchaseAmount) { | ||
| this.lottoStatistics = lottoStatistics; | ||
| this.purchaseAmount = purchaseAmount; | ||
| } | ||
|
|
||
| public double calculateProfitRate() { | ||
| long totalWinningPrize = calculateTotalPrize(); | ||
| if (totalWinningPrize == 0) { | ||
| return 0.0; | ||
| } | ||
| return (double) totalWinningPrize / purchaseAmount; | ||
| } | ||
|
|
||
| private long calculateTotalPrize() { | ||
| long totalPrize = 0; | ||
| Map<LottoWinningType, Integer> stats = lottoStatistics.getMatchStatistics(); | ||
|
|
||
| for (Map.Entry<LottoWinningType, Integer> entry : stats.entrySet()) { | ||
| LottoWinningType type = entry.getKey(); | ||
| int count = entry.getValue(); | ||
| totalPrize += (long) type.prizeExpression(count); | ||
| } | ||
| return totalPrize; | ||
| } | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class LottoStatistics { | ||
| private Map<LottoWinningType, Integer> matchStatistics = new HashMap<>(); | ||
|
|
||
| public LottoStatistics() { | ||
| for (LottoWinningType type : LottoWinningType.values()) { | ||
| matchStatistics.put(type, 0); | ||
| } | ||
| } | ||
|
|
||
| public Map<LottoWinningType, Integer> countMatches(ArrayList<LottoWinningType> winningTypes) { | ||
| for (LottoWinningType type : winningTypes) { | ||
| matchStatistics.put(type, matchStatistics.get(type) + 1); | ||
| } | ||
| return matchStatistics; | ||
| } | ||
|
|
||
| public Map<LottoWinningType, Integer> getMatchStatistics() { | ||
| return matchStatistics; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package domain; | ||
|
|
||
| public class LottoTicketCount { | ||
| public static final int PRICE_PER_ONE_LOTTO_TICKET = 1000; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
로또 하나의 가격을 2000원으로 변경한다면, 변경 지점이 여러 곳 이네요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LottoTicketCount 에 두는것이 나을거같아서 여기 클래스에 있는 티켓가격상수를 살려두고 |
||
| private int lottoTicketCount; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
단순히 특정 메서드 안에서 계산하고 바로 반환하는 값 인 것 같아요 ~
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 큰 고민없이 클래스의 인스턴스 변수로 두었었는데요, 성현님 질문을 통해 새롭게 배운 내용입니다.
=> 결론: 인스턴스 변수로 두게 되면, 불필요한 상태가 되는 셈이다. 즉, 인스턴스 변수가 아닌, 메서드 안에서 사용하는 지역변수이면 충분하다.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 위와 같은 이유로 LottoTickectCount에서 상태를 가지지 않게 수정을 했습니다. |
||
|
|
||
| public int convertLottoPriceToTicketCount(int totalLottoPrice) { | ||
| validatePurchaseAmount(totalLottoPrice); | ||
| lottoTicketCount = totalLottoPrice / PRICE_PER_ONE_LOTTO_TICKET; | ||
| return lottoTicketCount; | ||
| } | ||
|
|
||
| private void validatePurchaseAmount(int price) { | ||
| if (price < PRICE_PER_ONE_LOTTO_TICKET) { | ||
| throw new IllegalArgumentException("구입 금액은 " + PRICE_PER_ONE_LOTTO_TICKET + "원 이상이어야 합니다."); | ||
| } | ||
| if (price % PRICE_PER_ONE_LOTTO_TICKET != 0) { | ||
| throw new IllegalArgumentException("구입 금액은 " + PRICE_PER_ONE_LOTTO_TICKET + "원 단위로 입력해야 합니다."); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.TreeSet; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class LottoTickets { | ||
| ArrayList<Lotto> lottoArrayList = new ArrayList<>(); | ||
|
|
||
| public void addUserSelectedLottos(List<String> userSelectedNumbersInput) { | ||
| for (String numbersString : userSelectedNumbersInput) { | ||
| List<Integer> numbers = Arrays.stream(numbersString.split(",\\s*")) | ||
| .map(Integer::parseInt) | ||
| .collect(Collectors.toList()); | ||
| lottoArrayList.add(new Lotto(numbers)); | ||
| } | ||
| } | ||
|
|
||
| public void addAutoLottos(int autoCount) { | ||
| for (int i = 0; i < autoCount; i++) { | ||
| lottoArrayList.add(new Lotto()); | ||
| } | ||
| } | ||
|
|
||
| public TreeSet<Integer> getLottoTreeSet(int lottoTicketNumber){ | ||
| return new TreeSet<>(lottoArrayList.get(lottoTicketNumber).getRandomNumberSet()); | ||
| } | ||
|
|
||
| public int getSize() { | ||
| return lottoArrayList.size(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package domain; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.function.Function; | ||
|
|
||
| public enum LottoWinningType { | ||
| FIRST_PLACE("6개 일치 (2000000000원)- ", tickets -> tickets * 2000000000), | ||
| SECOND_PLACE("5개 일치, 보너스 볼 일치(30000000원)- ", tickets -> tickets * 30000000), | ||
| THIRD_PLACE("5개 일치 (1500000원)- ", tickets -> tickets * 1500000), | ||
| FOURTH_PLACE("4개 일치 (50000원)- ", tickets -> tickets * 50000), | ||
| FIFTH_PLACE("3개 일치 (5000원)- ", tickets -> tickets * 5000), | ||
| NO_PRIZE("2개 이하 일치 (0원)- ", tickets -> 0d); | ||
|
|
||
| private String winningDescription; | ||
| private Function<Double, Double> prizeExpression; | ||
|
|
||
|
|
||
| LottoWinningType(String winningDescription, Function<Double, Double> prizeExpression) { | ||
| this.winningDescription = winningDescription; | ||
| this.prizeExpression = prizeExpression; | ||
|
|
||
| } | ||
|
|
||
| public double prizeExpression(double matchingTickets) { | ||
| return prizeExpression.apply(matchingTickets); | ||
| } | ||
|
|
||
| public String getWinningDescription() { | ||
| return winningDescription; | ||
| } | ||
|
|
||
| public static LottoWinningType valueOf(int matchCount, boolean matchBonus) { | ||
| if (matchCount == 6) return FIRST_PLACE; | ||
| if (matchCount == 5 && matchBonus) return SECOND_PLACE; | ||
| if (matchCount == 5) return THIRD_PLACE; | ||
| if (matchCount == 4) return FOURTH_PLACE; | ||
| if (matchCount == 3) return FIFTH_PLACE; | ||
| return NO_PRIZE; | ||
| } | ||
|
|
||
| public static LottoWinningType findLottoWinningType(String winningType){ | ||
| return Arrays.stream(LottoWinningType.values()) | ||
| .filter(lottoWinningTypePrize -> lottoWinningTypePrize.name().equals(winningType)) | ||
| .findAny() | ||
| .orElse(NO_PRIZE); | ||
| } | ||
|
|
||
| } |





There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README 작성 잊지 않고 잘 해주셨네요 ~ 👍