-
Notifications
You must be signed in to change notification settings - Fork 1.1k
2주차 - Step4 로또(수동) 리뷰 요청드립니다. #262
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b183733
[step4] feat : step4 패키지 생성
Integerous 3113b8a
[step4] refactor : LottoTickets 일급 컬렉션 추가 (피드백 반영)
ea39369
[step4] refactor : List<LottoTicket> 사용되던 곳을 LottoTickets로 변경(피드백 반영)
dace932
[step4] refactor : 도메인 영역 내에서 int bonusNumber를LottoNumber 불변객체로 주고 받도…
571046a
[step4] refactor : 당첨티켓과 보너스번호를 담는 LuckyTicket 객체 생성
94f93a4
[step4] refactor : lottoTicket과 bonusNumber를 인자로 사용하던 부분을 LuckyTicket…
dfd3c02
[step4] refactor : LottoRank를 생성할때 원시값 대신 객체 전달
942152f
[step4] refactor : LottoRank 정적팩토리메서드의 로직 개선
9fdd283
[step4] refactor : OutputView의 당첨결과 출력 로직 개선
e7d1325
[step4] refactor : 테스트코드 수정
10324b9
[step4] feat : 로또 수동 구매 view 생성
d133891
[step4] feat : 각 수동로또와 자동로또 개수 저장
68d9f5d
[step4] feat : 수동으로 구매할 번호를 입력받아 컬렉션으로 반환하는 메서드 추가
666b334
[step4] feat : 자동 생성되는 로또복권 리스트에 수동복권 추가
ebc0ef6
[step4] refactor : 총 구입개수 반환하는 메서드 개선
ac292eb
[step4] refactor : 5개 맞추면 모두 2등으로 추출되는 오류 해결
300fc9b
[step4] refactor : 5등 미만(LOSER)는 출력하지 않도록 수정
5b725a1
[step4] refactor : 필요없는 import 제거
0766b70
[step4] refactor : (피드백 반영) List<List<Integer>> 대신 List<String> 사용
Integerous 0246b91
[step4] refactor : 결과 출력 로직 개선
Integerous 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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package step4; | ||
|
|
||
| import step4.domain.*; | ||
| import step4.view.InputView; | ||
| import step4.view.OutputView; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public class LottoApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| final int inputMoney = InputView.askMoneyToInput(); | ||
| final int numberOfManualTickets = InputView.askNumberOfManualTicket(); | ||
| final int numberOfAutoTickets = LottoSeller.countAutoTickets(inputMoney, numberOfManualTickets); | ||
|
|
||
| List<String> manualTickets = InputView.askNumbersForManualTickets(numberOfManualTickets); | ||
| OutputView.printNumberOfTickets(numberOfManualTickets, numberOfAutoTickets); | ||
|
|
||
| LottoTickets lottoTickets = LottoSeller.issueLottoTicket(manualTickets, numberOfAutoTickets); | ||
| OutputView.printLottoTickets(lottoTickets); | ||
|
|
||
| LuckyTicket luckyTicket = LottoSeller | ||
| .getLuckyNumber(InputView.askLuckyNumber(), InputView.askBonusNumber()); | ||
|
|
||
| ResultSheet result = ResultSheet.getResult(lottoTickets, luckyTicket); | ||
| OutputView.printResult(result); | ||
| } | ||
| } | ||
|
|
||
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,17 @@ | ||
| package step4.domain; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| public class LottoBalls { | ||
|
|
||
| private static List<Integer> lottoBalls = IntStream | ||
| .rangeClosed(LottoNumber.MINIMUM_LOTTO_NUMBER, LottoNumber.MAXIMUM_LOTTO_NUMBER) | ||
| .boxed() | ||
| .collect(Collectors.toList()); | ||
|
|
||
| static List<Integer> getLottoBalls() { | ||
| return lottoBalls; | ||
| } | ||
| } |
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,47 @@ | ||
| package step4.domain; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class LottoNumber { | ||
| static final String ALERT_OUT_OF_RANGE_OF_LOTTO_NUMBER = "로또번호는 1부터 45까지의 자연수만 가능합니다."; | ||
| static final int MINIMUM_LOTTO_NUMBER = 1; | ||
| static final int MAXIMUM_LOTTO_NUMBER = 45; | ||
| private int number; | ||
|
|
||
| private LottoNumber(int number) { | ||
| if (isOutOfRange(number)) { | ||
| throw new IllegalArgumentException(ALERT_OUT_OF_RANGE_OF_LOTTO_NUMBER); | ||
| } | ||
| this.number = number; | ||
| } | ||
|
|
||
| public static LottoNumber from(Integer number) { | ||
| return new LottoNumber(number); | ||
| } | ||
|
|
||
| private boolean isOutOfRange(int number) { | ||
| return number < MINIMUM_LOTTO_NUMBER || number > MAXIMUM_LOTTO_NUMBER; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| LottoNumber that = (LottoNumber) o; | ||
| return number == that.number; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(number); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return number + ""; | ||
| } | ||
| } |
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,44 @@ | ||
| package step4.domain; | ||
|
|
||
| import java.util.Arrays; | ||
|
|
||
| public enum LottoRank { | ||
|
|
||
| FIRST_PLACE(6, 2_000_000_000), | ||
| SECOND_PLACE(5, 30_000_000), | ||
| THIRD_PLACE(5, 1_500_000), | ||
| FOURTH_PLACE(4, 50_000), | ||
| FIFTH_PLACE(3, 5_000), | ||
| LOSER(0, 0); | ||
|
|
||
| private int numberOfMatchedToLuckyNumber; | ||
| private int prizeMoney; | ||
|
|
||
| LottoRank(int numberOfMatchedToLuckyNumber, int prizeMoney) { | ||
| this.numberOfMatchedToLuckyNumber = numberOfMatchedToLuckyNumber; | ||
| this.prizeMoney = prizeMoney; | ||
| } | ||
|
|
||
| public static LottoRank from(LottoTicket lottoTicket, LuckyTicket luckyTicket) { | ||
| int countMatchedNumbers = lottoTicket.getNumberOfMatchedToLuckyNumber(luckyTicket); | ||
| boolean isMatchedToBonusNumber = lottoTicket.isBonusNumberMatched(luckyTicket); | ||
|
|
||
| if ((countMatchedNumbers == SECOND_PLACE.numberOfMatchedToLuckyNumber) && isMatchedToBonusNumber) { | ||
| return LottoRank.SECOND_PLACE; | ||
| } | ||
| return Arrays.stream(LottoRank.values()) | ||
| .filter(lottoRank -> lottoRank.numberOfMatchedToLuckyNumber == countMatchedNumbers) | ||
| .filter(lottoRank -> lottoRank.prizeMoney != SECOND_PLACE.prizeMoney) | ||
| .findFirst() | ||
| .orElse(LOSER); | ||
| } | ||
|
|
||
| public int getNumberOfMatchingNumber() { | ||
| return numberOfMatchedToLuckyNumber; | ||
| } | ||
|
|
||
| public int getPrizeMoney() { | ||
| return prizeMoney; | ||
| } | ||
|
|
||
| } |
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 step4.domain; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class LottoSeller { | ||
| static final int PRICE_OF_A_LOTTO_TICKET = 1000; | ||
| static final String ALERT_MISSING_MONEY = "돈을 넣어주세요. 로또복권은 한 장당 1000원 입니다."; | ||
| private static final String ALERT_SHORT_OF_MONEY = "돈이 모자랍니다."; | ||
| private static final String ALERT_NEGATIVE_NUMBER = "구매할 수동로또 개수는 음수가 될 수 없습니다."; | ||
| static final String NUMBER_SEPARATOR = ","; | ||
|
|
||
| public static int countAutoTickets(int inputMoney, int numberOfManualTickets) { | ||
| validationInputData(inputMoney, numberOfManualTickets); | ||
| return (inputMoney / PRICE_OF_A_LOTTO_TICKET) - numberOfManualTickets; | ||
| } | ||
|
|
||
| public static LottoTickets issueLottoTicket(List<String> manualTickets, int numberOfAutoTickets) { | ||
| List<LottoTicket> lottoTickets = new ArrayList<>(); | ||
|
|
||
| for (String manualTicket : manualTickets) { | ||
| List<Integer> parsedManualTicket = parseToNumbers(manualTicket); | ||
| lottoTickets.add(LottoTicketGenerator.issueManualTickets(parsedManualTicket)); | ||
| } | ||
| for (int i = 0; i < numberOfAutoTickets; i++) { //TODO: index i가 사용되지 않고 있음 | ||
| lottoTickets.add(LottoTicketGenerator.issueAutoTickets()); | ||
| } | ||
| return LottoTickets.from(lottoTickets); | ||
| } | ||
|
|
||
| private static List<Integer> parseToNumbers(String manualTicket) { | ||
| return Arrays.stream(manualTicket.split(NUMBER_SEPARATOR)) | ||
| .map(String::trim) | ||
| .mapToInt(Integer::parseInt) | ||
| .boxed() | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| public static LuckyTicket getLuckyNumber(List<Integer> inputLuckyNumber, int bonusNumber) { | ||
| List<LottoNumber> luckyTicket = inputLuckyNumber.stream() | ||
| .map(LottoNumber::from) | ||
| .collect(Collectors.toList()); | ||
| return LuckyTicket.of(luckyTicket, LottoNumber.from(bonusNumber)); | ||
| } | ||
|
|
||
| private static void validationInputData(int inputMoney, int numberOfManualTickets) { | ||
| if (inputMoney < PRICE_OF_A_LOTTO_TICKET) { | ||
| throw new IllegalArgumentException(ALERT_MISSING_MONEY); | ||
| } | ||
| if (numberOfManualTickets < 0) { | ||
| throw new IllegalArgumentException(ALERT_NEGATIVE_NUMBER); | ||
| } | ||
| if (numberOfManualTickets * PRICE_OF_A_LOTTO_TICKET > inputMoney) { | ||
| throw new IllegalArgumentException(ALERT_SHORT_OF_MONEY); | ||
| } | ||
| } | ||
| } |
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,69 @@ | ||
| package step4.domain; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
|
|
||
| public class LottoTicket { | ||
| static final String ALERT_NUMBER_OVERLAP = "중복된 로또 번호가 존재합니다."; | ||
| static final String AlERT_DIFFERENT_SIZE_OF_NUMBERS = "로또번호의 개수가 6개가 아닙니다."; | ||
|
|
||
| private final List<LottoNumber> lottoTicket; | ||
|
|
||
| LottoTicket(List<LottoNumber> lottoTicket) { | ||
| validationNumberSize(lottoTicket); | ||
| validationNumberOverlap(lottoTicket); | ||
| this.lottoTicket = lottoTicket; | ||
| } | ||
|
|
||
| public int getNumberOfMatchedToLuckyNumber(LuckyTicket luckyTicket) { | ||
| return (int) luckyTicket.getLuckyNumber().stream() | ||
| .filter(lottoTicket::contains) | ||
| .count(); | ||
| } | ||
|
|
||
| boolean isBonusNumberMatched(LuckyTicket luckyTicket) { | ||
| return luckyTicket.checkBonusNumber(lottoTicket); | ||
| } | ||
|
|
||
| private void validationNumberSize(List<LottoNumber> lottoTicket) { | ||
| if (lottoTicket.size() != LottoTicketGenerator.BASIC_LOTTO_SIZE) { | ||
| throw new IllegalArgumentException(AlERT_DIFFERENT_SIZE_OF_NUMBERS); | ||
| } | ||
| } | ||
|
|
||
| private void validationNumberOverlap(List<LottoNumber> lottoTicket) { | ||
| long SizeOfLottoTicket = lottoTicket.stream() | ||
| .mapToLong(LottoNumber::getNumber) | ||
| .distinct() | ||
| .count(); | ||
|
|
||
| if (SizeOfLottoTicket != LottoTicketGenerator.BASIC_LOTTO_SIZE) { | ||
| throw new IllegalArgumentException(ALERT_NUMBER_OVERLAP); | ||
| } | ||
| } | ||
|
|
||
| public List<LottoNumber> getLottoTicket() { | ||
| return Collections.unmodifiableList(lottoTicket); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| LottoTicket that = (LottoTicket) o; | ||
| return Objects.equals(lottoTicket, that.lottoTicket); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(lottoTicket); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "LottoTicket{" + | ||
| "lottoTicket=" + lottoTicket + | ||
| '}'; | ||
| } | ||
| } |
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,34 @@ | ||
| package step4.domain; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| public class LottoTicketGenerator { | ||
| static final int BASIC_LOTTO_SIZE = 6; | ||
|
|
||
| static LottoTicket issueAutoTickets() { | ||
| return new LottoTicket(pickLottoBalls(LottoBalls.getLottoBalls())); | ||
| } | ||
|
|
||
| static LottoTicket issueManualTickets(List<Integer> manualTicket) { | ||
| return new LottoTicket(manualTicket.stream() | ||
| .sorted() | ||
| .map(LottoNumber::from) | ||
| .collect(Collectors.toList())); | ||
| } | ||
|
|
||
| static List<LottoNumber> pickLottoBalls(List<Integer> lottoBalls) { | ||
| shuffleLottoBalls(lottoBalls); | ||
| return lottoBalls.stream() | ||
| .limit(BASIC_LOTTO_SIZE) | ||
| .sorted() | ||
| .map(LottoNumber::from) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
| static void shuffleLottoBalls(List<Integer> lottoBalls) { | ||
| Collections.shuffle(lottoBalls); | ||
| } | ||
|
|
||
| } |
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,20 @@ | ||
| package step4.domain; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class LottoTickets { | ||
| private final List<LottoTicket> lottoTickets; | ||
|
|
||
| private LottoTickets(List<LottoTicket> lottoTickets) { | ||
| this.lottoTickets = lottoTickets; | ||
| } | ||
|
|
||
| public static LottoTickets from(List<LottoTicket> lottoTickets) { | ||
| return new LottoTickets(lottoTickets); | ||
| } | ||
|
|
||
| public List<LottoTicket> getLottoTickets() { | ||
| return Collections.unmodifiableList(lottoTickets); | ||
| } | ||
| } |
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,26 @@ | ||
| package step4.domain; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| public class LuckyTicket { | ||
| private final List<LottoNumber> luckyNumber; | ||
| private final LottoNumber bonusNumber; | ||
|
|
||
| private LuckyTicket(List<LottoNumber> luckyNumber, LottoNumber bonusNumber) { | ||
| this.luckyNumber = luckyNumber; | ||
| this.bonusNumber = bonusNumber; | ||
| } | ||
|
|
||
| static LuckyTicket of(List<LottoNumber> luckyNumber, LottoNumber bonusNumber) { | ||
| return new LuckyTicket(luckyNumber, bonusNumber); | ||
| } | ||
|
|
||
| public List<LottoNumber> getLuckyNumber() { | ||
| return Collections.unmodifiableList(luckyNumber); | ||
| } | ||
|
|
||
| boolean checkBonusNumber(List<LottoNumber> lottoTicket) { | ||
| return lottoTicket.contains(bonusNumber); | ||
| } | ||
| } |
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.
ㅠㅠ 패키지를 스텝별로 새로 만들면서 해서 그런 것 같습니다..
단계별 코드를 한 곳에 저장해두려고 그렇게 만들었는데 리뷰하시기에 불편하셨을 것 같네요..