Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
194bd15
docs: TDD 기능 구현 사항 정의
hochan222 Feb 11, 2022
2132cfe
test: RentCompanyTest 테스트 케이스 추가
hochan222 Feb 11, 2022
452e494
feat: 초기 구조.
hochan222 Feb 11, 2022
af3b6ac
test: `Sonata` String Type 이름을 가져야한다.
hochan222 Feb 11, 2022
a508794
test: `Sonata` String Type 이름을 가져야한다.
hochan222 Feb 11, 2022
115b872
feat: `Sonata` String Type 이름을 가져야한다.
hochan222 Feb 11, 2022
afb8d8b
docs: `Sonata` String Type 이름을 가져야한다.
hochan222 Feb 11, 2022
27431e9
test: `10km/리터`의 연비 가져야한다.
hochan222 Feb 11, 2022
bed1c08
feat: `10km/리터`의 연비 가져야한다.
hochan222 Feb 11, 2022
33d93c5
docs: `10km/리터`의 연비 가져야한다.
hochan222 Feb 11, 2022
7071676
test: 거리
hochan222 Feb 11, 2022
4d48981
test: 거리
hochan222 Feb 11, 2022
49214d3
feat: 거리
hochan222 Feb 11, 2022
e5bcbc7
docs: 거리
hochan222 Feb 11, 2022
9e5d638
test: 주입해야할 연료량을 구할 수 있다.
hochan222 Feb 11, 2022
7aab241
feat: 주입해야할 연료량을 구할 수 있다.
hochan222 Feb 11, 2022
6081d09
docs: 주입해야할 연료량을 구할 수 있다.
hochan222 Feb 11, 2022
4f596ac
test: 메서드 이름 리펙토링
hochan222 Feb 11, 2022
d557835
test: Avante 기능 구현
hochan222 Feb 11, 2022
5ced626
feat: Avante 기능 구현
hochan222 Feb 11, 2022
c2d769b
docs: Avante 기능 구현
hochan222 Feb 11, 2022
fdc4a5d
test: K5 기능 구현
hochan222 Feb 11, 2022
c0f7781
feat: K5 기능 구현
hochan222 Feb 11, 2022
18191da
docs: K5 기능 구현
hochan222 Feb 11, 2022
0501b46
docs: git pull pair
hochan222 Feb 11, 2022
7ad9a5f
docs : 기능 구현 사항 checkbox 제거
Feb 11, 2022
4d22b97
test : Class명에 따른 테스트 메소드명 변경
Feb 11, 2022
94c57b9
docs : RentCompany에 대한 기능 구현 추가
Feb 11, 2022
3fbb733
feat : RentCompany factory 메소드 구현
Feb 11, 2022
ffc7c7f
test : RentCompanyTest - Car의 List를 가져야한다.
Feb 11, 2022
118309e
feat : RentCompany - 상태변수 rentCars 구현
Feb 11, 2022
0083d3c
docs : RentCompany - List<Car> 관련 구현
Feb 11, 2022
00c41a8
refactor : EUC-KR로 인코딩 방식 변경
Feb 11, 2022
f6076e5
docs : RentCompany - addCar() 기능 명세 변경
Feb 11, 2022
226c68d
test : `addCar()`, 차를 추가할 수 있다.
Feb 11, 2022
df2f622
refactor : Car의 구현 클래스의 equals, hashcode 오버라이딩
Feb 11, 2022
c983e1d
feat : RentCompany addCar() 구현
Feb 11, 2022
b12d669
docs : RentCompany addCar() 구현
Feb 11, 2022
b01db13
feat : RentCompany generateReport 메서드 구현
Feb 14, 2022
18abdbf
feat : Car getChargeQuantity 추상화 메서드 구체화
Feb 14, 2022
3521cdf
docs : 누락된 RentCompany checkbox 추가
Feb 14, 2022
15f080c
docs : blackjack 기능 요구 사항 정의
Feb 14, 2022
4a3c4db
feat: 인터페이스를 적용해 구현한다.
hochan222 Feb 15, 2022
ea6bcd9
docs: 인터페이스를 적용해 구현한다.
hochan222 Feb 15, 2022
caa3e0e
chore: 안쓰는 파일 삭제 및 구조 변경
hochan222 Feb 15, 2022
ed92876
test: 주어진 정수로 CardNumber 생성 후 getCardNumber() 호출시, 주어진 정수와 동일하다.
hochan222 Feb 15, 2022
99a0d73
feat: 주어진 정수로 CardNumber 생성 후 getCardNumber() 호출시, 주어진 정수와 동일하다.
hochan222 Feb 15, 2022
14d58ef
test: 유효하지 않는 CarNumber 범위로 인스턴스가 생성될때, RuntimeException 발생한다.
hochan222 Feb 15, 2022
66493b8
feat: 유효하지 않는 CarNumber 범위로 인스턴스가 생성될때, RuntimeException 발생한다.
hochan222 Feb 15, 2022
f7b945e
test: int to string
hochan222 Feb 15, 2022
0015e65
test: 주어진 String type 으로 CardType 생성 후 getCardType() 호출시, 주어진 type과 동…
hochan222 Feb 15, 2022
9c12086
feat: 주어진 String type 으로 CardType 생성 후 getCardType() 호출시, 주어진 type과 동…
hochan222 Feb 15, 2022
ec1bb3d
test: 유효하지 않는 CardType 범위로 인스턴스가 생성될때, RuntimeException 발생한다.
hochan222 Feb 15, 2022
093f6a0
test: typo err 수정
hochan222 Feb 15, 2022
efe9782
docs: CardType, CardNumber 구현
hochan222 Feb 15, 2022
9dc87ff
docs: CardType은 `"다이아몬드", "하트", "클로버", "스페이드"` 이 범위안에 반드시 있어야한다.
hochan222 Feb 15, 2022
a5f917f
test: 카드 숫자와 카드 타입을 입력할때, 주어진 숫자와 타입으로 카드가 생성된다.
hochan222 Feb 15, 2022
c532650
feat: 카드 숫자와 카드 타입을 입력할때, 주어진 숫자와 타입으로 카드가 생성된다.
hochan222 Feb 15, 2022
99a30dc
refactor: card getter 네이밍 변경
hochan222 Feb 15, 2022
8f38840
refactor: card getter 네이밍 변경
hochan222 Feb 15, 2022
3a11286
feat: Deck, User
hochan222 Feb 15, 2022
b4fcda3
docs: Card 완료
hochan222 Feb 15, 2022
9866a48
feat : Deck 클래스 구현
Feb 15, 2022
7647b14
docs : Deck 클래스 구현
Feb 15, 2022
3f16e2f
refactor: 원시 자료 래핑 추상화
hochan222 Feb 15, 2022
7293f4e
feat: GameCard 에는 52장의 서로 다른 카드가 존재한다.
hochan222 Feb 15, 2022
359e1fa
test: GameCard 에는 52장의 서로 다른 카드가 존재한다.
hochan222 Feb 15, 2022
175b6e0
docs: GameCard 에는 52장의 서로 다른 카드가 존재한다.
hochan222 Feb 15, 2022
17fbe9c
test: String 이름이 주어질때, getUserName 메소드의 값은 주어진 이름과 동일하다.
hochan222 Feb 15, 2022
ff529d1
feat: String 이름이 주어질때, getUserName 메소드의 값은 주어진 이름과 동일하다.
hochan222 Feb 15, 2022
f8aa8fb
docs: String 이름이 주어질때, getUserName 메소드의 값은 주어진 이름과 동일하다.
hochan222 Feb 15, 2022
70929bf
feat: User Interface 구현
hochan222 Feb 15, 2022
53bccc6
docs: User Interface 구현
hochan222 Feb 15, 2022
f3bc3af
feat: deck isScoreOver21 메서드 추가
hochan222 Feb 15, 2022
e8617a6
test: player 구현
hochan222 Feb 15, 2022
8165393
feat: player 구현
hochan222 Feb 15, 2022
5e682f8
docs: player 구현
hochan222 Feb 15, 2022
2c0ee93
test : Dealer 클래스의 테스트코드 작성
Feb 16, 2022
6d6cb04
feat : Dealer 클래스 구현
Feb 16, 2022
35ca712
docs : Dealer 클래스 구현
Feb 16, 2022
64ce0e8
docs : Dealer 클래스 구현 checkbox 추가
Feb 16, 2022
bb07a41
test : GameUser 클래스 테스트 작성
Feb 16, 2022
d93d497
feat : GameUser 클래스 구현
Feb 16, 2022
78af8ab
docs : GameUser 클래스 구현
Feb 16, 2022
19f4ef3
refactor : GameUser 리팩토링
Feb 16, 2022
cd83748
refactor : Dealer 정적 상태 변수명 변경
Feb 16, 2022
a761d7c
feat : GameCard shuffle 기능 추가
Feb 16, 2022
c5a791d
feat : BlackJack 클래스 구현
Feb 16, 2022
5feebd2
feat : BlackJack 클래스 구현
Feb 16, 2022
7ad8fe2
feat : BlackJack 클래스 구현
Feb 16, 2022
4b81f6b
docs : BlackJack 클래스 구현
Feb 16, 2022
452aa4c
refactor : GameUser의 Playter, Dealer 책임 분리
Feb 16, 2022
359ff2f
refactor : 메소드 참조로 변경
Feb 16, 2022
d8f4f20
feat : BlackJack 구현
Feb 16, 2022
3e33b79
docs : BlackJack 구현
Feb 16, 2022
2c71cbf
feat: Game - 전체적인 게임을 진행할 Controller 구현 및 InputView, OutputView 로직 추가
hochan222 Feb 16, 2022
d0e97ac
docs: Game - 전체적인 게임을 진행할 Controller 구현 및 InputView, OutputView 로직 추가
hochan222 Feb 16, 2022
03ea0d5
feat: phase 출력 구현
hochan222 Feb 16, 2022
7908ef9
feat: convertTotalScore 메서드 구현, UserStats
hochan222 Feb 17, 2022
d7a5c87
test: convertTotalScore 메서드 구현에 따른 dealer이름 수정
hochan222 Feb 17, 2022
37c524e
docs: convertTotalScore 메서드 구현
hochan222 Feb 17, 2022
44216e4
docs: convertTotalScore 메서드 구현
hochan222 Feb 17, 2022
2589dfc
feat : UserStats 구현
Feb 17, 2022
352de29
refactor : User 추상 클래스로 리팩토링
Feb 17, 2022
83bcacb
refactor: getScore within 10 line
hochan222 Feb 18, 2022
52fe5e1
refactor: remove not use Score
hochan222 Feb 18, 2022
0f7ea39
style: UserStats
hochan222 Feb 18, 2022
4e5dc51
refactor: Game's function within 10 lines
hochan222 Feb 18, 2022
981ae7d
refactor : RentCompanyTest 리팩토링
Feb 21, 2022
1d218f0
refactor : Enum 사용
Feb 21, 2022
08d0258
refactor : Deck 리팩토링
Feb 21, 2022
c82c962
refactor : Card 리팩토링
Feb 21, 2022
2f3bfd5
refactor : Dealer, Player 리팩토링
Feb 21, 2022
d2ece34
refactor : 불필요한 메서드 제거
Feb 21, 2022
d7e3bef
refactor : View 로직 Controller로 이동
Feb 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 149 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,149 @@
# java-blackjack
# 연료 주입

## TDD 기능 구현 사항

- [x] Sonata
- [x] `Sonata` String Type 이름을 가져야한다.
- [x] `10km/리터`의 연비 가져야한다.
- [x] 거리
- [x] 거리를 가져야한다.
- [x] 거리는 `0` 이상 정수이어야 한다.
- [x] 주입해야할 연료량을 구할 수 있다.
- [x] Avante
- [x] `Avante` String Type 이름을 가져야한다.
- [x] `15km/리터`의 연비 가져야한다.
- [x] 거리 가져야한다.
- [x] 거리는 `0` 이상 정수이어야한다. -
- [x] 주입해야할 연료량을 구할 수 있다.
- [x] K5
- [x] `K5` String Type 이름을 가져야한다.
- [x] `13km/리터`의 연비 가져야한다.
- [x] 거리 가져야한다.
- [x] 거리는 `0` 이상 정수이어야한다.
- [x] 주입해야할 연료량을 구할 수 있다.
- [x] RentCompany
- [x] `List<Car>`을 가져야한다.
- [x] `List<Car>`에 대한 getter를 가져야한다.
- [x] `create()`, 팩토리 메서드를 구현한다.
- [x] `addCar()`, 차를 추가할 수 있다.
- [x] `List<Car>`에 Sonata를 추가할 수 있다.
- [x] `List<Car>`에 Avante를 추가할 수 있다.
- [x] `List<Car>`에 K5를 추가할 수 있다.
- [x] `generateReport()`는 전체 결과를 출력한다.

## 기능 구현 사항

- 보유 차량
- Sonata
- 대수: 2대
- 연비: 10km/리터
- Avante
- 대수: 1대
- 연비: 15km/리터
- K5
- 대수: 2대
- 연비: 13km/리터
- 고객이 인터넷으로부터 예약할 때 여행할 목적지의 대략적인 이동거리를 입력 받을 수 있다.
- 이동거리를 활용해 차량 별로 필요한 연료를 주입할 수 있다.
- 차량 별로 주입해야 할 연료량을 확인할 수 있는 보고서를 생성할 수 있다.

## 프로그래밍 요구 사항

- [x] 상속과 추상 메서드를 활용한다.
- [x] 위 요구사항을 if/else 절을 쓰지 않고 구현해야 한다.
- [x] 인터페이스를 적용해 구현한다.

---

# java-blackjack

## TDD 기능 구현 사항

- [x] User
- [x] Deck을 가지고 있다.
- [x] UserName을 가지고 있다.
- [x] Deck에 카드를 추가할 수 있다.
- [x] 해당 카드의 점수인 score를 반환할 수 있다.
- [x] Dealer
- [x] Deck을 가지고 있다.
- [x] UserName을 가지고 있다. - name은 `dealer`라는 기본 이름을 가진다.
- [x] 현재 score가 16이하 인지를 판단하여 반환할 수 있다.
- [x] 1장의 카드를 추가로 받을 수 있다.
- [x] Player
- [x] Deck을 가지고 있다.
- [x] UserName을 가지고 있다.
- [x] 현재 score가 21을 넘지 않는지를 판단하여 반환할 수 있다.
- [x] Deck - 딜러 또는 플레이어가 가진 Card의 집합
- [x] List<Card>를 가지고 있다.
- [x] 현재 List<Card>의 총 score를 계산할 수 있다.
- [x] Deck의 현재 score가 21을 넘는지에 대한 boolean 계산을 할 수 있다.
- [x] 현재 가진 Card 중에서 Ace가 있는 경우, 해당 Card에 대한 Score를 1 또는 11로 계산할 수 있다.
- [x] 21을 초과하지 않으면서, 21에 가깝게 계산할 수 있다.
- [x] Card - Game에서 사용할 카드의 객체
- [x] CardType type을 가지고 있다. (e.g 다이아몬드, 클로버, 스페이드, 하트 ...)
- [x] CardNumber _String을_ 가지고 있다. (e.g 2, 3, A, K, Q, J ...)
- [x] 카드 숫자와 카드 타입을 입력할때, 주어진 숫자와 타입으로 카드가 생성된다.
- [x] CardType - Card의 타입
- [x] CardType은 `"다이아몬드", "하트", "클로버", "스페이드"` 이 범위안에 반드시 있어야한다.
- [x] CardNumber - Card의 숫자
- [x] CardNumber는 `"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"` 이 범위안에 반드시 있어야한다.
- [x] GameCard - 게임에서 사용될 모든 Card의 집합
- [x] 모든 Card는 중복이 없어야한다.
- [x] 총 52 장이 있어야한다.
- [x] 모든 Card를 셔플할 수 있다.
- [x] GameUser - BlackJack을 수행하는 User의 집합
- [x] List<User>를 가지고 있다.
- [x] User를 추가할 수 있다.
- [x] List<User>를 반환할 수 있다.
- [x] BlackJack - 게임 로직 수행
- [x] GameUser를 가지고 있다.
- [x] GameCard를 가지고 있다.
- [x] 게임 진행시 최초로 GameCard를 셔플할 수 있다.
- [x] User별로 초기 카드를 나눠준다.
- [x] GameCard에서 Card를 두 장 뽑기
- [x] User에게 Card 전달하기
- [x] Dealer는 총 score가 16이하일 경우, 1장의 카드를 추가로 받는다.
- [x] User별로 턴을 진행할 수 있게 한다.
- [x] GameCard에서 Card를 한 장 뽑기
- [x] User에게 Card 전달하기
- [x] Player는 총 score가 21이하일 경우, 1장의 카드를 추가로 받을 수 있다.
- [x] UserStats - User별 승/패에 대한 정보
- [x] GameUser를 인자로 받아 User별, 승/패 정보를 계산한다.
- [x] User별 Deck의 score를 출력하기 위한 String을 반환할 수 있다. convertTotalScore()
- [x] User별 최종 승/패를 출력하기 위한 String을 반환할 수 있다. convertTotalResult()
- [x] User별 Deck의 score가 21을 초과할 경우, 승/패를 계산할 수 있다.
- [x] Dealer의 score가 21을 초과할 경우, Player가 승리한다.
- [x] Dealer의 score가 21을 초과하지 않고, Player의 score가 21을 초과하는 경우, Dealer가 승리한다.
- [x] Game - 전체적인 게임을 진행할 Controller
- [x] 이름의 배열을 BlackJack에 전달한다.
- [x] 싱글턴 패턴 적용
- [x] UserName - 게임 참여자의 이름
- [x] InputView
- [x] 게임에 참여할 이름을 입력받는다.
- [x] OutputView

## 최초 PR 마감 기한

2월 17일 목요일까지

### test

```bash
./gradlew clean check
```

### git pull pair

```bash
git pull pair step1
```

### git multiple author

```bash
git commit -m "commit message


Co-authored-by: hochan222 <hochan049@gmail.com>
Co-authored-by: chanuuuuu <dn0208@gmail.com>
```
11 changes: 11 additions & 0 deletions src/main/java/blackJack/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package blackJack;

import blackJack.controller.Game;

public class Application {

public static void main(String[] args) {
Game game = Game.getInstance();
game.run();
}
}
80 changes: 80 additions & 0 deletions src/main/java/blackJack/controller/Game.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package blackJack.controller;

import blackJack.domain.BlackJack;
import blackJack.domain.Player;
import blackJack.domain.UserStats;
import blackJack.util.Util;
import blackJack.view.InputView;
import blackJack.view.OutputView;
import java.util.List;

public class Game {

private static Game game = null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분이 필요한 이유는 무엇일까요?
없어도 되지 않을까요? ″̮

또한 Controller는 상태를 가지고 있지 않아도 될 것 같습니다 ″̮

private final BlackJack blackJack;

private Game(List<String> playerNames) {
blackJack = BlackJack.from(playerNames);
}

public static Game getInstance() {
if (game == null) {
game = new Game(getPlayerName());
}
return game;
}

public void run() {
init();
goPhase();
summarize();
}

private void init() {
blackJack.initCardDraw();
OutputView.printInitCardDrawFormat(blackJack.getGameUser().convertPlayersName());
OutputView.printUserStatus(blackJack.getGameUser());
}

private void goPhase() {
playerPhase();
dealerPhase();
}

private void playerPhase() {
for (Player player : blackJack.getGamePlayers()) {
useTurn(player);
}
}

private void useTurn(Player player) {
while (player.isCardDraw()) {
OutputView.printRequestAdditionalCardDrawFormat(player);
if (InputView.readYN()) {
player.appendToDeck(blackJack.drawGameCard());
OutputView.printPlayerStatus(player);
continue;
}
OutputView.printPlayerStatus(player);
break;
}
}

private void dealerPhase() {
if (blackJack.getGameDealer().isCardDraw()) {
blackJack.getGameDealer().additionalCardDraw(blackJack.drawGameCard());
OutputView.printDealerAdditionalCardDraw();
}
}

private void summarize() {
UserStats userStats = UserStats.of(blackJack.getGameUser());
OutputView.printTotalScore(userStats.convertTotalScore());
OutputView.printTotalResult(userStats.convertTotalResult());
}

private static List<String> getPlayerName() {
OutputView.printRequestPlayerNames();
return Util.stringToStringList(InputView.readPlayerName());
}
}
59 changes: 59 additions & 0 deletions src/main/java/blackJack/domain/BlackJack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package blackJack.domain;

import java.util.List;

public class BlackJack {

private static final int INITIAL_DRAW_CARD_COUNT = 2;

private final GameUser gameUser;
private final GameCard gameCard;

private BlackJack(List<String> userNames) {
this.gameUser = GameUser.from(userNames);
this.gameCard = GameCard.create();
cardShuffle();
}

public static BlackJack from(List<String> userNames) {
return new BlackJack(userNames);
}

private void cardShuffle() {
gameCard.shuffle();
}

public void initCardDraw() {
initDealerDraw();
initPlayerDraw();
}

private void initDealerDraw() {
gameUser.getDealer().appendToDeck(gameCard.drawCard(INITIAL_DRAW_CARD_COUNT));
}

private void initPlayerDraw() {
gameUser.getPlayers()
.forEach(player -> player.appendToDeck(gameCard.drawCard(INITIAL_DRAW_CARD_COUNT)));
}

public GameUser getGameUser() {
return gameUser;
}

public GameCard getGameCard() {
return gameCard;
}

public List<Player> getGamePlayers() {
return gameUser.getPlayers();
}

public Dealer getGameDealer() {
return gameUser.getDealer();
}

public Card drawGameCard() {
return gameCard.drawCard();
}
}
33 changes: 33 additions & 0 deletions src/main/java/blackJack/domain/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package blackJack.domain;

public class Card {

private final CardType cardType;
private final CardNumber cardNumber;

private Card(String cardType, String cardNumber) {
this.cardType = CardType.from(cardType);
this.cardNumber = CardNumber.from(cardNumber);
}

public static Card of(String cardType, String cardNumber) {
return new Card(cardType, cardNumber);
}

public boolean isAce() {
return cardNumber.getNumber().equals(TrumpNumber.ACE.getTrumpNumber());
}

public int getCardScore() {
return cardNumber.calculateScore();
}

public String getCardType() {
return cardType.getType();
}

public String getCardNumber() {
return cardNumber.getNumber();
}
}

35 changes: 35 additions & 0 deletions src/main/java/blackJack/domain/CardNumber.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package blackJack.domain;

public class CardNumber {

private static final String JQK_REGEX = "[JQK]";
private static final int JQK_SCORE = 10;
private static final int ACE_SCORE = 1;

private final TrumpNumber trumpNumber;

private CardNumber(String cardNumber) {
this.trumpNumber = TrumpNumber.from(cardNumber);
}

public static CardNumber from(String cardNumber) {
return new CardNumber(cardNumber);
}

public String getNumber() {
return trumpNumber.getTrumpNumber();
}

public int calculateScore() {
String number = trumpNumber.getTrumpNumber();

if (number.matches(JQK_REGEX)) {
return JQK_SCORE;
}
if (number.equals(TrumpNumber.ACE.getTrumpNumber())) {
return ACE_SCORE;
}

return Integer.parseInt(number);
}
}
18 changes: 18 additions & 0 deletions src/main/java/blackJack/domain/CardType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package blackJack.domain;

public class CardType {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CardType 객체를 생성하는 대신 Suit를 바로 사용해보는건 어떨까요?


private final Suit suit;

private CardType(String cardType) {
this.suit = Suit.from(cardType);
}

public static CardType from(String cardType) {
return new CardType(cardType);
}

public String getType() {
return suit.getName();
}
}
Loading