forked from woowacourse/java-vendingmachine-precourse
-
Notifications
You must be signed in to change notification settings - Fork 3
4시간? 정도 걸린듯 #1
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
Open
ca1af
wants to merge
10
commits into
CODE-CLEANERS:main
Choose a base branch
from
ca1af:ca1af
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
4시간? 정도 걸린듯 #1
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
296242b
docs : 도메인별 요구사항 정리
ca1af d6d136a
feat : 상품 도메인 기능 작성
ca1af 9e7c635
feat : 상품 더미 도메인 작성
ca1af 3992094
feat : 코인 더미 도메인 작성
ca1af fea76b3
feat(Products) : 상품목록은 상품 이름을 통해 상품을 불러온다
ca1af 94b40e0
fix : 사용된 코인은 코인목록에서 제거된다.
ca1af bd5fec1
feat(ProductParser) : 사용자의 입력을 파싱해서 상품 목록으로 변환한다
ca1af 76786d8
feat(RandomCoinGenerator) : 자판기가 가질 잔돈은 랜덤값으로 생성된다
ca1af bf36e11
feat(VendingMachine) : 자판기 도메인 기능
ca1af a9f3c8d
feat : 어플리케이션 테스트 통과하도록 변경
ca1af File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,14 @@ | ||
| package vendingmachine; | ||
|
|
||
| import vendingmachine.presentation.InputView; | ||
| import vendingmachine.presentation.OutputView; | ||
| import vendingmachine.presentation.VendingMachineController; | ||
|
|
||
| public class Application { | ||
| public static void main(String[] args) { | ||
| // TODO: 프로그램 구현 | ||
| InputView inputView = new InputView(); | ||
| OutputView outputView = new OutputView(); | ||
| VendingMachineController vendingMachineController = new VendingMachineController(inputView, outputView); | ||
| vendingMachineController.run(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,55 @@ | ||
| package vendingmachine; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import vendingmachine.domain.DomainErrorMessage; | ||
|
|
||
| public enum Coin { | ||
| COIN_500(500), | ||
| COIN_100(100), | ||
| COIN_50(50), | ||
| COIN_10(10); | ||
|
|
||
| private static final int MINIMUM_MONEY_VALUE = 100; | ||
| private static final int MINIMUM_MONEY_THRESHOLD = 10; // TODO 이 부분 프로덕트와 중복이다. 제거한다. | ||
| private final int amount; | ||
|
|
||
| Coin(final int amount) { | ||
| this.amount = amount; | ||
| } | ||
|
|
||
| // 추가 기능 구현 | ||
| public static List<Coin> getCoinsFrom(int money){ | ||
| validateMoney(money); | ||
| return generateCoins(money); | ||
| } | ||
|
|
||
| private static List<Coin> generateCoins(int money) { | ||
| List<Coin> coins = new ArrayList<>(); | ||
| for (Coin coin : Coin.values()) { | ||
| int count = money / coin.amount; | ||
| money %= coin.amount; | ||
| addCoins(coin, count, coins); | ||
| } | ||
| return coins; | ||
| } | ||
|
|
||
| private static void addCoins(Coin coin, int count, List<Coin> coins) { | ||
| for (int i = 0; i < count; i++) { | ||
| coins.add(coin); | ||
| } | ||
| } | ||
|
|
||
| private static void validateMoney(int money){ | ||
| if (money % MINIMUM_MONEY_THRESHOLD != 0 || money < MINIMUM_MONEY_VALUE){ | ||
| throw new IllegalArgumentException(DomainErrorMessage.INVALID_MONEY.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public int getAmount() { | ||
| return amount; | ||
| } | ||
|
|
||
| public String customToString(int quantity) { | ||
| return amount + "원 - " + quantity + "개"; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package vendingmachine.domain; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import vendingmachine.Coin; | ||
|
|
||
| public class Coins { | ||
| private final List<Coin> coinsForChanges; | ||
|
|
||
| private Coins(List<Coin> coinsForChanges) { | ||
| validate(coinsForChanges); | ||
| this.coinsForChanges = coinsForChanges; | ||
| } | ||
|
|
||
| private void validate(List<Coin> coins){ | ||
| if (Objects.isNull(coins) || coins.isEmpty()) { | ||
| throw new IllegalArgumentException(DomainErrorMessage.INVALID_CHANGES.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public static Coins from(int money){ | ||
| List<Coin> coinsFromMoney = Coin.getCoinsFrom(money); | ||
| return new Coins(coinsFromMoney); | ||
| } | ||
|
|
||
| private int getCoinsSum(){ | ||
| return coinsForChanges.stream().mapToInt(Coin::getAmount).sum(); | ||
| } | ||
|
|
||
| public List<Coin> getChanges(int changes){ | ||
| if (getCoinsSum() <= changes){ | ||
| return coinsForChanges; | ||
| } | ||
| return Coin.getCoinsFrom(changes); | ||
| } | ||
|
|
||
| public void removeAll(List<Coin> changes) { | ||
| coinsForChanges.removeAll(changes); | ||
| } | ||
|
|
||
| public List<Coin> getCoinsForChanges() { | ||
| return coinsForChanges; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/vendingmachine/domain/DomainErrorMessage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package vendingmachine.domain; | ||
|
|
||
| public enum DomainErrorMessage { | ||
| INVALID_MONEY("가격 형식이 부적절합니다."), | ||
| INVALID_BUY_QUANTITY("구매하려는 수량이 재고 수량보다 많습니다."), | ||
| EMPTY_STOCK("상품 목록이 없습니다."), | ||
| INVALID_CHANGES("잔돈 입력 금액이 부적절합니다."), | ||
| INVALID_PRODUCT_NAME("상품 이름이 부적절합니다."), | ||
| NOT_ENOUGH_MONEY("상품 구매 금액이 부족합니다."), | ||
|
|
||
| DUPLICATED_NAMES("상품 이름이 중복되었습니다."); | ||
|
|
||
| private static final String ERROR = "[ERROR] "; | ||
| private final String message; | ||
|
|
||
| DomainErrorMessage(String message) { | ||
| this.message = message; | ||
| } | ||
|
|
||
| public String getMessage() { | ||
| return ERROR + message; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| package vendingmachine.domain; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class Product { | ||
| private static final int MINIMUM_MONEY_VALUE = 100; | ||
| private static final int MINIMUM_MONEY_THRESHOLD = 10; | ||
| private final String name; | ||
| private final int price; | ||
| private int quantity; | ||
|
|
||
| public Product(String name, int price, int quantity) { | ||
| this.name = name; | ||
| validateMoney(price); | ||
| this.price = price; | ||
| this.quantity = quantity; | ||
| } | ||
|
|
||
| private void validateMoney(int money){ | ||
| if (money % MINIMUM_MONEY_THRESHOLD != 0 || money < MINIMUM_MONEY_VALUE){ | ||
| throw new IllegalArgumentException(DomainErrorMessage.INVALID_MONEY.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| public int getPrice() { | ||
| return price; | ||
| } | ||
|
|
||
| public int getQuantity() { | ||
| return quantity; | ||
| } | ||
|
|
||
| public void decreaseQuantity(int buyQuantity) { | ||
| if (buyQuantity > this.quantity){ | ||
| throw new IllegalArgumentException(DomainErrorMessage.INVALID_BUY_QUANTITY.getMessage()); | ||
| } | ||
| this.quantity -= buyQuantity; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (!(o instanceof Product)) { | ||
| return false; | ||
| } | ||
| Product product = (Product) o; | ||
| return price == product.price && quantity == product.quantity && Objects.equals(name, product.name); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(name, price, quantity); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
이 방법은 가격이 높은 동전부터 최대한으로 생성하는 방식으로 보입니다. (450원 -> 500원 최대 0개, 100원 최대 4개, 50원 최대 1개...)
요구사항을 확인해보면,
"자판기가 보유하고 있는 금액을 입력하면 무작위로 동전을 생성한다" -> 동전생성은 무작위
"잔돈을 돌려줄 때 현재 보유한 최소 개수의 동전으로 잔돈을 돌려준다." -> 잔돈을 돌려줘야 할때 최소의 갯수로 반환
이기 때문에 코인 생성 방식을 제공받은 Random 라이브러리를 활용해 생성하는 방식으로 전환할 필요성이 있어 보입니다.
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.
이거 요구사항이 몬지 정확히 이해를 못했었음...어케해야대냐 이거