Skip to content
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
wants to merge 19 commits into
base: nathan29849
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
97da692
[step2] 시작
nathan29849 Feb 23, 2022
edf45b6
[step2] Enum 클래스 이름 변경(Rank) 및 switch문 Enum 클래스 내부로 이동
nathan29849 Feb 23, 2022
c59c7d5
[step2] makeAutoTicket(), makeManualTicket 분리해 수동 추첨 구현
street62 Feb 23, 2022
f438af0
[step2] 보너스 볼 기능 추가
nathan29849 Feb 23, 2022
cedce92
[step2] recactoring : 당첨 티켓과 현재 로또 티켓을 비교하는 기능을 TicketOffice에서 LottoT…
nathan29849 Feb 23, 2022
0a0f20d
[step2] 로또 자동/수동 입력 오류 수정
street62 Feb 23, 2022
2be4b31
[step2] TicketOffice 클래스 자동/수동 설정 리팩토링
street62 Feb 23, 2022
00a3220
[step2] TicketOffice.checkBonusNumber() -> LottoTicket.checkBonusNumb…
nathan29849 Feb 23, 2022
7162394
[step2] TicketOffice 클래스의 당첨 관련 기능을 LottoCompany 클래스로 분리
street62 Feb 24, 2022
ff671c5
[step2] User 클래스 추가
street62 Feb 24, 2022
2778b9a
[step2] LottoCompany 클래스를 통해 User에서 당첨 정보를 조회
nathan29849 Feb 24, 2022
a89c370
[step2] Rank 수정, 당첨 통계 Map key Integer -> Rank 수정
street62 Feb 24, 2022
6cc42b8
[step2] OutputView.showWinningResult 개선
nathan29849 Feb 24, 2022
8cc12ad
[step2] Rank 클래스 리팩토링 : checkBonus 메서드를 통해 indent를 줄임
nathan29849 Feb 24, 2022
68655b3
[step2] Rank 클래스에 FAIL 추가
nathan29849 Feb 24, 2022
c988010
[step3] 수동 티켓 개수 입력 받은 후 한꺼번에 생성하는 기능 구현
nathan29849 Feb 25, 2022
643fd1f
[step3] AutoTicketOffice, ManualTicketOffice 클래스 추가
street62 Feb 25, 2022
01591d8
[step3] User.goTicketOffice 메서드 구현
nathan29849 Feb 25, 2022
a2bed80
[step3] README 3단계 수동구매 기능 추가 관련 정보 기입
nathan29849 Feb 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[step2] Rank 수정, 당첨 통계 Map key Integer -> Rank 수정
Enum 클래스인 Rank를 수정해 boolean 값인 isBonus를 가지고 있게 하고, LottoCompany의 멤버변수 statisctic의 key를 Rank로 변경.
street62 committed Feb 24, 2022
commit a89c370ec0d8fbbaa9627e2023bc709eacd4bdd8
Binary file modified .gradle/6.7/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/6.7/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/6.7/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/6.7/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/6.7/javaCompile/classAnalysis.bin
Binary file not shown.
Binary file modified .gradle/6.7/javaCompile/javaCompile.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
12 changes: 8 additions & 4 deletions build/tmp/compileJava/source-classes-mapping.txt
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
26 changes: 12 additions & 14 deletions src/main/java/domain/LottoCompany.java
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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인스턴스 변수인데 대문자로 선언되어 있고 값도 부여되어 있군요.
제 생각에 이 변수는 인스턴스 변수로 관리할 것이 아니라 static 키워드를 추가로 부여해서 런타임 상수로 보존하는 게 좋을 것 같군요.

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<>();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

statistics 라는 것이 제가 이해하기론 몇 등짜리가 몇 장 당첨되었느냐를 알려주면 되는 부분인 것 같네요.
그렇다면 굳이 Map 형태로 보관할 필요 있을까요?
필요할 때마다 List<LottoTicket> 을 순회하며 계산하면 될 것 같기도 한데요? 자신이 몇 등 당첨되었는지는 LottoTicket 이 직접 말하게 하면 되고요.



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();
}
}
20 changes: 11 additions & 9 deletions src/main/java/domain/Rank.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package domain;

public enum Rank {
FIFTH(3, 5_000),
FORTH(4, 50_000),
THIRD(5, 1_500_000),
SECOND(7, 30_000_000),
FIRST(6, 2_000_000_000);
FIFTH(3, 5_000, false),
FORTH(4, 50_000, false),
THIRD(5, 1_500_000, false),
SECOND(5, 30_000_000, true),
FIRST(6, 2_000_000_000, false);

private final int matchedNumber;
private final int prize;
private final boolean isBonus;

private Rank(int matchedNumber, int prize) {
private Rank(int matchedNumber, int prize, boolean isBonus) {
this.matchedNumber = matchedNumber;
this.prize = prize;
this.isBonus = isBonus;
}

public int getMatchedNumber() {
@@ -23,16 +25,16 @@ public int getPrize() {
return prize;
}

public static Rank designateRank(int matchedNumber) {
public static Rank designateRank(int matchedNumber, boolean isBonus) {
switch (matchedNumber) {
case 3:
return FIFTH;
case 4:
return FORTH;
case 5:
if (isBonus)
return SECOND;
return THIRD;
case 7:
return SECOND;
default:
return FIRST;
}
2 changes: 1 addition & 1 deletion src/main/java/view/OutputView.java
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ public static void completePurchase(int numberOfTickets, int change, List<LottoT
}
}

public static void showWinningResult(Map<Integer, Integer> statistics, double profitRate) {
public static void showWinningResult(Map<Rank, Integer> statistics, double profitRate) {
StringBuilder sb = new StringBuilder();
int matchedNumber;
int prize;