-
Notifications
You must be signed in to change notification settings - Fork 4
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
[Step2] 로또 - 2등 #7
base: doy
Are you sure you want to change the base?
Changes from all commits
96a4705
ae662ec
871a410
f4b9a22
01fe553
baa60b7
af9a159
6630221
7f1d8e0
edba06a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
import java.util.List; | ||
|
||
public class LottoSeller { | ||
private static final int PRICE = 1000; | ||
public static final int UNIT_PRICE = 1000; | ||
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. 로또의 가격은 변경의 여지가 있으니, 외부에서 주입받을 수 있을 것 같습니다. |
||
|
||
private final NumberGenerator numberGenerator; | ||
|
||
|
@@ -11,8 +11,10 @@ public LottoSeller(final NumberGenerator numberGenerator) { | |
} | ||
|
||
public List<Ticket> buyTickets(final int money) { | ||
if (money < UNIT_PRICE) throw new IllegalArgumentException(UNIT_PRICE + "원 이상 구매해야 합니다"); | ||
|
||
List<Ticket> tickets = new ArrayList<>(); | ||
for (int i = 0; i < money / PRICE; i++) { | ||
for (int i = 0; i < money / UNIT_PRICE; i++) { | ||
tickets.add(new Ticket(LottoNumbers.of(numberGenerator.generate()))); | ||
} | ||
return tickets; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,30 @@ | ||
public enum Rank { | ||
FIRST(6, 2000000000), | ||
SECOND(5, 1500000), | ||
THIRD(4, 50000), | ||
FOURTH(3, 5000); | ||
FIRST(6, false, 2000000000), | ||
SECOND(5, true, 30000000), | ||
THIRD(5, false, 1500000), | ||
FOURTH(4, false, 50000), | ||
FIFTH(3, false, 5000), | ||
MISS(0, false, 0); | ||
|
||
private static final int WINNING_MIN_COUNT = 3; | ||
|
||
private int countOfMatch; | ||
private boolean isBonusMatch; | ||
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. 이런 전략을 하나로 추상화할 수 없을까요? |
||
private int prizeMoney; | ||
|
||
Rank(final int countOfMatch, final int prizeMoney) { | ||
Rank(final int countOfMatch, final boolean isBonusMatch, final int prizeMoney) { | ||
this.countOfMatch = countOfMatch; | ||
this.isBonusMatch = isBonusMatch; | ||
this.prizeMoney = prizeMoney; | ||
} | ||
|
||
public static Rank valueOf(final int countOfMatch) { | ||
public static Rank valueOf(final int countOfMatch, final boolean isBonusMatch) { | ||
if (countOfMatch < WINNING_MIN_COUNT) { | ||
return MISS; | ||
} | ||
|
||
for (final Rank rank : Rank.values()) { | ||
if (rank.countOfMatch == countOfMatch) { | ||
if (rank.countOfMatch == countOfMatch && rank.isBonusMatch == isBonusMatch) { | ||
return rank; | ||
} | ||
} | ||
|
@@ -26,4 +36,9 @@ public int getPrizeMoney() { | |
return prizeMoney; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
if (this.equals(SECOND)) return String.format("%d개 일치, 보너스 볼 일치 (%d원)", countOfMatch, prizeMoney); | ||
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. 한국어가 아니라 영어로 출력되는 경우에 대해 확장성있는 구조는 어떻게 가져가야할까요? 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. https://github.com/WeareSoft/java-lotto/pull/7/files#r368273623 |
||
return String.format("%d개 일치 (%d원)", countOfMatch, prizeMoney); | ||
} | ||
} |
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.
극단적으로는 출력하는 책임도 분리할 수 있을것 같습니다. 소리나 이미지로 출력하는 것 처럼요. (
@toString
오버라이딩 전반)(변경안 아님)