-
Notifications
You must be signed in to change notification settings - Fork 550
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๋ฒ ํ )] ์ฃผ๋ ๋ฏธ์ ์ ์ถํฉ๋๋ค. #1122
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: haeseonlee
Are you sure you want to change the base?
Changes from all commits
42b0ddd
1efb71c
bfcb4f2
85f5769
fca8b22
af2d198
1c0939a
318db5b
3235007
ebd112a
b0cf709
11bb5f7
ce7705a
b3e49dc
2e3e0f2
e4824d7
1b492ba
9be7e57
414e765
081cb1c
61ef165
0f1a896
9f2eba0
ca323a5
81dbce6
ca3350e
72d918e
9d4143d
2d0dfb1
7caf5d0
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,14 @@ | ||
| package blackjack.domain; | ||
|
|
||
| public class Money { | ||
|
|
||
| private final int bettingMoney; | ||
|
|
||
| public Money(int bettingMoney) { | ||
| this.bettingMoney = bettingMoney; | ||
|
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.
๊ทธ๋ฆฌ๊ณ ๋ฐฐํ
๊ธ์ก์ด
Author
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. Money ํด๋์ค์ 0์ด๋ ์์๊ฐ ์ ๋ ฅ๋ ๊ฒฝ์ฐ ์์ธ๋ฅผ ๋ฐ์์ํค๋๋ก ์์ ํ์ต๋๋ค! ๋ฒ ํ ๊ธ์ก์ ์ต ๋จ์๋ฅผ ๋์ด๊ฐ ์๋ ์๋ค๋ ์ ์ ๊ณ ๋ คํ์ง ๋ชปํ๊ณ int ํ์ ์ ์ฌ์ฉํ์๋๋ฐ, ํผ๋๋ฐฑ์ ๋ฐ์ํ์ฌ ๋ ํฐ ๊ธ์ก๋ ์์ฉ ๊ฐ๋ฅํ long ํ์ ์ผ๋ก ๋ฆฌํฉํฐ๋ง์ ์งํํ์ต๋๋ค. |
||
| } | ||
|
|
||
| public int getBettingMoney() { | ||
| return bettingMoney; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package blackjack.domain; | ||
|
|
||
| public class Name { | ||
| private final String name; | ||
|
|
||
| public Name(String name) { | ||
| validate(name); | ||
| this.name = name; | ||
| } | ||
|
|
||
| private void validate(String name) { | ||
| if (name == null || name.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("[ERROR] ์ด๋ฆ์ ์ ํํ๊ฒ ์ ๋ ฅํด์ฃผ์ธ์."); | ||
| } | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,24 +5,19 @@ | |
|
|
||
| public abstract class Participant { | ||
|
|
||
| protected final String name; | ||
| private static final int BLACKJACK_SCORE = 21; | ||
|
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.
๋ธ๋์ญ ์ ์ 21์ด๋ผ๋ ๊ฐ๋
์ ์นด๋ ํฉ๊ณ๋ฅผ ๋ค๋ฃจ๋ |
||
| private static final int BLACKJACK_SIZE = 2; | ||
|
|
||
| protected final Name name; | ||
| protected final Cards drawnCards; | ||
|
|
||
| protected Participant(String name) { | ||
| this.name = name; | ||
| this.name = new Name(name); | ||
| this.drawnCards = new Cards(); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public boolean isDealerNotDone() { | ||
| return false; | ||
| } | ||
|
|
||
| public static Participant createPlayer(String name) { | ||
| return new Player(name); | ||
| public static Participant createPlayer(String name, Money money) { | ||
| return new Player(name, money); | ||
| } | ||
|
|
||
| public static Participant createDealer() { | ||
|
|
@@ -33,19 +28,35 @@ public void receiveOneCard(Card card) { | |
| drawnCards.addCard(card); | ||
| } | ||
|
|
||
| public List<String> getCardNames() { | ||
| return drawnCards.getCardNames(); | ||
| public boolean isDealerNotDone() { | ||
| return false; | ||
| } | ||
|
|
||
| public boolean isBust() { | ||
| return drawnCards.sumScore() > 21; | ||
| return drawnCards.sumScore() > BLACKJACK_SCORE; | ||
| } | ||
|
|
||
| public boolean isBlackjack() { | ||
| return drawnCards.sumScore() == BLACKJACK_SCORE && drawnCards.getSize() == BLACKJACK_SIZE; | ||
| } | ||
|
|
||
| public int calculateTotalScore() { | ||
| return drawnCards.sumScore(); | ||
| } | ||
|
|
||
| public int calculateFinalProfit(Participant dealer) { | ||
| return 0; | ||
| } | ||
|
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 GameResult judgeResult(List<Participant> players, Participant dealer) { | ||
| return new GameResult(new HashMap<>(), new HashMap<>()); | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name.getName(); | ||
| } | ||
|
|
||
| public List<String> getCardNames() { | ||
| return drawnCards.getCardNames(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,25 @@ | ||
| package blackjack.domain; | ||
|
|
||
| public class Player extends Participant { | ||
| private final String name; | ||
|
|
||
| public Player(String name) { | ||
| private final Money money; | ||
|
|
||
| public Player(String name, Money money) { | ||
| super(name); | ||
| this.name = name; | ||
| this.money = money; | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| @Override | ||
|
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 int calculateFinalProfit(Participant dealer) { | ||
| if (isBlackjack() && dealer.isBlackjack()) { | ||
| return money.getBettingMoney(); | ||
| } | ||
| if (isBlackjack()) { | ||
| return (int) (money.getBettingMoney() * 1.5); | ||
|
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. ์ด์ ๋จ๊ณ์์ ๋ฆฌ๋ทฐ๋ฅผ ์๋๋ ธ์๋ ์ถ์๋ฐ์ ๊ทธ๋ฆฌ๊ณ ์์ต ๊ณ์ฐ์
Author
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. ๋งค์ง ๋๋ฒ ์์ํ๋ ์ด์ ๋ฆฌ๋ทฐ์์ ํ์ธ ํ ๋ฆฌํฉํฐ๋ง์ ์งํํ์๋๋ฐ, ์ด ์ซ์๋ ์ ๊ฐ ๋์น ๊ฒ ๊ฐ์ต๋๋ค... ์ด ๋ถ๋ถ๋ ์์ํํ์ฌ ์์ ํ์์ต๋๋ค! ์ ๋ Money ๊ฐ์ฒด๋ฅผ ๋ง๋ค๋ฉด์ ๋จ์ํ ๊ฐ๋ง ๋ด๊ณ ์๋ค ๋ณด๋ ๊ตณ์ด ํ์ํ ํด๋์ค์ผ๊น ์๊ฐํ์๋๋ฐ, ์ด๋ฒ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ์ํด์ Money ๊ฐ์ฒด ์์์ ๊ณฑ์ ์ด๋ ๋ถํธ ๋ฐ์ ์ฐ์ฐ์ ์ํํ๊ณ ๋ฒ ํ ๊ฒฐ๊ณผ ๊ธ์ก๋ Money ๊ฐ์ฒด๋ก ๋ฐํํ๋๋ก ๋ฆฌํฉํฐ๋งํ์ต๋๋ค. |
||
| } | ||
| if (isBust() || dealer.isBlackjack() || (calculateTotalScore() < dealer.calculateTotalScore() && !dealer.isBust())) { | ||
| return -money.getBettingMoney(); | ||
|
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. ์ด ์กฐ๊ฑด์ด ํ ์ค์ ๋๋ฌด ๋ง์ ํ๋จ์ ๋ด๊ณ ์์ด์ ์ฝ๊ธฐ๊ฐ ์ฝ์ง ์์๊ฒ ๊ฐ์์. ๋ณ๊ฒฝ๊ณผ ํ์ฅ์ ์ ๋ฆฌํ ๊ตฌ์กฐ๋ก ๋ณ๊ฒฝํ๋ ๋ฐฉ๋ฒ์ ์์๊น์?
Author
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. ๋ณต์กํ ์กฐ๊ฑด๋ฌธ์ ์กฐ๊ธ ๋ ๊ฐ๋ ์ฑ์๊ฒ ๋ถ๋ฆฌํ์์ต๋๋ค! ํ๋ ์ด์ด๊ฐ ๋ฒ ํ ๊ธ์ก์ ๋๋ ค๋ฐ๋ ๊ฒฝ์ฐ, 1.5๋ฐฐ์ ์์ต์ ์ป๋ ๊ฒฝ์ฐ, ๋ฒ ํ ๊ธ์ก์ ์๋ ๊ฒฝ์ฐ๋ฅผ ๊ฐ๊ฐ ๋ถ๋ฆฌํ์ฌ ํ๋์ ์กฐ๊ฑด๋ฌธ์ด ๋๋ฌด ๋ง์ ํ๋จ์ ๋ด์ง ์๋๋ก ๋ฆฌํฉํฐ๋ง ํ์ต๋๋ค. |
||
| } | ||
| return money.getBettingMoney(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,25 @@ | ||
| package blackjack.utils; | ||
|
|
||
| import java.util.List; | ||
| import java.util.stream.Stream; | ||
|
|
||
| public class InputParser { | ||
|
|
||
| public static List<String> splitPlayerNames(String input) { | ||
| if (input == null || input.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด ์ด๋ฆ์ ์ ๋ ฅํด์ฃผ์ธ์."); | ||
| throw new IllegalArgumentException("[ERROR] ์ด๋ฆ์ ์ ํํ๊ฒ ์ ๋ ฅํด์ฃผ์ธ์."); | ||
| } | ||
| String[] names = input.split(","); | ||
| for (String name : names) { | ||
| validateNameEmpty(name); | ||
| } | ||
| return List.of(names).stream() | ||
| return Stream.of(names) | ||
| .map(String::trim) | ||
| .toList(); | ||
| } | ||
|
|
||
| private static void validateNameEmpty(String name) { | ||
| if (name.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("[ERROR] ํ๋ ์ด์ด ์ด๋ฆ์ ๊ณต๋ฐฑ์ด ๋ ์ ์์ต๋๋ค."); | ||
| public static int convertNumber(String input) { | ||
| try { | ||
| return Integer.parseInt(input); | ||
| } catch (NumberFormatException e) { | ||
| throw new IllegalArgumentException("[ERROR] ์ซ์ ์ด์ธ์ ๊ฐ์ ์ ๋ ฅํ ์ ์์ต๋๋ค."); | ||
| } | ||
| } | ||
| } |
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.
calculateFinalGameProfit์ดpublic์ผ๋ก ์ ์ธ๋์ด ์๋ค์~๊ทธ๋ฆฌ๊ณ
HashMap์ playersProfit์ ๊ตฌ์ฒด ํ์ ์ผ๋ก ์ ์ธํ๊ณ ์๋๋ฐ,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.
์ด ๋ถ๋ถ๋ private์ผ๋ก ์ค์ ๋์ด์๋์ค ์์์ต๋๋ค.. ์ฃผ์ํ๊ฒ ์ต๋๋ค!
playersProfit์ ํ์ ๋ ์ธํฐํ์ด์ค๋ก ์ ์ธํ๋๋ก ๋ณ๊ฒฝํ์์ต๋๋ค. Map ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํ๋ฉด ๋์ค์ ๊ตฌํ์ฒด๋ฅผ ๋ฐ๊พธ๋๋ผ๋ ์ค์ ์ฌ์ฉํ๋ ์ฝ๋๋ ๊ณ ์น ํ์๊ฐ ์์ด์ ํจ์ฌ ์ ์ฐํ๋ค๋ ์ ์ ๋ฐฐ์ ์ต๋๋ค. ์ธํฐํ์ด์ค๋ฅผ ํ์ฉํ๋ ์ด์ ๋ฅผ ๋ค์ ํ๋ฒ ์๊ฐํด๋ณด๊ฒ ๋ ๊ฒ ๊ฐ์ต๋๋ค!