-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[Step5] 로또(수동) #1698
Merged
Merged
[Step5] 로또(수동) #1698
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
25e09db
feat: 수동입력된 티켓 추가
LenKIM b9f884b
feat: int 값을 LottoNo 으로 변경
LenKIM b387a03
refactor: rename LottoNo.java > LottoNumber.java
LenKIM 6058761
refactor: tickets.sizeOfXXXTickets 메소드 체이닝 분리
LenKIM e330b47
fix: 당첨되지 되지 않은 경우 테스트 코드 추가
LenKIM File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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,51 @@ | ||
package lottery; | ||
|
||
import java.util.Objects; | ||
|
||
public class LottoNumber implements Comparable<LottoNumber> { | ||
|
||
private int value; | ||
|
||
public static LottoNumber of(int value) { | ||
return new LottoNumber(value); | ||
} | ||
|
||
public static LottoNumber of(String value) { | ||
return new LottoNumber(Integer.parseInt(value)); | ||
} | ||
|
||
private LottoNumber(int value) { | ||
setValue(value); | ||
} | ||
|
||
public int value() { | ||
return value; | ||
} | ||
|
||
private void setValue(int value) { | ||
if (value <= 0 || value > 45) { | ||
throw new IllegalArgumentException("유효하지 않는 숫자입니다."); | ||
} | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (!(o instanceof LottoNumber)) | ||
return false; | ||
LottoNumber lottoNumber = (LottoNumber)o; | ||
return value == lottoNumber.value; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(value); | ||
} | ||
|
||
@Override | ||
public int compareTo(LottoNumber o) { | ||
return Integer.compare(this.value, o.value); | ||
} | ||
} |
This file contains 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 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,54 +1,85 @@ | ||
package lottery; | ||
|
||
import java.util.Arrays; | ||
import java.util.LinkedHashSet; | ||
import java.util.ArrayList; | ||
import java.util.InputMismatchException; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.Scanner; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import lottery.view.InputView; | ||
import lottery.view.ResultView; | ||
|
||
public class Main { | ||
|
||
private static InputView inputView; | ||
private static ResultView resultView; | ||
private static Scanner sc; | ||
private static Store store; | ||
private static InfoCenter infoCenter; | ||
|
||
public static void init(){ | ||
inputView = new InputView(); | ||
resultView = new ResultView(); | ||
sc = new Scanner(System.in); | ||
store = new Store(); | ||
infoCenter = new InfoCenter(); | ||
} | ||
public static void main(String[] args) { | ||
init(); | ||
private static final InputView inputView = new InputView(); | ||
private static final ResultView resultView = new ResultView(); | ||
private static final Scanner sc = new Scanner(System.in); | ||
private static final Store store = new Store(); | ||
private static final InfoCenter infoCenter = new InfoCenter(); | ||
|
||
public static void main(String[] args) { | ||
inputView.askForBuyerMoney(); | ||
Money initialMoney = Money.won(Long.parseLong(sc.nextLine().trim())); | ||
Money initialMoney = Money.won(getLongValue()); | ||
Buyer buyer = Buyer.of(initialMoney); | ||
|
||
buyer.buyTicket(store); | ||
inputView.askForManualTicketCount(); | ||
int manualTicketQuantity = getIntegerValue(); | ||
|
||
inputView.askForManualTicketNumbers(); | ||
Tickets manualTickets = getManualTickets(manualTicketQuantity); | ||
buyer.buyTicket(store, manualTickets); | ||
|
||
Tickets tickets = buyer.tickets(); | ||
inputView.inputCountOfTickets(tickets.size()); | ||
inputView.inputCountOfTickets(tickets.sizeOfManualTickets(), tickets.sizeOfAutoTickets()); | ||
inputView.printTickets(tickets); | ||
|
||
inputView.askForLastWeekTickets(); | ||
Set<Integer> ints = Arrays.stream(sc.nextLine().split(",")) | ||
.map(a -> Integer.parseInt(a.trim())) | ||
.sorted() | ||
.collect(Collectors.toCollection(LinkedHashSet::new)); | ||
Ticket lastWeekTicket = Ticket.of(LottoNumbers.from(ints)); | ||
Ticket lastWeekTicket = Ticket.of(LottoNumbers.from(sc.nextLine().split(",")), TicketType.WINNING); | ||
|
||
inputView.askForBonusNumber(); | ||
int bonus = Integer.parseInt(sc.nextLine().trim()); | ||
infoCenter.setLastWeekWinningTicket(new WinningTicket(lastWeekTicket, bonus)); | ||
infoCenter.setLastWeekWinningTicket(new WinningTicket(lastWeekTicket, LottoNumber.of(bonus))); | ||
|
||
Result result = buyer.checkTicket(infoCenter); | ||
|
||
float totalYield = result.getTotalYield(initialMoney); | ||
resultView.printResult(result, totalYield); | ||
} | ||
|
||
private static Tickets getManualTickets(int manualTicketQuantity) { | ||
List<Ticket> tickets = new ArrayList<>(); | ||
for (int i = 0; i < manualTicketQuantity; i++) { | ||
String s = sc.nextLine(); | ||
tickets.add(Ticket.of(LottoNumbers.from(s.split(",")), TicketType.MANUAL)); | ||
} | ||
return Tickets.of(tickets); | ||
} | ||
|
||
private static long getLongValue() { | ||
try { | ||
return sc.nextLong(); | ||
} catch (InputMismatchException e) { | ||
throw new IllegalArgumentException("정수를 입력해주세요.", e); | ||
} | ||
} | ||
|
||
private static int getIntegerValue() { | ||
try { | ||
return sc.nextInt(); | ||
} catch (InputMismatchException e) { | ||
throw new IllegalArgumentException("정수를 입력해주세요.", e); | ||
} finally { | ||
sc.nextLine(); | ||
} | ||
} | ||
|
||
private static String getStringValue() { | ||
try { | ||
return sc.nextLine(); | ||
} catch (NoSuchElementException e) { | ||
throw new IllegalArgumentException("6자리에 콤마(,)로 구분된 숫자를 입력해주세요", e); | ||
} finally { | ||
sc.nextLine(); | ||
} | ||
} | ||
} |
This file contains 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 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
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.
머지 전에 전체적인 코드를 한번 훑어봤는데 아래 부분에 궁금한 점이 있어 코멘트 남깁니다.
java-lotto/src/main/java/lottery/LotteryMatchTypeMap.java
Line 22 in b9f884b
파일 체인지론 잡히지 않아서 링크를 걸었어요.
위 부분에서 아래와 같이 검증해주는 부분이 있는데
Map에 데이터가 하나도 없는 경우도 아래와 같이 출력되어야 하지 않을까요?
위와 같이 처리하면 예외가 발생할 것 같아서요.
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.
맞네요 👍 테스트 케이스가 빈약하네요. 테스트 코드 추가 후, 코드 변경하겠습니다ㅎ