-
Notifications
You must be signed in to change notification settings - Fork 39
[스프링 목요일 5팀](구나현) 미션 제출합니다 #34
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
Open
nahyunKoo
wants to merge
7
commits into
TEAM-ALOM:main
Choose a base branch
from
nahyunKoo:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6c247e2
다른 레포지토리를 fork 한 이슈로 몰아서 commit
nahyunKoo 0301006
로또 당첨번호랑 비교하는 메소드 작성
nahyunKoo 56ce9e6
로또 결과 출력하는 메소드 구현
nahyunKoo 2e7e081
메인메소드 간결하게 정리
nahyunKoo 5aae421
commit test
nahyunKoo c72e077
주석 달고 결과 출력하는 메소드 위치 이동
nahyunKoo e6f6663
TEST 3개 성공
nahyunKoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,96 @@ | ||
| package lotto; | ||
| import java.util.*; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
|
|
||
| try{ | ||
| List<Lotto> purchasedLottos = new ArrayList<>(); | ||
| int[] result; | ||
|
|
||
| //구입 금액 입력 받은 후 로또 개수 구하기 | ||
| int purchaseAmount = InputHelper.getIntInput("구입금액을 입력해 주세요."); | ||
| int numLotto = Lotto.getNumberOfLotto(purchaseAmount); | ||
| System.out.println(numLotto + "개를 구매했습니다."); | ||
|
|
||
| //로또 생성 후 생성한 로또들 출력 | ||
| Lotto.generateLotto(purchasedLottos, numLotto); | ||
| Application.printPurchasedLottos(purchasedLottos); | ||
|
|
||
| //당첨번호 입력받기 | ||
| List<Integer> winningNumbers = new ArrayList<>(getWinningNumbers()); | ||
|
|
||
| //보너스 번호 입력받기 | ||
| int bonus = getBonusNumber(); | ||
| Lotto.checkWinningNumberBonus(winningNumbers, bonus); | ||
|
|
||
|
|
||
| //로또 비교하기 | ||
| result = getResult(purchasedLottos, winningNumbers, bonus); | ||
|
|
||
| //결과 출력하기 | ||
| Application.printWinningResults(result, purchaseAmount); | ||
|
|
||
| } catch(IllegalArgumentException e){ | ||
| System.out.println(e.getMessage()); | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
| //구매한 로또 목록 출력하는 메소드 | ||
| private static void printPurchasedLottos(List<Lotto> purchased){ | ||
| for(int i = 0; i<purchased.size(); i++){ | ||
| System.out.println(purchased.get(i).getLottoNum()); | ||
| } | ||
| } | ||
|
|
||
| //당첨 번호 입력받는 메소드 | ||
| private static List<Integer> getWinningNumbers() { | ||
| List<Integer> winningNumbers = new ArrayList<>(InputHelper.getListInput("당첨 번호를 입력해 주세요.")); | ||
| Collections.sort(winningNumbers); | ||
| if(!Lotto.checkWinningNumbersRange(winningNumbers)){ | ||
| throw new IllegalArgumentException("[ERROR]로또 번호 개수는 6개입니다."); | ||
| } | ||
| if (!Lotto.checkWinningNumbersCount(winningNumbers)) { | ||
| throw new IllegalArgumentException("[ERROR]번호의 범위는 1~45입니다."); | ||
| } | ||
| if(!Lotto.checkWinningNumbersDuplication(winningNumbers)){ | ||
| throw new IllegalArgumentException("[ERROR]로또 번호에 중복이 있습니다."); | ||
| } | ||
| return winningNumbers; | ||
| } | ||
|
|
||
| //보너스 번호 입력 받는 메소드 | ||
| private static int getBonusNumber(){ | ||
| int bonusN = InputHelper.getIntInput("보너스 번호를 입력해 주세요."); | ||
| if(bonusN < 1 || bonusN > 45){ | ||
| throw new IllegalArgumentException("[ERROR]번호의 범위는 1~45입니다."); | ||
| } | ||
| return bonusN; | ||
| } | ||
|
|
||
| //구매한 모든 로또에 대해 반복문을 돌면서 당첨 확인한 후 결과를 저장하는 메소드 | ||
| private static int[] getResult(List<Lotto> purchased, List<Integer> winningNumbers, int bonus){ | ||
| int[] result = {0, 0, 0, 0, 0, 0}; | ||
| for(int i = 0; i<purchased.size(); i++){ | ||
| int rank = Lotto.checkWinningResults(winningNumbers, purchased.get(i), bonus); | ||
| result[rank] += 1; | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| //결과 출력하는 메소드 | ||
| private static void printWinningResults(int[] result, int purchaseP) { | ||
| double earningRate; | ||
| System.out.println("당첨 통계"); | ||
| System.out.println("---"); | ||
| System.out.println("3개 일치 (5,000원) - " + result[5] + "개"); | ||
| System.out.println("4개 일치 (50,000원) - " + result[4] + "개"); | ||
| System.out.println("5개 일치 (1,500,000원) - " + result[3] + "개"); | ||
| System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원) - " + result[2] + "개"); | ||
| System.out.println("6개 일치 (2,000,000,000원) - " + result[1] + "개"); | ||
| earningRate = (double)((result[5] * 5 + result[4] * 50 + result[3] * 1500 + result[2] * 30000 + result[1] * 2000000)) / (purchaseP / 1000) * 100; | ||
| System.out.println("총 수익률은 " + earningRate + "%입니다."); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package lotto; | ||
|
|
||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import org.kokodak.Console; | ||
|
|
||
| public class InputHelper { | ||
|
|
||
| //정수를 입력받는 메소드 | ||
| public static int getIntInput(String prompt) { | ||
| try{ | ||
| System.out.println(prompt); | ||
| int num = Integer.parseInt(Console.readLine()); | ||
| return num; | ||
| } catch (IllegalArgumentException e){ | ||
| throw new IllegalArgumentException("[ERROR]유효한 숫자를 입력해주세요"); | ||
| } | ||
| } | ||
|
|
||
| //리스트를 입력받는 메소드 | ||
| public static List<Integer> getListInput(String prompt){ | ||
| List<Integer> list = new ArrayList<>(); | ||
| System.out.println(prompt); | ||
| String line = Console.readLine(); | ||
| String[] str = line.split(","); | ||
| if(str.length == 6){ | ||
| for(int i = 0; i < str.length; i++){ | ||
| list.add(Integer.parseInt(str[i])); | ||
| } | ||
| return list; | ||
| } | ||
| throw new IllegalArgumentException("[ERROR]당첨숫자의 개수를 잘못 입력했습니다."); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
우왕! 직접 작성하셨다니! 정말 대단해요!