-
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
base: main
Are you sure you want to change the base?
4시간? 정도 걸린듯 #1
Conversation
- 상품 도메인은 이름,가격,수량을 가진다 - 상품 도메인은 필드를 전부 리턴 가능하다 - 상품 도메인은 수량을 감소 가능하다
- 상품 더미는 상품 목록을 가진다 - 상품 최소 가격을 도출한다 - 상품 총 수량을 도출한다 - 상품 더미 초기화 시 빈 리스트나 null 이 들어오면 예외가 발생한다.
- 코인더미는 코인 리스트를 가진다. - 금액으로부터 코인 리스트를 생성 할 수 있다 - 입력된 잔돈이 현재 코인 보유량보다 많으면 보유량 전부를 리턴한다 - 입력된 잔돈이 현재 코인 보유량보다 적으면 필요량을 계산하여 리턴한다 - 부적절한 금액이 주어지면 예외가 발생한다
- 상품은 상품 이름으로 가격을 리턴 가능하다 - 상품 이름으로 재고를 차감 가능하다 - 중복된 상품 이름이 있으면 예외이다
- 코인을 가변 컬렉션으로 변경
- 사용자의 입력을 파싱해서 상품 목록으로 변환한다 - 정해진 포맷에 맞지 않으면 예외가 발생한다 - 상품 별 구분자는 ';'여야 한다 - 상품 내 이름,가격 등의 구분자는 ',' 이다 - 상품은 '이름, 가격, 수량' 세 가지 항목 모두를 포함해야 한다.
- 자판기는 제품을 살 수 있다 - 자판기는 남은 금액으로 제품을 더 살 수 있는지 판별 가능하다. - 자판기는 투입 금액을 리턴 가능하다 - 자판기는 돌려 줄 잔돈을 리턴 가능하다
| public static <T> T retry(Supplier<T> consumer){ | ||
| while (true){ | ||
| try { | ||
| return consumer.get(); | ||
| } catch (IllegalArgumentException e){ | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void retry(Runnable consumer){ | ||
| while (true){ | ||
| try { | ||
| consumer.run(); | ||
| return; | ||
| } catch (IllegalArgumentException e){ | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } | ||
| } |
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.
재입력이 필요한 구간을 handler로 처리하는 방식은 매우 SEXY합니다.
| 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; | ||
| } |
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.
이거 요구사항이 몬지 정확히 이해를 못했었음...어케해야대냐 이거
| } | ||
|
|
||
| public void run(){ | ||
| int changesInfo = RetryHandler.retry(inputView::getChangesInfo); |
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.
자판기 보유금액을 입력 받은 후 보유 동전 갯수 output이 나타나지 않습니다.
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.
😭
| Coins coins = RetryHandler.retry(() -> getCoins(changesInfo)); | ||
| VendingMachine vendingMachine = RetryHandler.retry(() -> new VendingMachine(coins, products, inputMoney)); | ||
| RetryHandler.retry(() -> purchaseProducts(vendingMachine)); | ||
| RetryHandler.retry(() -> printRemainingCoins(vendingMachine)); |
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.
최종 output에서 반환되지 않는 동전도 표시되는 문제가 있습니다.
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.
😱
| public String format() { | ||
| return coinMap.entrySet().stream() | ||
| .map(CoinsFormatter::formatEntry) | ||
| .collect(Collectors.joining(System.lineSeparator())); | ||
| } |
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.
잔돈 출력 형식을 Output 에서 처리하지 않고 포맷터로 변환 후 넘겨주는 방식은 매우 SEXY합니다.
| } | ||
|
|
||
| private static Product getProduct(String each) { | ||
| String[] namePriceQuantity = getNamePriceQuantity(each); |
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.
List 대신 배열을 사용한 특별한 이유가 있는지 궁금합니다.
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.
split 한 데이터를 따로 가공하는 게 구찮았기 때문...
가변 길이를 가질 이유가 없다(길이는 3이어야한다)도 있슴
No description provided.