-
Notifications
You must be signed in to change notification settings - Fork 40
[스프링 목요일 5팀](김태식) 미션 제출합니다 #33
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
Kimttaeshik
wants to merge
2
commits into
TEAM-ALOM:main
Choose a base branch
from
Kimttaeshik: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
2 commits
Select commit
Hold shift + click to select a range
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
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,90 @@ | ||
| package lotto; | ||
|
|
||
| import lotto.controller.LottoController; | ||
|
|
||
| import java.util.Scanner; | ||
|
|
||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| LottoController lottoController = new LottoController(); | ||
| lottoController.run(); | ||
|
|
||
|
|
||
| // TODO: 프로그램 구현 | ||
|
|
||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // | ||
| //package lotto; | ||
| // | ||
| //import org.kokodak.Randoms; | ||
| //import org.kokodak.Console; | ||
| // | ||
| // | ||
| // | ||
| //public class Application { | ||
| // public static void main(String[] args) { | ||
| // // TODO: 프로그램 구현 | ||
| // | ||
| // int[] lotto = new int[6]; | ||
| // Randoms randoms = new Randoms; | ||
| // | ||
| // Lotto(randoms.in); | ||
| // | ||
| // int money; | ||
| // int bonus_number; | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // System.out.print("구입 금액을 입력하세요: "); | ||
| // | ||
| // System.out.println("당첨 번호를 입력하세요(쉼표로 구분): "); | ||
| // | ||
| // System.out.println("보너스 번호를 입력하세요: "); | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // | ||
| // for (int i = 0; i < lotto.length; i++) { | ||
| // lotto[i] = random.nextInt(45) + 1; | ||
| // // 중복번호 제거 | ||
| // for(int j = 0; j < i; j++) { | ||
| // if(lotto[i] == lotto[j]) { | ||
| // i--; | ||
| // break; | ||
| // } | ||
| // } | ||
| // } | ||
| // | ||
| // // 오름차순 정렬 | ||
| // for(int i = 0; i < lotto.length; i++) { | ||
| // for(int j = i + 1; j < lotto.length; j++) { | ||
| // if(lotto[i] > lotto[j]) { | ||
| // int temp = lotto[i]; | ||
| // lotto[i] = lotto[j]; | ||
| // lotto[j] = temp; | ||
| // } | ||
| // } | ||
| // } | ||
| // | ||
| // // 랜덤번호 출력 | ||
| // System.out.println("* 로또번호 : " + Arrays.toString(lotto)); | ||
| // | ||
| // | ||
| // } | ||
| //} | ||
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,20 +1,20 @@ | ||
| package lotto; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class Lotto { | ||
| private final List<Integer> numbers; | ||
|
|
||
| public Lotto(List<Integer> numbers) { | ||
| validate(numbers); | ||
| this.numbers = numbers; | ||
| } | ||
|
|
||
| private void validate(List<Integer> numbers) { | ||
| if (numbers.size() != 6) { | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| // TODO: 추가 기능 구현 | ||
| } | ||
| //package lotto; | ||
| // | ||
| //import java.util.List; | ||
| // | ||
| //public class Lotto { | ||
| // private final List<Integer> numbers; | ||
| // | ||
| // public Lotto(List<Integer> numbers) { | ||
| // validate(numbers); | ||
| // this.numbers = numbers; | ||
| // } | ||
| // | ||
| // private void validate(List<Integer> numbers) { | ||
| // if (numbers.size() != 6) { | ||
| // throw new IllegalArgumentException(); | ||
| // } | ||
| // } | ||
| // | ||
| // // TODO: 추가 기능 구현 | ||
| //} |
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,59 @@ | ||
| package lotto.domain; | ||
|
|
||
| import lotto.view.ExceptionMessage; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| public class Lotto { | ||
| private static final int minNumber = 1; | ||
| private static final int maxNumber = 45; | ||
| private final List<Integer> numbers; | ||
| public Lotto(List<Integer> numbers){ | ||
| validate(numbers); | ||
| validateOverlap(numbers); | ||
| validateRange(numbers); | ||
|
|
||
| Collections.sort(numbers); | ||
| this.numbers = numbers; | ||
| } | ||
| public List<Integer> getLottoNumbers(){ | ||
| return numbers; | ||
| } | ||
| public int countMatch(Lotto winLotto){ | ||
| return (int) numbers.stream().filter(winLotto::containNumber).count(); | ||
| } | ||
| public boolean containNumber(int number){ | ||
| return numbers.contains(number); | ||
| } | ||
| private void validate(List<Integer> numbers){ | ||
| if(numbers.size() != 6){ | ||
| ExceptionMessage.sizeException(); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| private void validateOverlap(List<Integer> numbers){ | ||
| Set<Integer> overlapCheck = new HashSet<>(); | ||
| for (int i = 0; i< numbers.size();i++){ | ||
| overlapCheck.add(numbers.get(i)); | ||
| } | ||
| if (overlapCheck.size() != 6){ | ||
| ExceptionMessage.overlapException(); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| private void validateRange(List<Integer> numbers){ | ||
| for (int winNumber = 0;winNumber<numbers.size();winNumber++){ | ||
| if (numbers.get(winNumber) < minNumber || numbers.get(winNumber) > maxNumber){ | ||
| ExceptionMessage.rangeException(); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } | ||
| public static void validateBonusNumber(List<Integer> numbers, int bonusNumber){ | ||
| if (numbers.contains(bonusNumber)){ | ||
| ExceptionMessage.overlapException(); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
|
|
||
| } |
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,22 @@ | ||
| package lotto.domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import camp.nextstep.edu.missionutils.Randoms; | ||
|
|
||
| public class LottoNumbers { | ||
| public LottoNumbers(){ | ||
|
|
||
| } | ||
| private static final int cntLottoNumber = 6; | ||
| private static final int minLottoNumber = 1; | ||
| private static final int maxLottoNumber = 45; | ||
| private static List<Integer> lottoNumberList; | ||
| public static List<Integer> setRandomNumbers(){ | ||
| lottoNumberList = Randoms.pickUniqueNumbersInRange(minLottoNumber,maxLottoNumber,cntLottoNumber); | ||
| List<Integer> lottoTicketNumberList = new ArrayList<>(lottoNumberList); | ||
| Collections.sort(lottoTicketNumberList); | ||
| return lottoTicketNumberList; | ||
| } | ||
| } |
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,39 @@ | ||
| package lotto.domain; | ||
| import lotto.view.ExceptionMessage; | ||
|
|
||
| public class PlayerLottoAmount { | ||
| private static final int lottoPrice = 1000; | ||
| private final int coin; | ||
| public PlayerLottoAmount(String coin){ | ||
| int coinNum = validateNumber(coin); | ||
| validateCoin(coinNum); | ||
| this.coin = coinNum; | ||
| } | ||
| public int calcLottoCount(){ | ||
| return coin / lottoPrice; | ||
| } | ||
| private void validateCoin(int coin){ | ||
| validateNatural(coin); | ||
| validateDivisible(coin); | ||
| } | ||
| private static int validateNumber(String coin) throws IllegalArgumentException{ | ||
| try{ | ||
| return Integer.parseInt(coin); | ||
| } catch (NumberFormatException e){ | ||
| ExceptionMessage.numberException(); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| private void validateNatural(int coin){ | ||
| if (coin <= 0) { | ||
| ExceptionMessage.naturalException(); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| private void validateDivisible(int coin){ | ||
| if (coin % lottoPrice != 0){ | ||
| ExceptionMessage.divisibleException(); | ||
| throw new IllegalArgumentException(); | ||
| } | ||
| } | ||
| } |
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,57 @@ | ||
| package lotto.domain; | ||
|
|
||
| import lotto.view.OutputView; | ||
|
|
||
| public enum Ranking { | ||
| first(6,2_000_000_000, "6개 일치 (2,000,000,000원) - "), | ||
| second(5,30_000_000, "5개 일치, 보너스 볼 일치 (30,000,000원) - "), | ||
| third(5,1_500_000, "5개 일치 (1,500,000원) - "), | ||
|
|
||
| fourth(4,50_000, "4개 일치 (50,000원) - "), | ||
| fifth(3,5_000, "3개 일치 (5,000원) - "), | ||
| miss(0,0,""); | ||
|
|
||
| public int getMatchCount() { | ||
| return matchCount; | ||
| } | ||
|
|
||
| public int getWinAmount() { | ||
| return winAmount; | ||
| } | ||
| private boolean counter(int matchCount){ | ||
| return this.matchCount == matchCount; | ||
| } | ||
| public void printMessage(int cnt){ | ||
| if (this!=miss){ | ||
| OutputView.printSuccessMessage(message,cnt); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Ranking(int matchCount, int winAmount, String message){ | ||
| this.matchCount = matchCount; | ||
| this.winAmount = winAmount; | ||
| this.message = message; | ||
| } | ||
| private static final int winMinCount = 3; | ||
| private static final String errorMessage = "[ERROR]"; | ||
|
|
||
| private int matchCount; | ||
| private int winAmount; | ||
| private String message; | ||
| public static Ranking valueOf(int matchCount,boolean matchBonus){ | ||
| if (matchCount < winMinCount){ | ||
| return miss; | ||
| } | ||
| if (second.counter(matchCount) && matchBonus){ | ||
| return second; | ||
| } | ||
| for (Ranking rank : values()){ | ||
| if (rank.counter(matchCount)&&rank != second){ | ||
| return rank; | ||
| } | ||
| } | ||
| throw new IllegalArgumentException(errorMessage); | ||
| } | ||
|
|
||
| } |
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,15 @@ | ||
| package lotto.domain; | ||
|
|
||
| public class WinResult { | ||
| private final Lotto lotto; | ||
| private final int bonus; | ||
| public WinResult(Lotto lotto,int bonus){ | ||
| this.lotto = lotto; | ||
| this.bonus = bonus; | ||
| } | ||
| public Ranking match(Lotto playername){ | ||
| int matchCount = playername.countMatch(lotto); | ||
| boolean bonusCheck = playername.containNumber(bonus); | ||
| return Ranking.valueOf(matchCount,bonusCheck); | ||
| } | ||
| } |
Oops, something went wrong.
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.
혹시.. 스캐너 사용 하셨나요?
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.
처음에 모르고 사용했다가 지우는 과정에서 깜빡했네요!