-
Notifications
You must be signed in to change notification settings - Fork 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
[Lee, Nathan] 로또 2단계 - 보너스 번호 추가 #41
Open
nathan29849
wants to merge
19
commits into
codesquad-members-2022:nathan29849
Choose a base branch
from
nathan29849:step-2
base: nathan29849
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.
+332
−155
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
97da692
[step2] 시작
nathan29849 edf45b6
[step2] Enum 클래스 이름 변경(Rank) 및 switch문 Enum 클래스 내부로 이동
nathan29849 c59c7d5
[step2] makeAutoTicket(), makeManualTicket 분리해 수동 추첨 구현
street62 f438af0
[step2] 보너스 볼 기능 추가
nathan29849 cedce92
[step2] recactoring : 당첨 티켓과 현재 로또 티켓을 비교하는 기능을 TicketOffice에서 LottoT…
nathan29849 0a0f20d
[step2] 로또 자동/수동 입력 오류 수정
street62 2be4b31
[step2] TicketOffice 클래스 자동/수동 설정 리팩토링
street62 00a3220
[step2] TicketOffice.checkBonusNumber() -> LottoTicket.checkBonusNumb…
nathan29849 7162394
[step2] TicketOffice 클래스의 당첨 관련 기능을 LottoCompany 클래스로 분리
street62 ff671c5
[step2] User 클래스 추가
street62 2778b9a
[step2] LottoCompany 클래스를 통해 User에서 당첨 정보를 조회
nathan29849 a89c370
[step2] Rank 수정, 당첨 통계 Map key Integer -> Rank 수정
street62 6cc42b8
[step2] OutputView.showWinningResult 개선
nathan29849 8cc12ad
[step2] Rank 클래스 리팩토링 : checkBonus 메서드를 통해 indent를 줄임
nathan29849 68655b3
[step2] Rank 클래스에 FAIL 추가
nathan29849 c988010
[step3] 수동 티켓 개수 입력 받은 후 한꺼번에 생성하는 기능 구현
nathan29849 643fd1f
[step3] AutoTicketOffice, ManualTicketOffice 클래스 추가
street62 01591d8
[step3] User.goTicketOffice 메서드 구현
nathan29849 a2bed80
[step3] README 3단계 수동구매 기능 추가 관련 정보 기입
nathan29849 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
[step2] Rank 수정, 당첨 통계 Map key Integer -> Rank 수정
Enum 클래스인 Rank를 수정해 boolean 값인 isBonus를 가지고 있게 하고, LottoCompany의 멤버변수 statisctic의 key를 Rank로 변경.
commit a89c370ec0d8fbbaa9627e2023bc709eacd4bdd8
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,12 +1,16 @@ | ||
view/InputView.java | ||
view.InputView | ||
Main.java | ||
Main | ||
domain/Rank.java | ||
domain.Rank | ||
view/OutputView.java | ||
view.OutputView | ||
domain/LottoTicket.java | ||
domain.LottoTicket | ||
Main.java | ||
Main | ||
view/InputView.java | ||
view.InputView | ||
domain/User.java | ||
domain.User | ||
domain/TicketOffice.java | ||
domain.TicketOffice | ||
domain/LottoCompany.java | ||
domain.LottoCompany |
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 |
---|---|---|
|
@@ -10,13 +10,13 @@ public class LottoCompany { | |
private int bonusNumber; | ||
private int totalPrice; | ||
private final int PRICE = 1000; | ||
private final Map<Integer, Integer> statistics = new HashMap<>(); | ||
{ | ||
statistics.put(3, 0); | ||
statistics.put(4, 0); | ||
statistics.put(5, 0); | ||
statistics.put(6, 0); | ||
statistics.put(7, 0); | ||
private final Map<Rank, Integer> statistics = new HashMap<>(); | ||
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.
|
||
|
||
|
||
public void setInitialStatistic() { | ||
for (Rank rank : Rank.values()) { | ||
statistics.put(rank, 0); | ||
} | ||
} | ||
|
||
public void check(List<LottoTicket> tickets){ | ||
|
@@ -35,13 +35,14 @@ public void setBonusNumber() { // 추후 당첨 번호에 없는 번호만 받 | |
} | ||
|
||
public void getStatistic(List<LottoTicket> tickets) { | ||
setInitialStatistic(); | ||
int matchedNumber; | ||
boolean isBonus; | ||
for (LottoTicket ticket : tickets) { | ||
matchedNumber = ticket.comparisonWinningTicket(this.winningTicket); | ||
isBonus = ticket.checkBonusNumber(this.bonusNumber); | ||
matchedNumber += addMatchedForBonus(matchedNumber, isBonus); | ||
statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); | ||
Rank currentRank = Rank.designateRank(matchedNumber, isBonus); | ||
statistics.computeIfPresent(currentRank, (k, v) -> v + 1); | ||
} | ||
OutputView.showWinningResult(this.statistics, calculateProfit()); | ||
} | ||
|
@@ -55,13 +56,10 @@ private int addMatchedForBonus(int matchedNumber, boolean isBonus){ | |
|
||
public double calculateProfit() { | ||
int totalPrize = 0; | ||
for (int matchedNumber : this.statistics.keySet()) { | ||
totalPrize += (switchPrize(matchedNumber) * statistics.get(matchedNumber)); | ||
for (Rank rank : this.statistics.keySet()) { | ||
totalPrize += rank.getPrize() * statistics.get(rank); | ||
} | ||
return ((double) (totalPrize - totalPrice) / totalPrice) * 100; | ||
} | ||
|
||
private int switchPrize(int matchedNumber) { | ||
return Rank.designateRank(matchedNumber).getPrize(); | ||
} | ||
} |
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
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.
인스턴스 변수인데 대문자로 선언되어 있고 값도 부여되어 있군요.
제 생각에 이 변수는 인스턴스 변수로 관리할 것이 아니라
static
키워드를 추가로 부여해서 런타임 상수로 보존하는 게 좋을 것 같군요.