Conversation
| CoinController coinController = new CoinController(); | ||
| ProductController productController = new ProductController(); | ||
| MoneyController moneyController = new MoneyController(); | ||
| OrderController orderController = new OrderController(); |
There was a problem hiding this comment.
Service나 Domain 계층에 책임을 위임하지 않고, Controller에 구현하신 우진님만의 의도가 궁금합니다!
| MoneyController moneyController = new MoneyController(); | ||
| OrderController orderController = new OrderController(); | ||
|
|
||
| int[] coins = coinController.initMoney(); |
| public static boolean validateEmptyStock(Products products) { | ||
| //재고가 하나라도 있으면 진행 가능 | ||
| return products.getProducts().stream().anyMatch(product -> product.getStock() > 0); | ||
| } |
There was a problem hiding this comment.
재고 확인 검증을 Domain이 아닌 Controller에서 하신 이유가 궁금합니다!
| public static Product getProductByName(String name) { | ||
| return products.stream().filter(product -> product.getName().equals(name)).findFirst() | ||
| .orElse(null); | ||
| } |
There was a problem hiding this comment.
상품 이름으로 Product를 반환하는 메서드라면, findAny()를 사용하는게 더 좋지 않을까요?? 우진님의 의견은 어떠신지 궁금해요!
| } | ||
|
|
||
| public static String input() { | ||
| return readLine(); |
There was a problem hiding this comment.
항상 Console.readLint()을 사용해왔는데, 해당 라인처럼 더 간결하게 표현할 수 있어서 좋은 것 같아요!👍
| //보유 금액만큼 동전 생성 후 출력 | ||
| printCoins(coins); | ||
| return coins; | ||
| } |
|
|
||
| public int receiveMoney() { | ||
| printPurchasingMoneyMessage(); | ||
| return inputInteger(); |
There was a problem hiding this comment.
Console과 같은 라이브러리뿐만 아니라, InputView와 같은 클래스까지 모두 static import 하신 의도가 궁금합니다!
InputView를 명시해주는 편이 해당 클래스 내에서 역할 및 관계를 명확히 이해할 수 있다고 생각하는데 우진님의 의견은 어떠신가요??
|
|
||
| public void giveChange() { | ||
|
|
||
| } |
| CoinController coinController = new CoinController(); | ||
| ProductController productController = new ProductController(); | ||
| MoneyController moneyController = new MoneyController(); | ||
| OrderController orderController = new OrderController(); |
There was a problem hiding this comment.
컨트롤러가 많네요..
구현과 동시에 리팩토링을 추구하신 건가요??
| public class MoneyController { | ||
|
|
||
| public int receiveMoney() { | ||
| printPurchasingMoneyMessage(); | ||
| return inputInteger(); | ||
| } | ||
| } |
There was a problem hiding this comment.
컨트롤러 분리가 조금 과한 감이 있는 것 같아요. 코드가 많이 길어지면 그 때 가서 분리해도 좋을 것 같습니다!
| //동전 합이 total이 될 때까지 loop | ||
| //0부터 size까지를 왔다갔다할 인덱스 | ||
| int coinPrice = coinType[index].getAmount(); | ||
| //현재 index에 해당하는 동전의 액면가 | ||
| int possibleCoin = total / coinPrice; | ||
| //현재 index의 동전의 최대 개수 | ||
| List<Integer> numberRange = makeNumberRange(possibleCoin); | ||
| //pickNumberInList의 매개변수 타입에 맞게 0부터 possibleCoin까지의 모든 수를 넣은 List | ||
| if (possibleCoin > 0) { | ||
| //가능한 코인 개수가 있으면 | ||
| int pickedNumber = pickNumberInList(numberRange); | ||
| //랜덤 돌려서 | ||
| coins[index] += pickedNumber; | ||
| //코인 개수에 추가 | ||
| total -= coinPrice * pickedNumber; | ||
| //while문 조건에 반영하기 위해 동전개수 * 액면가를 total에서 제해줌 |
There was a problem hiding this comment.
주석은 설계 과정에서 스스로 쉽게 알아보기 위해 작성한 건가요?!
| private static final String HAVING_MONEY_MESSAGE = "자판기가 보유하고 있는 금액을 입력해 주세요."; | ||
| private static final String HAVING_COIN_MESSAGE = "\n자판기가 보유한 동전"; | ||
| private static final String ORDER_MESSAGE = "\n상품명과 가격, 수량을 입력해 주세요."; | ||
| private static final String PURCHASING_MONEY_MESSAGE = "\n투입 금액을 입력해 주세요."; | ||
| private static final String PURCHASING_MONEY = "\n투입 금액: %d원"; | ||
| private static final String PURCHASING_ITEM_MASSAGE = "구매할 상품명을 입력해 주세요."; | ||
| private static final String printForm = "%d원 - %d개"; |
There was a problem hiding this comment.
운영체제에 의존적이지 않은 줄바꿈 방법을 사용하면 더 좋을 것 같아요!
| for (int i = 0; i < coins.length; i++) { | ||
| System.out.println(String.format(printForm, Coin.values()[i].getAmount(), coins[i])); | ||
| } |
우선 늦어서 죄송합니다 ㅎㅎ ㅠㅠㅜ
5시간 동안 구현해보았는데 시간이 부족해서 미완성한 것들이 있습니다 -> 잔돈 거슬러주기, 오류 처리
코드리뷰하고 이 부분도 시간날 때 이어서 작성해보겠습니다!