-
Notifications
You must be signed in to change notification settings - Fork 122
[완두콩] 이지인 로또 미션 제출합니다. #206
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: eas-yin
Are you sure you want to change the base?
Changes from 5 commits
454c575
93aa2d4
549c80d
7d69333
d02b955
915790b
d8d6548
d405a8e
50395ca
0664a34
27c891f
5086f62
eaf3205
92d0254
d178e57
cf56668
71a792e
2851bd0
13229a9
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,37 @@ | ||
| import domain.LottoResult; | ||
| import domain.WinningRate; | ||
| import view.InputView; | ||
| import view.ResultView; | ||
| import domain.Lotto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| Lotto lotto = new Lotto(); | ||
| LottoResult lottoResult = new LottoResult(); | ||
| WinningRate winningRate = new WinningRate(); | ||
|
|
||
| int purchasePrice = InputView.inputPrice(); | ||
| int lottoCount = lotto.calculateCount(purchasePrice); | ||
| int passiveCount = InputView.inputPassiveCount(); | ||
| int autoCount = lottoCount - passiveCount; | ||
|
|
||
| List<List<Integer>> passiveLotto = InputView.inputPassiveLotto(passiveCount); | ||
| List<List<Integer>> autoLotto = lotto.lottoLists(autoCount); | ||
|
|
||
| ResultView.printPurchase(passiveLotto, passiveCount, autoCount); | ||
| passiveLotto.addAll(autoLotto); | ||
|
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. 컴파일 문제를 해결한 뒤에는 수동 0장, 자동 3장이나 수동 1장, 자동 2장을 입력해서 직접 실행해보면 좋겠습니다. 지금은 수동 로또만 아무래도 4단계에서 기능을 구현하다가 막혀서 놓치게된 케이스 같은데, 기능을 구현한 뒤에 사용자 입력을 직접 실행하거나 테스트로 남겨두면 이런 문제를 조금 더 일찍 발견할 수 있다는 점 참고하세요!
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. 수동과 자동 번호를 모두 출력할 수 있도록 출력 순서를 바꿨습니다! |
||
|
|
||
| List<Integer> wins = InputView.inputWinning(); | ||
|
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. |
||
| int bonusBall = InputView.inputBonusBall(); | ||
|
Comment on lines
+27
to
+28
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~45 범위의 중복 없는 번호 6개라는 점에서는 한 장의 이때 보너스 볼이 당첨 번호 6개 중 하나와 같아도 되는지도 함께 생각해보면 좋겠습니다. |
||
| List<Integer> counts = lottoResult.calculateCounts(passiveLotto, wins, bonusBall); | ||
|
|
||
| int winPrice = winningRate.calculateWinPrice(counts); | ||
| double rate = winningRate.calculateRate(winPrice, purchasePrice); | ||
|
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. 위에서 생성한 |
||
|
|
||
| ResultView.printResult(counts, rate); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class Lotto { | ||
|
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. 지금은 일급 컬렉션은 단순히 List를 클래스로 감싸는 것보다, 컬렉션 전체가 지켜야 하는 규칙을 한곳에서 보장하는 데 의미가 있는데요. 사실 지금
한 장의 로또를 표현하는 그렇게 바꿨을 때 지금의
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. 현재는 로또가 계산 같은 기능을 하는데 로또 한 장의 상태를 나타내야 합니다. 일급 컬렉션은 하나의 객체가 그 컬렉션에 대한 규칙과 책임을 갖게 합니다. 기존의 Lotto에 있던 기능 메서드들은 LottoGenerator 클래스로 이동하였고, 그에 따라서 Application 클래스도 수정하였습니다. Lotto 클래스에서 컬렉션이 규칙과 책임을 가지도록 private한 리스트를 만들었고, 생성자와 팩토리 메서드를 구현하였습니다. 번호가 5개 또는 7개인 로또 - 유효성 검증 메서드를 구현했습니다. 같은 번호가 중복된 로또 - 유효성 검증 메서드를 구현했습니다. 유효하지 않은 번호가 포함된 로또 - LottoNumber 클래스에서 이미 검증했다고 생각하여 따로 구현하지 않았습니다. 또한 LottoTest 클래스에서 각각을 테스트 하였습니다. |
||
| public int calculateCount(int price) { | ||
| return price / 1000; | ||
| } | ||
|
|
||
| private static List<Integer> lottoList() { | ||
| List<Integer> lotto = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < 45; i++) { | ||
| lotto.add(i+1); | ||
| } | ||
| return lotto; | ||
| } | ||
|
|
||
| private void lottoShuffle(List<Integer> lotto) { | ||
| Collections.shuffle(lotto); | ||
| } | ||
|
|
||
| private List<LottoNumber> lottoPick(List<Integer> lotto) { | ||
| List<LottoNumber> lottoSix = new ArrayList<>(); | ||
| for (int i = 0; i < 6; i++) { | ||
| lottoSix.add(lotto.get(i)); | ||
|
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. 팩토리 메서드: 객체를 대신 만들어 주는 메서드
Lotto에서는 숫자를 LottoNumber 객체로 변환하는 것이기 때문에 from을 사용하였고, Lotto 클래스도 수정하였습니다. |
||
| } | ||
|
|
||
| return lottoSix; | ||
| } | ||
|
|
||
| private void lottoSort(List<LottoNumber> lotto) { | ||
| Collections.sort(lotto); | ||
| } | ||
|
|
||
| public List<LottoNumber> run() { | ||
| List<Integer> lottoList = lottoList(); | ||
|
|
||
| lottoShuffle(lottoList); | ||
| List<LottoNumber> lotto = lottoPick(lottoList); | ||
| lottoSort(lotto); | ||
|
|
||
| return lotto; | ||
| } | ||
|
|
||
| public List<List<LottoNumber>> lottoLists(int count) { | ||
| List<List<Integer>> lottos = new ArrayList<>(); | ||
| for (int i = 0; i < count; i++) { | ||
| lottos.add(run()); | ||
| } | ||
| return lottos; | ||
| } | ||
|
|
||
|
|
||
|
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. Ctrl + Alt + L으로 정렬했습니다! 감사합니다. |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package domain; | ||
|
|
||
| public class LottoNumber { | ||
|
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. 원시값 포장은 단순히 int를 필드로 옮기는 건 아닙니다.
이 질문을 만족하도록 생성 방법, 검증, 값 비교, 정렬 기준을 하나씩 구현하고 테스트해보면 원시값 포장의 목적을 이해하는 데 도움이 될 것 같습니다~
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. 0이나 46으로 생성할 수 있는지 - LottoNumber 유효성 검사 메서드 생성 및 Test 코드 추가하였습니다. 테스트 하는 도중 타입 부분이 컴파일 오류가 떠서 오류가 나는 부분의 타입을 수정하였습니다. 타입을 수정하면서 번호 관리를 하는 원시값 포장에 대해서 이해했습니다! 값이 3인 두 객체를 같은 번호라고 할 수 있는지 - equals로 판단하여 테스트 코드 추가하였습니다. 유효성 검사할 때 수정하지 못했던 정렬 부분 Collections.sort() 메서드도 함께 수정하였습니다. 번호를 오름차순으로 정렬할 수 있는지 - 확인하는 테스트를 추가하였습니다. 또한 지금까지 커밋 메시지 작성 시 refactor:, test: 등을 적용하지 못했는데, 이번부터는 적용하여 작성하였습니다. 외부에서 실제로 객체를 생성할 수 있는지 - 외부에서 직접 생성자를 호출하면 유효성 검사를 거치지 않은 객체도 생성할 수 있다고 생각했습니다. 따라서 객체 생성은 팩토리 메서드를 통해서만 이루어지도록 생성자를 private으로 변경했습니다. 리뷰어 님의 요구에 대한 답이 제가 이해한 방향이 맞는지 궁금합니다. 답변에 대해 수정하다 보니 원시값 포장에 대해 이해할 수 있었던 것 같습니다. 아직 완벽하진 않지만 계속 미션 하면서 적용해 보겠습니다! 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 int number; | ||
|
|
||
| private LottoNumber(int number) { | ||
| this.number = number; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
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. getNumber() 삭제하였습니다! |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| public class LottoResult { | ||
|
|
||
| private boolean containsWinningNumber(List<Integer> lottoList, int win) { | ||
| return lottoList.contains(win); | ||
| } | ||
|
|
||
| private int resultCounting(List<Integer> lottoList, int win, int count) { | ||
| if (containsWinningNumber(lottoList, win)) { | ||
| count++; | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| private int checkingWinningNumbers(List<Integer> lottoList, List<Integer> wins, int bonusBall) { | ||
| int count = 0; | ||
| for (int win : wins) { | ||
| count = resultCounting(lottoList, win, count); | ||
| } | ||
|
|
||
| if (count == 5 && containsWinningNumber(lottoList, bonusBall)) return 7; | ||
|
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.
이후 코드는 일치 개수와 보너스 볼 일치 여부를 전달해 enum이 당첨 결과를 판단하게 하면 어떨까요? 이와 관련해서는 위에 남겨둔 enum 관련 피드백을 참고해주세요.
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. 기존에는 LottoResult에서 당첨 번호가 5개 일치하고 보너스 볼까지 일치한 경우 7을 반환하도록 구현했는데, 말씀해 주신 것처럼 7만으로는 어떤 당첨 결과를 의미하는지 알기 어렵다고 생각했습니다. 이를 수정하여 일치한 번호의 개수와 보너스 볼 일치 여부를 Rank에 전달하고, Rank.find()에서 해당 조건에 맞는 등수를 판단하도록 변경하였습니다. |
||
| return count; | ||
| } | ||
|
|
||
| public List<Integer> calculateCounts(List<List<Integer>> lottos, List<Integer> wins, int bonusBall) { | ||
| List<Integer> counts = new ArrayList<>(); | ||
|
|
||
| for (List<Integer> lotto : lottos) { | ||
| counts.add(checkingWinningNumbers(lotto, wins, bonusBall)); | ||
| } | ||
| return counts; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package domain; | ||
|
|
||
| public class Purchase { | ||
|
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. LottoNumber를 구현하면서 원시값 포장과 객체의 책임을 나누는 방향을 조금 이해해서, 비슷한 방식으로 PurchaseAmount도 구입 금액을 표현하는 객체로 변경해 보았습니다. 생성 시 유효한 구입 금액(1,000원 이상, 1,000원 단위)인지 검증하도록 구현하고, 로또 수를 계산하는 책임도 PurchaseAmount로 이동하였습니다. 다만 수익률 계산과 관련된 부분은 잘 모르겠습니다. 구입 금액도 PurchaseAmount가 알고 있어야 할 것 같다고 생각했는데, 수익률 계산까지 PurchaseAmount의 책임으로 두는 것이 맞는지 잘 모르겠습니다. 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.
그런데 수익률은 구입 금액 하나만으로 계산할 수 있는 건 아니고, 구입 금액과 총 당첨금 사이의 관계로 만들어지는 값이죠.
우선 지금은 구입 금액을 사용하는 코드가 계속 int를 사용해도 괜찮은지 먼저 고민해보면 좋을 것 같습니다! |
||
| private final int price; | ||
|
|
||
| private Purchase(int price) { | ||
| this.price = price; | ||
| } | ||
|
|
||
| private int getLottoCount() { | ||
| return price / 1000; | ||
| } | ||
|
|
||
| private int getPrice() { | ||
| return price; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package domain; | ||
|
|
||
| public enum WinningPrize { | ||
| THREE(3, 5000), | ||
| FOUR(4, 50000), | ||
| FIVE(5, 1500000), | ||
| BONUS(7, 30000000), | ||
| SIX(6, 2000000000); | ||
|
|
||
| private final int goal; | ||
| private final int prize; | ||
|
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. 이제 지인님이 처음에 남겨주셨던 enum에 대해 한번 살펴볼까요? 지금 enum의 이름은 특히 그렇다면 이 enum의 본질이 무엇일까일치 개수, 보너스 볼 조건, 당첨금은 결국 로또의 당첨 결과를 판단하기 위한 정보죠. 그렇다면 이 enum을 그럼 enum 상수의 이름도 일치 개수가 아니라 실제 등수로 표현할 수 있겠네요. 이젠 5개 일치라는 같은 조건에서도 보너스 여부에 따라
이렇게 실제 일치 개수와 보너스 볼 일치 여부를 그리고
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. WinningPrize를 Rank로 변경하고, FIRST, SECOND, THIRD, FOURTH, FIFTH, MISS로 당첨 결과를 직접 표현하도록 변경하였습니다. 또한 일치 개수와 보너스 볼 일치 여부를 통해 Rank를 판단하도록 하여 기존에 사용하던 7과 같은 숫자를 제거하였습니다. 이에 맞춰서 LottoResult가 List 대신 List를 반환하도록 변경하고, WinningRate에서는 각 Rank가 가지고 있는 당첨금을 이용해 총 당첨금을 계산하도록 수정하였습니다. ResultView 역시 숫자별 결과가 아닌 각 Rank의 개수를 세어 출력하도록 변경하였습니다. |
||
|
|
||
| WinningPrize(int goal, int prize) { | ||
| this.goal = goal; | ||
| this.prize = prize; | ||
| } | ||
|
|
||
| public int getGoal() { | ||
| return goal; | ||
| } | ||
|
|
||
| public int getPrize() { | ||
| return prize; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package domain; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class WinningRate { | ||
|
|
||
| public int calculateWinPrice(List<Integer> counts) { | ||
| return threeWin(counts) + fourWin(counts) + fiveWin(counts) + secondWin(counts) + sixWin(counts); | ||
| } | ||
|
|
||
| private int threeWin(List<Integer> counts) { | ||
| return countGoal(counts, WinningPrize.THREE.getGoal()) * WinningPrize.THREE.getPrize(); | ||
| } | ||
|
|
||
| private int fourWin(List<Integer> counts) { | ||
| return countGoal(counts, WinningPrize.FOUR.getGoal()) | ||
| * WinningPrize.FOUR.getPrize(); | ||
| } | ||
|
|
||
| private int fiveWin(List<Integer> counts) { | ||
| return countGoal(counts, WinningPrize.FIVE.getGoal()) | ||
| * WinningPrize.FIVE.getPrize(); | ||
| } | ||
|
|
||
| private int secondWin(List<Integer> counts) { | ||
| return countGoal(counts, WinningPrize.BONUS.getGoal()) | ||
| * WinningPrize.BONUS.getPrize(); | ||
| } | ||
|
|
||
| private int sixWin(List<Integer> counts) { | ||
| return countGoal(counts, WinningPrize.SIX.getGoal()) | ||
| * WinningPrize.SIX.getPrize(); | ||
| } | ||
|
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 int countGoal(List<Integer> counts, int goal) { | ||
| int count = 0; | ||
|
|
||
| for (int i = 0; i < counts.size(); i++) { | ||
| if (goal == counts.get(i)) count++; | ||
| } | ||
| return count; | ||
| } | ||
|
|
||
| public double calculateRate(int winPrice, int purchasePrice) { | ||
| return (double) winPrice / purchasePrice; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package view; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Scanner; | ||
|
|
||
| public class InputView { | ||
|
|
||
| private static Scanner scanner = new Scanner(System.in); | ||
|
|
||
| public static int inputPrice() { | ||
|
|
||
| System.out.println("구입금액을 입력해 주세요."); | ||
| int price = scanner.nextInt(); | ||
|
Comment on lines
+15
to
+16
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. |
||
|
|
||
| return price; | ||
| } | ||
|
|
||
| public static List<Integer> inputWinning() { | ||
| scanner.nextLine(); | ||
| System.out.println("\n지난 주 당첨 번호를 입력해 주세요."); | ||
|
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.
Java에서는
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. System.out.println()으로 빈 줄 출력하였습니다! |
||
| String win = scanner.nextLine(); | ||
|
|
||
| String[] wins = win.split(","); | ||
| List<Integer> nums = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < wins.length; i++) { | ||
| nums.add(Integer.parseInt(wins[i])); | ||
| } return nums; | ||
| } | ||
| public static int inputBonusBall() { | ||
| System.out.println("\n보너스 볼을 입력해 주세요."); | ||
| int bonusBall = scanner.nextInt(); | ||
|
|
||
| return bonusBall; | ||
| } | ||
|
|
||
| public static int inputPassiveCount() { | ||
| System.out.println("\n수동으로 구매할 로또 수를 입력해 주세요."); | ||
| int count = scanner.nextInt(); | ||
| return count; | ||
| } | ||
|
|
||
| public static List<List<Integer>> inputPassiveLotto(int manualCount) { | ||
| scanner.nextLine(); | ||
|
|
||
| System.out.println("\n수동으로 구매할 번호를 입력해 주세요."); | ||
| List<List<Integer>> passiveLottos = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < manualCount; i++) { | ||
| passiveLottos.add(inputManualLotto()); | ||
| } | ||
| return passiveLottos; | ||
| } | ||
|
|
||
| private static List<Integer> inputManualLotto() { | ||
| String input = scanner.nextLine(); | ||
| String[] numbers = input.split(","); | ||
|
|
||
| List<Integer> lotto = new ArrayList<>(); | ||
|
|
||
| for (String number : numbers) { | ||
| lotto.add(Integer.parseInt(number.trim())); | ||
| } | ||
|
|
||
| return lotto; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package view; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class ResultView { | ||
|
|
||
| public static void printPurchase(List<List<Integer>> lottos, int passiveCount, int autoCount) { | ||
| System.out.println("수동으로 " + passiveCount + "장, 자동으로 " + autoCount + "개를 구매했습니다." | ||
| ); | ||
| for (List<Integer> lotto : lottos) { | ||
| System.out.println(lotto); | ||
| } | ||
| } | ||
|
|
||
| public static void printResult(List<Integer> counts, double rate) { | ||
| System.out.println(); | ||
| System.out.println("당첨 통계"); | ||
| System.out.println("---------"); | ||
|
|
||
| int[] result = new int[8]; | ||
|
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.
프로그래밍 요구사항에는 배열 대신 컬렉션을 사용하도록 되어 있는데, 당첨 결과는 아직 배열로 집계하고 있네요. 앞에 남겨둔 리뷰처럼 당첨 결과를 enum을 키로 사용하기 적합한 |
||
|
|
||
| for (int count : counts) { | ||
| result[count]++; | ||
| } | ||
|
|
||
| System.out.println("3개 일치 (5,000원) - " + result[3] + "개"); | ||
| System.out.println("4개 일치 (50,000원) - " + result[4] + "개"); | ||
| System.out.println("5개 일치 (1,500,000원) - " + result[5] + "개"); | ||
| System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원) - " + result[7] + "개"); | ||
| System.out.println("6개 일치 (2,000,000,000원) - " + result[6] + "개"); | ||
| System.out.printf("총 수익률은 %.2f입니다.\n", rate); | ||
| } | ||
| } | ||



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.
이렇게 수동 구매 수를 음수로 입력하면, 실제로 지불한 금액보다 많은 로또를 구매할 수 있게 되네요~
수동 구매 수는 어떤 범위여야 할까요?
그리고 전체 구매 수와 수동 구매 수 사이의 규칙은 어느 객체가 보장하면 좋을지도 고민해보면 좋겠습니다.
0, 전체 구매 수와 같은 값, 전체 구매 수보다 큰 값, 음수를 각각 테스트해보는 것도 도움이 될 것 같아요~