Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
794c525
docs: 연료 주입 구현 사항 목록 작성
0JUUU Feb 13, 2022
d75a5f4
feat: 불필요한 파일 제거
0JUUU Feb 13, 2022
4fea65a
feat: 사용자 입력을 관리하는 InputView 클래스 구현
0JUUU Feb 13, 2022
ff68c0f
feat: 자동차 추상화 클래스 Car 구현
0JUUU Feb 13, 2022
977b285
feat: 소나타에 관한 테스트 SonataTest 구현
0JUUU Feb 13, 2022
ab5a54e
feat: Sonata 클래스 구현
0JUUU Feb 13, 2022
b83e167
feat: 아반떼에 관한 테스트 AvanteTest 구현
0JUUU Feb 13, 2022
6b90041
feat: Avante 클래스 구현
0JUUU Feb 13, 2022
619bc0b
feat: K5에 대한 테스트 K5Test 클래스 구현
0JUUU Feb 13, 2022
42bc897
feat: K5 클래스 구현
0JUUU Feb 13, 2022
2ea68bc
feat: add ignore
0JUUU Feb 14, 2022
a52796e
refactor: tripDistance 부모 필드에서 상속 받도록 변경.
0JUUU Feb 14, 2022
5fb53cf
feat: 입력을 저장하는 Rent VO 객체 추가
0JUUU Feb 14, 2022
37c0b78
feat: Rent 클래스 equals & hashCode 재정의
0JUUU Feb 14, 2022
0440900
feat: InputView 클래스 생성자 제한접근자 변경
0JUUU Feb 14, 2022
7603b88
feat: 사용자 입력을 파싱하여 Rent 객체 리스트를 반환
0JUUU Feb 14, 2022
f822ac0
test: Parser에 대한 테스트코드 작성
0JUUU Feb 14, 2022
e9205ee
docs: 연료 주입 구현 사항 목록 수정
0JUUU Feb 14, 2022
8b2cd26
feat: 이름에 따라 Car 객체를 반환하는 CarFactory enum 클래스 생성
0JUUU Feb 14, 2022
98acb61
test: CarFactory 클래스에 대한 테스트코드 작성
0JUUU Feb 14, 2022
f408a4c
feat: Car 객체 내 equals & hashcode 오버라이드
0JUUU Feb 14, 2022
88fb5d3
docs: 연료 주입 구현 사항 목록 수정
0JUUU Feb 14, 2022
ccff25c
feat: 여행거리가 1보다 작은 경우에 대한 예외처리 적용
0JUUU Feb 14, 2022
3daf149
feat: 1보다 작은 여행거리에 대한 테스트케이스 작성
0JUUU Feb 14, 2022
fa50f21
docs: 연료 주입 구현 사항 목록 수정
0JUUU Feb 14, 2022
b803fc1
feat: 대소문자 구분없이 Car 객체를 반환하는지 확인하는 테스트코드 작성
0JUUU Feb 14, 2022
4a56d05
refactor: 추상 메서드 접근제한자 default에서 public으로 변경
0JUUU Feb 14, 2022
738c9a7
refactor: CarFactory -> RentCar 네이밍 변경
0JUUU Feb 14, 2022
933475e
rename: Rent -> RentInfo 네이밍 변경
0JUUU Feb 14, 2022
d73ed2b
test: 렌트 예약 기능에 대한 테스트코드 작성
0JUUU Feb 14, 2022
5d665a6
feat: 렌트 예약 및 예약 여부 검증 기능 구현
0JUUU Feb 14, 2022
f8ebd34
test: 보고서 생성 관련 테스트 작성
0JUUU Feb 14, 2022
662a943
feat: 연료 주입량 보고서 생성 기능 구현
0JUUU Feb 14, 2022
f6c9906
feat: 출력 담당하는 ResultView 구현
0JUUU Feb 14, 2022
9dc45d6
feat: 연료 주입 Application 구현
0JUUU Feb 14, 2022
e751fa1
refactor: 불변 final 키워드 추가
0JUUU Feb 14, 2022
3b5ed7f
refactor: 메서드 접근제한자 변경
0JUUU Feb 14, 2022
75db369
refactor: name -> type으로 네이밍 변경
0JUUU Feb 14, 2022
4d32352
refactor: Integer -> int로 타입 변환
0JUUU Feb 15, 2022
0d0c16c
refactor: 메서드 추출
0JUUU Feb 15, 2022
06ea5cd
refactor: 메서드 추출
0JUUU Feb 15, 2022
e1c079b
docs: 블랙잭 구현 목록 정의.
0JUUU Feb 15, 2022
50dfc66
feat: 입력에 관한 클래스 InputView 구현
0JUUU Feb 15, 2022
f49f470
docs: 블랙잭 구현 사항 수정
0JUUU Feb 15, 2022
410e153
feat: 입력값을 파싱해주는 Parser 클래스 구현
0JUUU Feb 15, 2022
619bcb2
test: Parser 테스트코드 구현
0JUUU Feb 15, 2022
4ca64b4
docs: 블랙잭 구현 사항 수정
0JUUU Feb 15, 2022
4e3d897
feat: 카드 문양 클래스 생성
0JUUU Feb 15, 2022
7591931
feat: 카드 명칭 클래스 구현
0JUUU Feb 15, 2022
64005c1
feat: Card 클래스 생성 및 카드 종류이름 반환 기능 구현.
0JUUU Feb 15, 2022
2ec0076
test: Card 종류 이름 반환 기능 테스트
0JUUU Feb 15, 2022
b04ea08
test: 자신이 ACE인지 반환하는 기능 테스트
0JUUU Feb 15, 2022
b7dd06d
feat: 자신이 ACE인지 반환하는 기능 추가.
0JUUU Feb 15, 2022
10cb842
rename: Denomination -> Rank로 네이밍 변경
0JUUU Feb 15, 2022
3a2e8b1
docs: update README.md
0JUUU Feb 15, 2022
12a2fff
refactor: final로 변경
0JUUU Feb 15, 2022
9cc57ae
refactor: public -> protected 접근제한자 변경
0JUUU Feb 15, 2022
7008600
feat: equals & hashcode 재정의
0JUUU Feb 15, 2022
de8b298
feat: Cards 구현
0JUUU Feb 15, 2022
dd8c4cc
test: Deck 테스트코드 구현
0JUUU Feb 15, 2022
cfe7011
feat: 전체 카드를 갖고 있는 Deck 구현
0JUUU Feb 15, 2022
bcc2005
docs: 블랙잭 구현 사항 목록 수정
0JUUU Feb 15, 2022
91aa5cd
refactor: protected -> private 생성자 접근제한자 변경
0JUUU Feb 15, 2022
485735f
test: Cards에 대한 테스트코드 구현
0JUUU Feb 15, 2022
437ca51
test: Score에 대한 테스트코드 구현
0JUUU Feb 16, 2022
76d4db6
feat: 카드들의 합 Score 구현
0JUUU Feb 16, 2022
dddd016
test: Hands에 대한 테스트 구현
0JUUU Feb 16, 2022
2373537
feat: 참가자의 카드 관리하는 Hands 구현
0JUUU Feb 16, 2022
6e329cf
docs: 블랙잭 구현 사항 수정
0JUUU Feb 16, 2022
c2556e9
refactor: public으로 접근제한자 변경
0JUUU Feb 16, 2022
21b6368
feat: 참가자 추상 클래스 Participant 구현
0JUUU Feb 16, 2022
0033435
test: Player에 관한 테스트 구현
0JUUU Feb 16, 2022
7949bcd
test: Dealer에 대한 테스트 구현
0JUUU Feb 16, 2022
829037e
feat: 일반 플레이어 Player 구현
0JUUU Feb 16, 2022
125501e
feat: 딜러 Dealer 구현
0JUUU Feb 16, 2022
385903f
docs: 블랙잭 구현 사항 목록 수정
0JUUU Feb 16, 2022
3d0162d
style: 주석 관리
0JUUU Feb 16, 2022
f75bac5
refactor: InputView 유틸 클래스로 변경.
0JUUU Feb 16, 2022
d938a77
feat: 참가자 이름 추가
0JUUU Feb 16, 2022
df47d5c
docs: 블랙잭 참가자 이름에 대한 구현 사항 목록 수정
0JUUU Feb 16, 2022
2df412f
style: 구글 코드 컨벤션 적용
0JUUU Feb 16, 2022
a40bd3d
test: Game 관련 테스트 구현
0JUUU Feb 16, 2022
b0b47a4
feat: 카드를 분배하는 Game 구현
0JUUU Feb 16, 2022
330913e
refactor: Cards -> Deck 변경, 기존 Deck 제거
0JUUU Feb 16, 2022
df0be65
refactor: default -> public 접근제한자 변경
0JUUU Feb 16, 2022
348507e
feat: 참가자가 가지고 있는 카드 이름들을 반환하는 메서드 구현
0JUUU Feb 16, 2022
300e059
feat: 초기 분배 결과 출력 구현
0JUUU Feb 16, 2022
318d553
test: 중복 없이 모든 카드가 뽑힌다
0JUUU Feb 16, 2022
696cd0b
feat: 뽑힌 카드를 제거하도록 구현
0JUUU Feb 16, 2022
c77f874
docs: 블랙잭 OutputView 구현 사항 수정
0JUUU Feb 16, 2022
ce71f13
refactor: 기존 Deck, Game 이름 변경
0JUUU Feb 17, 2022
22150b7
refactor: final 키워드 추가
0JUUU Feb 17, 2022
7a5aed7
refactor: 팀 코드 컨벤션 적용
0JUUU Feb 17, 2022
fc6043b
fix: EIGHT의 이름이 7이던 걸 8로 변경
0JUUU Feb 17, 2022
2f94a6e
refactor: 불필요한 import문 제거
0JUUU Feb 17, 2022
330c4c9
feat: 추가 카드 Draw 구현
0JUUU Feb 17, 2022
460f2c4
style: 공백 및 줄바꿈 수정
0JUUU Feb 17, 2022
930eb9a
test: Judge 관련 테스트 구현
0JUUU Feb 17, 2022
c982483
feat: 참가자들의 승패를 판단하는 Judge 구현
0JUUU Feb 17, 2022
3835cb6
docs: 블랙잭 구현 사항 수정
0JUUU Feb 17, 2022
9f64fad
refactor: 네이밍 변경
0JUUU Feb 17, 2022
2b18ffa
refactor: 변수, 메서드 네이밍 변경
0JUUU Feb 17, 2022
525c261
refactor: Dealer, Player 생성자 파라미터 변경
0JUUU Feb 17, 2022
9ee25c2
refactor: getWinOrLose 로직 메서드 추출 및 네이밍 변경.
kimtaejun97 Feb 17, 2022
3bd09b5
feat: getStartCardNames 추가.
kimtaejun97 Feb 18, 2022
36f6d1d
fix: 플레이어 Score limit 설정 변경.
kimtaejun97 Feb 18, 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
144 changes: 144 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,147 @@ out/

### VS Code ###
.vscode/


# Created by https://www.toptal.com/developers/gitignore/api/macos,intellij
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,intellij

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij Patch ###
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721

# *.iml
# modules.xml
# .idea/misc.xml
# *.ipr

# Sonarlint plugin
# https://plugins.jetbrains.com/plugin/7973-sonarlint
.idea/**/sonarlint/

# SonarQube Plugin
# https://plugins.jetbrains.com/plugin/7238-sonarqube-community-plugin
.idea/**/sonarIssues.xml

# Markdown Navigator plugin
# https://plugins.jetbrains.com/plugin/7896-markdown-navigator-enhanced
.idea/**/markdown-navigator.xml
.idea/**/markdown-navigator-enh.xml
.idea/**/markdown-navigator/

# Cache file creation bug
# See https://youtrack.jetbrains.com/issue/JBR-2257
.idea/$CACHE_FILE$

# CodeStream plugin
# https://plugins.jetbrains.com/plugin/12206-codestream
.idea/codestream.xml

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# End of https://www.toptal.com/developers/gitignore/api/macos,intellij
120 changes: 119 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,119 @@
# java-blackjack
# 📌 연료 주입

## 기능 요구 사항
우리 회사는 렌터카를 운영하고 있다.
현재 보유하고 있는 차량은 Sonata 2대, Avante 1대, K5 2대로 총 5대의 차량을 보유하고 있다.
고객이 인터넷으로부터 예약할 때 여행할 목적지의 대략적인 이동거리를 입력 받는다.
이 이동거리를 활용해 차량 별로 필요한 연료를 주입한다. 차량 별로 주입해야 할 연료량을 확인할 수 있는 보고서를 생성해야 한다.

각 차량별 연비는 다음과 같다.

* Sonata : 10km/리터
* Avante : 15km/리터
* K5 : 13km/리터


## 구현 사항
- [x] 입력 (e.g. carName1:distance, carName2:distance)
- [x] 문자 사이에 불필요한 공백을 제거한다.

- [x] 파서 - Parser
- [x] 자동차는 `,` 로 구분한다.
- [x] 자동차의 이름과 속력은 `:` 로 구분한다.
- [x] 검증
- [x] 빈 값이 들어올 수 없다.
- [x] 이름이나 거리에 빈 값이 들어올 수 없다.
- [x] 입력 형식에 맞는지 확인한다.

- [x] 렌터카 회사 - RentCompany
- [x] 자동차 객체를 받아 예약을 승인한다. - acceptReservation(List<RentInfo> rentInfos)
- [x] 보유한 렌터카의 수를 넘지 않는다. - validateOverMinTripDistance
- [x] 차량 별로 주입해야 할 연료량을 확인할 수 있는 보고서를 생성한다. - createReport

- [x] 자동차 - abstract
- [x] 주입해야 할 연료량을 구한다. - getChargeQuantity

- [x] 렌트카 -RentCar
- [x] 여행 거리와 타입을 받아 Car 객체 생성.
- [x] 검증
- [x] 자동차 이름 확인(대소문자 구분 X)
- [x] 거리는 1 이상이어야 한다.

- [x] 출력
- [x] 생성한 보고서 출력.


# 📌 블랙잭

## 기능 요구 사항
블랙잭 게임을 변형한 프로그램을 구현한다. 블랙잭 게임은 `딜러`와 `플레이어` 중 카드의 합이 21 또는 21에 가장 가까운 숫자를 가지는 쪽이 이기는 게임이다.

카드의 숫자 계산은 카드 숫자를 기본으로 하며, 예외로 `Ace는 1 또는 11`로 계산한다.
- King, Queen, Jack은 각각 10으로 계산한다.
- 게임을 시작하면 플레이어는 두 장의 카드를 지급 받는다.
- 두 장의 카드 숫자를 합쳐 21을 초과하지 않으면서 21에 가깝게 만들면 이긴다. 21을 넘지 않을 경우 원한다면 얼마든지 카드를 계속 뽑을 수 있다.
- 딜러는 처음에 받은 2장의 합계가 16이하이면 반드시 1장의 카드를 추가로 받아야 하고, 17점 이상이면 추가로 받을 수 없다.
- 게임을 완료한 후 각 플레이어별로 승패를 출력한다.
- 딜러와 플레이어의 카드 합이 같을 경우, 딜러가 승리한다.
- 딜러와 플레이어가 모두 21을 넘었을 때, 딜러가 승리한다.

- 카드 : 스페이드, 클로버, 하트, 다이아 1~10, JQK

## 구현 사항.

- [x] InputView
- [x] 플레이어의 이름을 받는다. (`,`로 구분)
- [x] 카드를 받을 지에 대한 여부 입력 (`y`, `n`으로 구분)
- [x] 'y' 와 'n'이 아닐 경우 exception이 발생한다.

- [x] Parser
- [x] 플레이어 이름이 비어있는지 확인한다.

- [x] Deck
- [x] 카드 분배

- [x] Cards
- [x] Cards(list<Card>: pattern, rank)
- [x] 카드 뽑기 - draw
- [x] 빈 덱이라면 예외 발생
- [x] 카드 제거 - Cards remove(Card card)

- [x] Card
- [x] ACE 인지 확인.
- [x] 이름(patter + rank)

- [x] Hands
- [x] 두 장의 카드로 초기화
- [x] 카드 관리
- [x] 현재 점수 관리
- [x] ACE의 값을 결정한다.

- [x] Score
- [x] Card의 합
- [x] 기존 합에 한장의 Card의 값을 더한 값을 반환한다.

- [x] Judge
- [x] 승패 구하기
- [x] 딜러와 플레이어의 카드 합이 같을 경우, 딜러가 승리한다.
- [x] 딜러와 플레이어가 모두 21을 넘었을 때, 딜러가 승리한다.

- [x] abstract Participant (딜러, 플레이어)
- [x] 이름을 가진다.
- [x] 자신의 패를 가진다.
- [x] 카드패의 합산을 구한다. (구현)
- [x] 카드를 더 받을 수 있는지.

- [x] Player extends Participant
- [x] 플레이어 이름을 반환한다. (Override)
- [x] 카드를 더 받을 수 있는지. (Override) -> 카드의 합이 21을 초과하면 턴을 종료한다.

- [x] Dealer extends Participant
- [x] '딜러' 를 반환한다. (Override)
- [x] 카드를 더 받을 수 있는지. (Override) -> 카드의 합이 16을 초과하면 턴을 종료한다.

- [x] OutputView
- [x] 참가자 패
- [x] 참가자 카드 분배
- [x] 참가자 최종 결과
- [x] 참가자 최종 승패
- [x] 딜러는 16이하라 한장의 카드를 더 받았습니다.
63 changes: 63 additions & 0 deletions src/main/java/blackjack/BlackJackApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package blackjack;

import blackjack.domain.judge.Judge;
import blackjack.domain.card.Deck;
import blackjack.domain.participant.Dealer;
import blackjack.domain.participant.Participant;
import blackjack.domain.participant.Player;
import blackjack.util.Parser;
import blackjack.view.InputView;
import blackjack.view.OutputView;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class BlackJackApplication {

public static void main(String[] args) {
final Deck deck = new Deck();

final List<String> playerNames = Parser.parse(InputView.inputPlayerNames());
final Participant dealer = new Dealer(deck.dealCards());
final List<Participant> players = playerNames.stream()
.map(name -> new Player(name, deck.dealCards()))
.collect(Collectors.toList());

OutputView.printStartStatus(combine(dealer, players));

drawCardsIfWant(deck, players);
drawCardIfCan(deck, dealer);

final Judge judge = new Judge();
OutputView.printGameResult(combine(dealer, players), judge.getWinOrLose(dealer, players));
}

private static void drawCardsIfWant(final Deck deck, final List<Participant> players) {
players.forEach(player -> additionalDraw(deck, player));
}

private static void additionalDraw(final Deck deck, final Participant player) {
while (player.canDraw() && isAgree(player)) {
player.addCard(deck.draw());
OutputView.printParticipantsStatus(Collections.singletonList(player));
}
}

private static boolean isAgree(final Participant player) {
return InputView.inputDrawFlag(player.getName()).equalsIgnoreCase("y");
}

private static void drawCardIfCan(final Deck deck, final Participant dealer) {
if (dealer.canDraw()) {
dealer.addCard(deck.draw());
OutputView.printDealerDrawMessage();
}
}

private static List<Participant> combine(final Participant dealer, final List<Participant> participants) {
return Collections.unmodifiableList(
Stream.concat(Stream.of(dealer), participants.stream())
.collect(Collectors.toList()));
}
}
43 changes: 43 additions & 0 deletions src/main/java/blackjack/domain/card/Card.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package blackjack.domain.card;

import java.util.Objects;

public class Card {

private final Pattern pattern;
private final Rank rank;

public Card(final Pattern pattern, final Rank rank) {
this.pattern = pattern;
this.rank = rank;
}

public boolean isAce() {
return rank == Rank.ACE;
}

public String getName() {
return rank.getName() + pattern.getName();
}

public int getRank() {
return rank.getValue();
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Card card = (Card) o;
return pattern == card.pattern && rank == card.rank;
}

@Override
public int hashCode() {
return Objects.hash(pattern, rank);
}
}
Loading