-
Notifications
You must be signed in to change notification settings - Fork 550
[๐ ์ฌ์ดํด2 - ๋ฏธ์ (๋ธ๋์ญ ๋ฒ ํ )] ์๋ํค ๋ฏธ์ ์ ์ถํฉ๋๋ค. #1108
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: kcnsmoothie
Are you sure you want to change the base?
Changes from all commits
c8daa3f
6cdbba2
9ff221c
648fe9b
cbedd0e
d17084e
eec36bb
ac4041f
549740e
c102d24
abffda7
6107d0d
16188ab
3fe7c1d
ba63f5b
490cf85
3060aa5
3952e53
e35b6f6
d36a0d0
30eb78b
f983a5e
9bce798
63ce635
e3987cb
5b5a0b1
d3f91cc
4624b1f
6452da9
1429d04
5b7c169
8d51966
a9b09c5
dc7f9ea
dd01040
197df1a
496bd15
9e983fd
9172798
9346ddb
b117fab
537399d
5cc1a64
cf19faa
15241fe
262573b
3fd51eb
1a28213
ba853bb
a6366c5
6dee305
109c86c
9447709
8cac4f9
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 |
|---|---|---|
|
|
@@ -7,11 +7,11 @@ | |
| public class Players { | ||
| private final List<Player> playerList; | ||
|
|
||
| public Players(List<String> names) { | ||
| public Players(List<String> names,List<Integer> betAmounts) { | ||
|
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. ์ ๋ฌํ ์ ๋ณด๋ค์ด ๋ง์์ก๋๋ฐ ํ๋ผ๋ฏธํฐ๋ก ์ ๋ฌํ ๋ ์์ํ์ ์ List ๋ณด๋ค ๊ฐ์ฒด๋ก ์ ๋ฌํด์ฃผ๋ฉด ์ด๋จ๊น์? |
||
| validateDuplicate(names); | ||
| playerList = new ArrayList<>(); | ||
| for (String name : names) { | ||
| playerList.add(new Player(name)); | ||
| playerList.add(new Player(name, betAmounts.get(names.indexOf(name)))); | ||
|
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. indexOf๋ฅด ์ฐ๋ฉด ์ด๋ค ๋ฌธ์ ๊ฐ ์์๊น์? ์ด๋ป๊ฒ ๊ฐ์ ํ ์ ์์๊น์? |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,10 @@ | |
| public class Referee { | ||
| private static final int BUST_THRESHOLD = 21; | ||
|
|
||
| public boolean isBlackJack(int playerScore) { | ||
| return playerScore == BUST_THRESHOLD; | ||
| } | ||
|
|
||
| public Result judge(int playerScore, int dealerScore) { | ||
| if (playerScore > BUST_THRESHOLD) { | ||
| return Result.LOSE; | ||
|
|
@@ -18,4 +22,9 @@ public Result judge(int playerScore, int dealerScore) { | |
| } | ||
|
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. judge ๋ฉ์๋์ if ๋ถ๊ธฐ๋ฌธ์ ์ข ์ฃผ์ฌ๋ณผ ์ ์์๊น์? Player์ Dealer๋ฅผ ์ ๋ฌ๋ฐ์์ ๊ฒฐ๊ณผ๋ฅผ ๋์ถํ๋๋ก ๊ตฌํํด๋ณด๋ฉด ์ค์ผ ์ ์์ง ์์๊น์? |
||
| return Result.LOSE; | ||
| } | ||
|
|
||
| public double calculateProfit(Result result, int betAmount) { | ||
| return result.getProfitRate() * betAmount; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,18 @@ | ||
| package domain; | ||
|
|
||
| public enum Result { | ||
| WIN, LOSE, TIE | ||
| BLACKJACK(1.5), | ||
| WIN(1), | ||
| LOSE(-1), | ||
| TIE(0); | ||
|
|
||
| private final double profitRate; | ||
|
|
||
| Result(double profitRate) { | ||
| this.profitRate = profitRate; | ||
| } | ||
|
|
||
| public double getProfitRate() { | ||
| return profitRate; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package domain; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| public class Results { | ||
| private final Map<Player, Result> results = new HashMap<>(); | ||
|
|
||
| public void add(Player player, Result result) { | ||
| results.put(player, result); | ||
| } | ||
|
|
||
| public Result findByPlayer(Player player) { | ||
| return results.get(player); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package view; | ||
|
|
||
| import domain.Card; | ||
| import domain.Dealer; | ||
| import domain.Participant; | ||
| import domain.Player; | ||
| import domain.Rank; | ||
|
|
@@ -59,12 +60,34 @@ public void printFinalResult(Participant dealer, Map<Player, Result> results) { | |
| printPlayerResults(results); | ||
| } | ||
|
|
||
| private void printPlayerResults(Map<Player, Result> results) { | ||
| for (Map.Entry<Player, Result> entry : results.entrySet()) { | ||
| System.out.println(entry.getKey().getName() + ": " + RESULT_NAME.get(entry.getValue())); | ||
| } | ||
| } | ||
|
|
||
| private void printDealerResult(Participant dealer, Map<Player, Result> results) { | ||
| int dealerWin = countResult(results, Result.LOSE); | ||
| int dealerLose = countResult(results, Result.WIN); | ||
| System.out.println(dealer.getName() + ": " + dealerWin + "์น " + dealerLose + "ํจ"); | ||
| } | ||
|
Comment on lines
69
to
73
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. Dealer์ ์น์๋ฅผ ์ธ๋๋ฐ Player์ Lose ๋ฅผ ํตํด์ ์ญ์ผ๋ก ๊ณ์ฐํ๊ณ ์์ต๋๋ค. |
||
|
|
||
| public void printFinalProfit(Dealer dealer, double dealerProfit, Map<Player, Integer> results) { | ||
| System.out.println("\n## ์ต์ข ์์ต"); | ||
| printDealerProfit(dealer, (int) dealerProfit); | ||
| printPlayerProfit(results); | ||
| } | ||
|
|
||
| private void printPlayerProfit(Map<Player, Integer> results) { | ||
| for (Map.Entry<Player, Integer> entry : results.entrySet()) { | ||
| System.out.println(entry.getKey().getName() + ": " + entry.getValue()); | ||
| } | ||
| } | ||
|
|
||
| private void printDealerProfit(Dealer dealer, int profit) { | ||
| System.out.println(dealer.getName() + ": " + profit); | ||
| } | ||
|
|
||
| private int countResult(Map<Player, Result> results, Result target) { | ||
| int count = 0; | ||
| for (Result result : results.values()) { | ||
|
|
@@ -75,12 +98,6 @@ private int countResult(Map<Player, Result> results, Result target) { | |
| return count; | ||
| } | ||
|
|
||
| private void printPlayerResults(Map<Player, Result> results) { | ||
| for (Map.Entry<Player, Result> entry : results.entrySet()) { | ||
| System.out.println(entry.getKey().getName() + ": " + RESULT_NAME.get(entry.getValue())); | ||
| } | ||
| } | ||
|
|
||
| private String formatCards(List<Card> cards) { | ||
| List<String> cardNames = new ArrayList<>(); | ||
| for (Card card : cards) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package domain; | ||
|
|
||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
|
||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| public class CardBundleTest { | ||
|
|
||
| private CardBundle cardBundle; | ||
|
|
||
| @BeforeEach | ||
| void beforeEach() { | ||
| cardBundle = new CardBundle(); | ||
| } | ||
|
|
||
| @DisplayName("์ผ๋ฐ ์นด๋์ ์ ์๋ฅผ ํฉ์ฐํ๋ค") | ||
| @Test | ||
| void ์ผ๋ฐ_์นด๋์_์ ์๋ฅผ_ํฉ์ฐํ๋ค() { | ||
| cardBundle.addCard(new Card(Rank.KING, Suit.SPADE)); // 10 | ||
| cardBundle.addCard(new Card(Rank.FIVE, Suit.HEART)); // 5 | ||
| assertThat(cardBundle.calculateScore()).isEqualTo(15); | ||
| } | ||
|
|
||
| @DisplayName("ACE๊ฐ ์๊ณ ๋ฒ์คํธ๊ฐ ์๋๋ฉด 11๋ก ๊ณ์ฐํ๋ค") | ||
| @Test | ||
| void ACE๊ฐ_์๊ณ _๋ฒ์คํธ๊ฐ_์๋๋ฉด_11๋ก_๊ณ์ฐํ๋ค() { | ||
| cardBundle.addCard(new Card(Rank.ACE, Suit.SPADE)); // 11 | ||
| cardBundle.addCard(new Card(Rank.KING, Suit.HEART)); // 10 | ||
| assertThat(cardBundle.calculateScore()).isEqualTo(21); | ||
| } | ||
|
|
||
| @DisplayName("ACE๊ฐ ์๊ณ ๋ฒ์คํธ๋ฉด 1๋ก ๊ณ์ฐํ๋ค") | ||
| @Test | ||
| void ACE๊ฐ_์๊ณ _๋ฒ์คํธ๋ฉด_1๋ก_๊ณ์ฐํ๋ค() { | ||
| cardBundle.addCard(new Card(Rank.ACE, Suit.SPADE)); // 1 | ||
| cardBundle.addCard(new Card(Rank.KING, Suit.HEART)); // 10 | ||
| cardBundle.addCard(new Card(Rank.FIVE, Suit.DIAMOND)); // 5 | ||
| assertThat(cardBundle.calculateScore()).isEqualTo(16); | ||
| } | ||
|
|
||
| @DisplayName("ACE๊ฐ ์ฌ๋ฌ ์ฅ์ด๋ฉด ํ๋๋ง 11๋ก ๊ณ์ฐํ๋ค") | ||
| @Test | ||
| void ACE๊ฐ_์ฌ๋ฌ_์ฅ์ด๋ฉด_ํ๋๋ง_11๋ก_๊ณ์ฐํ๋ค() { | ||
| cardBundle.addCard(new Card(Rank.ACE, Suit.SPADE)); // 11 | ||
| cardBundle.addCard(new Card(Rank.ACE, Suit.HEART)); // 1 | ||
| assertThat(cardBundle.calculateScore()).isEqualTo(12); | ||
| } | ||
|
|
||
| @Test | ||
| void ์ด๊ธฐ_๋์ฅ์ด_21์ด๋ฉด_๋ธ๋์ญ์ด๋ค() { | ||
| cardBundle.addCard(new Card(Rank.KING, Suit.HEART)); // 10 | ||
| cardBundle.addCard(new Card(Rank.ACE, Suit.SPADE)); // 11 | ||
|
|
||
| assertThat(cardBundle.isBlackjack()).isTrue(); | ||
| } | ||
| } |
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.
๋ฆฌ๋ทฐ์ด ์ ์ฅ์์ ๋ง์๋๋ฆฌ๋ฉด ์ด์ ๋จ๊ณ์์ ๋จ๊ธด ํผ๋๋ฐฑ์ด ๋ฐ์๋์ง ์์ผ๋ฉด ๋ ๋์ผํ ํผ๋๋ฐฑ์ ๋๋ ค๋ฉด ๋๊ธฐ ๋๋ฌธ์ ํธํฉ๋๋ค. ๊ทธ๋ฐ๋ฐ ์๋ํค ์ ์ฅ์์๋ ๊ทธ๋งํผ ๋ค๋ฅธ ์ฃผ์ ๋ก ์ด์ผ๊ธฐ๋ฅผ ํด๋ณผ ๊ธฐํ๊ฐ ์ค์ด๋ ๋ค๊ณ ์๊ฐํด์ ๊ฐ์ธ์ ์ผ๋ก๋ ๋ณธ์ธ์ด ์ถฉ๋ถํ ๊ณ ๋ฏผํ๋ค์ ์งํํ๋ ๊ฒ์ด ๋ง๋ค๊ณ ์๊ฐํฉ๋๋ค.
๊ธฐ๋ฅ์ด ๋์ํ๋ ์ํ๋ก ๋น ๋ฅด๊ฒ ๊ตฌํํด์ ๊ณต์ ํ๋ ๊ฒ์ ํผ์์๋ ํ ์ ์๋ ์ผ์ด์ง๋ง ์ค๊ณ์ ๋ํด์ ๊ณ ๋ฏผํ๊ณ ํ ๋ก ํ๋ ๊ณผ์ ์ ํผ์์ ๊ฐ๋ฅํ ์ง๋ผ๋ ์ค๊ณ๊ฐ ๋ฏธํกํ ์ ๋ฐ์ ์์ต๋๋ค. ์ฌ๋ฌ ๊ด์ ์์ ๋ฌธ์ ๋ฅผ ๋ฐ๋ผ๋ณด๋ ๊ฒ์ด ๋ ์ข์ ์ค๊ณ๋ฅผ ๋ง๋ค ์ ์์ผ๋๊น์. ํ์ฌ ์์ฒญ ์ฃผ์ ์ฝ๋์๋ ์ ๊ฐ ์ด์ ๋จ๊ณ์์ ๋๋ฆฐ ํผ๋๋ฐฑ๋ค์ด ์ฌ์ ํ ๋ฐ์๋์ง ์์ ๋ถ๋ถ๋ค์ด ๋ณด์ ๋๋ค. ์ ๊ฐ ์ถ์ฒ๋๋ฆฌ๋ ๋ฐฉํฅ์ ์ต์ํ ๋จ๊ธด ํผ๋๋ฐฑ์ ๋ํด์๋ ๊ณ ๋ฏผ ํน์ ๋ฐ์์ ํ ๋ค์ ์์ฒญํ๋ ๊ฒ์ ๋๋ค. ์ด๋์ผ ๋ ๋ง์ ๋ถ๋ถ์ ๋ํด์ ์ด์ผ๊ธฐ๋ฅผ ํด๋ณผ ์ ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
์ฐ์ ๊ฐ์ฒด ์งํฅ ์ค๊ณ์์ ์ ๋ต์ ์์ต๋๋ค, ๊ทธ๋์ ์ ๋๋ก ์ ๊ฐ ๋งํ๋ ๊ฒ์ ๊ทธ๋๋ก ๋ฃ์ง ์์ผ์ ์ผํฉ๋๋ค.
๋ถ๋ณ ๊ฐ์ฒด๋ ๋ฐฉ์ด์ ๋ณต์ฌ๋ ์ค๊ณ๋ฅผ ํผํผํ๊ฒ ๋ง๋ค์ด์ฃผ๋ ์ฅ์น์ ๋๋ค. ์์ ์ด ์ผ์ด๋์ง ์๋ ๋ถ๋ถ์ ๋ํด์๋ ์ ๊ทน์ ์ผ๋ก ์ฌ์ฉํด์ฃผ์ธ์.
์ต์ข ์์ต์ด ์ด๋์ ์์นํด์ผ ํ๋๋ ์ฌ๋ฌ ์ด์ผ๊ธฐ๋ฅผ ๋ง๋ค์ด๋ณผ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค.
์ง๊ธ์ฒ๋ผ Player๊ฐ ๊ฐ์ง๋ ๊ฒ๋ ํ์ค์ ์ผ๋ก๋ ์์ฐ์ค๋ฌ์ด ํ๋ฆ์ด๋ผ๊ณ ์๊ฐํด์. ํ์ค์์ ์์ต์ ๊ฒ์์ ์ฐธ๊ฐํ ์ฌ๋์ด ๊ฐ์ ธ๊ฐ๋๊น์. ๊ทธ๋ฐ๋ฐ ์ฝ๋ ์์ผ๋ก ๋ดค์ ๋ ์ ๋ง ํ์ํ๊ฐ๋ ๋ค๋ฅธ ๋ฌธ์ ์ ๋๋ค. Player๊ฐ ์ต์ข ์์ต์ ๊ฒฐ์ ์ ํด๋๋๊ณ ๋ฐ๋๋ก ์ต์ข ์์ต์ด Player๋ฅผ ๊ฐ์ ธ์์ ๊ฒฐ๊ณผ๋ฅผ ๋์ถํด์ค๋ ๋ฉ๋๋ค. ์ ์์ ๊ฒฝ์ฐ Player๊ฐ ์ต์ข ์์ต์ ์๊ฒ๋๊ณ ํ์์ ๊ฒฝ์ฐ ์ต์ข ์์ต์ด Player๋ฅผ ์๊ฒ ๋ฉ๋๋ค. ์ ์์ผ๋ฉด ํ์ฌ๋ ํ์๋ฅผ ํํ์ ๊ฒ ๊ฐ์์. ์ด์ ๋ ๋จ์ํฉ๋๋ค ํ์ฌ Player๊ฐ ํ๋ ์ผ์ด ํจ์ฌ ๋ง๊ฑฐ๋ ์. ๊ทธ๋ฆฌ๊ณ ์ฑ ์์ ์์ํ ์ ์๋ ๋ถ๋ถ๋ค์ด ๋ ๋ง์ต๋๋ค. Player ์ ์ฅ์์๋ ์ต์ข ์์ต์ ์กด์ฌ์ ๋ํด์ ๋ชฐ๋ผ๋ ๋๋๊น ์ต์ข ์์ต์ด๋ผ๋ context๋ ํ๋์ ๋ฌถ์์ผ๋ก ๋ฌถ์ด์ ๋ณ๋๋ก ๊ด๋ฆฌํ ์ ์๊ฒ ๋ฉ๋๋ค. ๋ญ ์ด๋ฌํ ์ด์ ์์ ์ ๋ Player ๊ฐ ์์ง ์๋ ๊ฒ์ด ๋ซ์ง ์์๊น ์ถ์๋ฐ, ๋ ๋ฐ๋๋๋ ์ ์ฅ์ด ํ๋ ธ๋ค๊ณ ๋งํ ์๋ ์๋ค๊ณ ์๊ฐํฉ๋๋ค.
์์์ ๋งํ๋ ์ ์๊ฐ์ ์ ์๊ฐ์ผ ๋ฟ์ด์ง ์ ๋ต์ด ์๋๋๋ค, ๋จ์ ๋ฏธ์ ์ ์งํํ๋ฉด์๋ ๋ฆฌ๋ทฐ์ด์ ๋ง์ ๋๋ฌด ๋ฏฟ์ง ๋ง์ธ์. ๋ณธ์ธ์ ์๊ฐ์ ํค์๋๊ฐ๋ณด์ธ์.๋ค.
ํจํค์ง ๊ด๋ฆฌ
domain ์์ Result, Referee ๋ฑ.. ๋ค์ํ ํด๋์ค๊ฐ ์ถ๊ฐ ๋๋ค ๋ณด๋ ํ ๋์ ๋๋ฉ์ธ์ ์ดํดํ๊ธฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์ต๋๋ค. ํน์ domain ํจํค์ง ๋ด์์ ๊ฐ๋ ์ฑ์ ์ํด ํจํค์ง๋ฅผ ๊ด๋ฆฌํ๋ ์ ๋ต์ด๋ ์ปจ๋ฒค์ ํน์.. ๊ธฐ์ค์ด ์์๊น์?
์ ์๊ฐ์๋ ํ์ฌ ๊ทธ๋ ๊ฒ ๊ฐ์ฒด๊ฐ ๋ง์ง ์์ ๊ฒ ๊ฐ์์ ๋ถ๋ฆฌํ์ง ์์๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ง์ฝ ๊ทผ๋ฐ domain์ด ๋ ์ปค์ง๋ค๋ฉด domain ์์ ํจํค์ง๋ก ๋ถ๋ฆฌํ ์ ์์ง ์์๊น ์ถ์ต๋๋ค.