-
Notifications
You must be signed in to change notification settings - Fork 389
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
[디디] 블랙잭 2단계 미션 제출합니다. #66
Changes from 14 commits
f16764e
f3162e5
49adee2
5b5cea1
068baef
5567dd9
a87949e
975d3d0
00132f3
8b686c6
b08b00b
bee4f0c
e224872
08d6065
82cdbe5
cec0c59
54e8cad
294a2c3
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,7 @@ | ||
package exception; | ||
|
||
public class BetFormatException extends RuntimeException { | ||
public BetFormatException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package exception; | ||
|
||
public class BetRangeException extends RuntimeException { | ||
public BetRangeException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package exception; | ||
|
||
public class IllegalDrawException extends RuntimeException { | ||
public IllegalDrawException(String message) { | ||
super(message); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package model; | ||
|
||
import exception.BetFormatException; | ||
import exception.BetRangeException; | ||
import utils.StringUtils; | ||
|
||
public class Bet { | ||
public static final double LOWER_BET_BOUND = 100; | ||
|
||
private final double bet; | ||
|
||
public Bet(String input) { | ||
validate(input); | ||
this.bet = Double.parseDouble(input); | ||
} | ||
|
||
public Bet(double input) { | ||
this.bet = input; | ||
} | ||
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. double로 생성할 경우에 대해서도 validate가 필요하지 않을까요?? |
||
|
||
private void validate(String input) { | ||
StringUtils.validateString(input); | ||
validateFormat(input); | ||
validateRange(input); | ||
} | ||
|
||
private void validateFormat(String input) { | ||
try { | ||
Double.parseDouble(input); | ||
} catch (NumberFormatException e) { | ||
throw new BetFormatException("베팅금액은 실수만 입력 가능합니다."); | ||
} | ||
} | ||
|
||
private void validateRange(String input) { | ||
if (Double.parseDouble(input) < LOWER_BET_BOUND) { | ||
throw new BetRangeException("베팅금액은 100원 이상부터 입력 가능합니다."); | ||
} | ||
} | ||
|
||
public Bet MultiplyBet(double ratio) { | ||
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 new Bet(bet * ratio); | ||
} | ||
|
||
public double getBet() { | ||
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. bet.getBet()은 조금 부자연스럽지 않을까요? |
||
return bet; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
package model; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class CardFactory { | ||
|
||
public static List<Card> createCardList() { | ||
List<Card> cards = new ArrayList<>(); | ||
for (Symbol symbol : Symbol.values()) { | ||
createByType(cards, symbol); | ||
} | ||
List<Card> cards = Arrays | ||
.stream(Type.values()) | ||
.flatMap(CardFactory::mapToCard) | ||
.collect(Collectors.toList()); | ||
return Collections.unmodifiableList(cards); | ||
} | ||
|
||
private static void createByType(List<Card> cards, Symbol symbol) { | ||
for (Type type : Type.values()) { | ||
cards.add(new Card(symbol, type)); | ||
} | ||
private static Stream<Card> mapToCard(Type type) { | ||
return Arrays | ||
.stream(Symbol.values()) | ||
.map(symbol -> new Card(symbol, type)); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
package model; | ||
|
||
import java.util.List; | ||
|
||
import static controller.BlackJackGame.HIT_BOUNDARY; | ||
|
||
public class Dealer extends User { | ||
public static final int ZERO = 0; | ||
private static final int FIRST = 0; | ||
public static final String DEALER_NAME = "딜러"; | ||
|
||
public Dealer(Deck deck, int initialDrawCount) { | ||
super(DEALER_NAME, deck, initialDrawCount); | ||
public Dealer(Deck deck) { | ||
super(DEALER_NAME, deck); | ||
} | ||
|
||
public Dealer(List<Card> cards) { | ||
super(DEALER_NAME, cards); | ||
} | ||
|
||
public String toStringCardHandFirst() { | ||
return cardHand.getCards().get(ZERO).toString(); | ||
return cardHand.getCards().get(FIRST).toString(); | ||
} | ||
|
||
public boolean isHitBound() { | ||
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. 지금 보니 해당 메서드를 Player의 isMoreThanBlackJack이랑 묶어서 더 카드를 뽑을수 있는지, 없는지를 판단하는 메서드로 추상화 할 수 있을 것 같네요. :) |
||
|
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.
값객체로 활용하신다면 당장 쓰이진 않더라도 equals, hashCode를 구현하는걸 습관화 하면 좋을 것 같습니다. :)