-
Notifications
You must be signed in to change notification settings - Fork 550
[π μ¬μ΄ν΄2 - λ―Έμ (λΈλμ κ²μ μ€ν)] νΌλ Έ λ―Έμ μ μΆν©λλ€. #1110
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
base: haechanmoon
Are you sure you want to change the base?
Changes from all commits
7aef3ba
54dbcba
8624763
2cef230
0e6ffe3
753590b
7c62216
1d483ff
da80618
127aaff
9b22cf9
681efe8
5064275
9658184
4637666
a3d7370
a832282
94facb9
77cbf6b
e2b01f2
66b64b6
f7400b7
08d7412
48a5ff6
b2400f3
9710ffc
9862c6b
05ef636
968ab8d
6642920
bda49a8
c9736a6
1f8b7d7
aa1061b
fa92f80
efc4365
1620c41
5cce321
4779a7c
a85e9e7
8ced443
a9afe86
8112c4f
b4f0ab9
355dae3
69b9c02
6223f4a
2471177
c43bd56
edc46dd
f1ddbaa
3a79b03
c8ef898
2c0ceb1
2fa58d6
5c7c892
8395e88
025c647
117fa4c
3ecb6b2
a2685b0
08ac63d
64bb84d
e2cd122
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 |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package domain; | ||
|
|
||
| import exception.BlackjackException; | ||
| import exception.ExceptionMessage; | ||
|
|
||
| public class BettingMoney { | ||
| private final int money; | ||
|
Comment on lines
+6
to
+7
Member
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. BettingMoneyλ₯Ό μμκ° ν¬μ₯νκ΅°μ π BettingMoneyκ° VO λλ €λ©΄ μ΄λ€ μ‘°κ±΄μ΄ νμν κΉμ? |
||
|
|
||
| public BettingMoney(int money) { | ||
| validateMoney(money); | ||
| validateMoneyUnit(money); | ||
| this.money = money; | ||
| } | ||
|
|
||
| private void validateMoneyUnit(int money) { | ||
| if (money % 100 != 0) { | ||
| throw new BlackjackException(ExceptionMessage.MONEY_UNIT_ERROR); | ||
| } | ||
| } | ||
|
|
||
| private void validateMoney(int money) { | ||
| if (money < 1000) { | ||
| throw new BlackjackException(ExceptionMessage.MONEY_INPUT_ERROR); | ||
| } | ||
| } | ||
|
|
||
| public int getMoney() { | ||
| return this.money; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
| package domain; | ||
|
|
||
| public enum MatchResult { | ||
| WIN("μΉ"), | ||
| LOSE("ν¨"), | ||
| DRAW("무"); | ||
| BLACKJACK("λΈλμ", 1.5), | ||
|
Member
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. BLACKJACKμΌλ‘ μ΄κΈ°λ κ²½μ°κ° μμ΄μ~ |
||
| WIN("μΉ", 1.0), | ||
| LOSE("ν¨", -1.0), | ||
| DRAW("무", 0.0); | ||
|
|
||
| private final String name; | ||
| private final double ratio; | ||
|
|
||
| MatchResult(String name) { | ||
| MatchResult(String name, double ratio) { | ||
| this.name = name; | ||
| this.ratio = ratio; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public int calculateIncome(BettingMoney bettingMoney) { | ||
|
Member
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. μ μ ν λ©μλλ€μ! π |
||
| return (int) (this.ratio * bettingMoney.getMoney()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,33 @@ | ||
| package domain.player; | ||
|
|
||
| import domain.MatchResult; | ||
| import domain.deck.Deck; | ||
| import dto.BlackjackResult; | ||
| import expcetion.BlackjackException; | ||
| import expcetion.ExceptionMessage; | ||
| import java.util.ArrayList; | ||
| import exception.BlackjackException; | ||
| import exception.ExceptionMessage; | ||
| import java.util.HashSet; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| public class Gamblers { | ||
| private final List<Gambler> gamblers; | ||
|
|
||
| public Gamblers(List<String> names) { | ||
| validateNonDuplicate(names); | ||
| gamblers = new ArrayList<>(); | ||
| init(names); | ||
| public Gamblers(List<Gambler> gamblers) { | ||
| validateNonDuplicateNames(gamblers); | ||
| this.gamblers = gamblers; | ||
| } | ||
|
|
||
| private void validateNonDuplicate(List<String> names) { | ||
| Set<String> namesSet = new HashSet<>(names); | ||
| if (namesSet.size() != names.size()) { | ||
| private void validateNonDuplicateNames(List<Gambler> gamblers) { | ||
| List<String> names = gamblers.stream() | ||
| .map(Gambler::getName) | ||
| .toList(); | ||
|
|
||
| Set<String> targetNames = new HashSet<>(names); | ||
| if (targetNames.size() != names.size()) { | ||
| throw new BlackjackException(ExceptionMessage.INPUT_ERROR); | ||
| } | ||
| } | ||
|
|
||
| private void init(List<String> names) { | ||
| names.stream().map(Gambler::new).forEach(gamblers::add); | ||
| } | ||
|
|
||
| public List<Gambler> getGamblers() { | ||
| return gamblers; | ||
| } | ||
|
|
@@ -38,21 +36,22 @@ public void dealAll(Deck deck) { | |
| gamblers.forEach(gambler -> gambler.deal(deck)); | ||
| } | ||
|
|
||
| public BlackjackResult getResult(Dealer dealer) { | ||
| int winCount = 0; | ||
| int loseCount = 0; | ||
| List<String> logs = new ArrayList<>(); | ||
| public Map<String, Integer> getResult(Dealer dealer) { | ||
| Map<String, Integer> gamblersResult = new LinkedHashMap<>(); | ||
| for (Gambler gambler : gamblers) { | ||
| String name = gambler.getName(); | ||
| int finalIncomeMoney = gambler.calculateFinalIncome(dealer); | ||
| gamblersResult.put(name, finalIncomeMoney); | ||
| } | ||
| return gamblersResult; | ||
| } | ||
|
|
||
| public int dealerFinalIncome(Dealer dealer) { | ||
| int dealerFinalIncome = 0; | ||
| for (Gambler gambler : gamblers) { | ||
| MatchResult result = gambler.getResult(dealer); | ||
| if (result == MatchResult.WIN) { | ||
| loseCount++; | ||
| } | ||
| if (result == MatchResult.LOSE) { | ||
| winCount++; | ||
| } | ||
| logs.add(gambler.showResult(result)); | ||
| dealerFinalIncome += gambler.calculateFinalIncome(dealer); | ||
|
Comment on lines
+43
to
+52
Member
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. gambler.calculateFinalIncome(dealer) λ₯Ό μ€λ³΅μΌλ‘ κ³μ°ν΄μΌνλ κ² λΉν¨μ¨μ μΈ κ² κ°μμ. Gamblersκ° κΌ μ΅μ’ λ°°ν κ²°κ³ΌκΉμ§ κ³μ°ν΄μΌν κΉμ? getterλ₯Ό μμ°κΈ° μν΄ μ΄λ° λ©μλλ₯Ό λ§λ κ² κ°μμ. Gamblersλ μ΄λ€ κΈ°λ₯κΉμ§ μ 곡νλ κ²μ΄ μ’μκΉ? λ₯Ό κ³ λ―Όν΄λ³΄λ©΄ μ’μ κ² κ°μμ. getterλ μμ»μ§λ§ μ€νλ € Gamblersμ Dealerμ μμ‘΄μ±μ΄ μκΈ°κ³ λ°°ν κ²°κ³ΌκΉμ§ κ³μ°νλ©΄μ μ± μμ΄ λ 컀μ‘μ΄μ. |
||
| } | ||
| return new BlackjackResult(winCount, loseCount, gamblers.size() - winCount - loseCount, logs); | ||
| return dealerFinalIncome * -1; | ||
| } | ||
|
|
||
| public List<String> getNames() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| package expcetion; | ||
| package exception; | ||
|
|
||
| public class BlackjackException extends IllegalArgumentException { | ||
|
|
||
|
|
||
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.
GamblersκΉμ§ λ§λ€μ΄λ μ’μ κ² κ°μμ!