diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9c672c5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..f5858db --- /dev/null +++ b/src/Main.java @@ -0,0 +1,5 @@ +public class Main { + public static void main(String[] args) { + + } +} \ No newline at end of file diff --git a/src/controller/VendingMachineController.java b/src/controller/VendingMachineController.java new file mode 100644 index 0000000..c91085b --- /dev/null +++ b/src/controller/VendingMachineController.java @@ -0,0 +1,59 @@ +package controller; + +import domain.MenuOrder; +import domain.menu.HotMenu; +import domain.menu.IceMenu; +import ui.InputView; +import ui.OutputView; + +public class VendingMachineController { + + private final OutputView outputView; + private final InputView inputView; + + public VendingMachineController(OutputView outputView, InputView inputView) { + this.outputView = outputView; + this.inputView = inputView; + } + + public void getBeverage() { + MenuOrder menuOrder = getMenuOrder(); + + } + + private MenuOrder getMenuOrder() { + int menuType; + try { + menuType = Integer.parseInt(inputView.getMenuType()); + if (menuType > 2 || menuType < 1) { + throw new IllegalArgumentException("메뉴는 1, 2 번중에 골라야 합니다.") + } + } catch (NumberFormatException e) { + outputView.printError("잘못된 메뉴 종류입니다."); + return getMenuOrder(); + } catch (IllegalArgumentException e) { + outputView.printError(e.getMessage()); + return getMenuOrder(); + } + return getMenu(menuType); + } + + private MenuOrder getMenu(int menuType) { + int orderNumber; + MenuOrder menuOrder = null; + try { + if (menuType == 1) { + orderNumber = Integer.parseInt(inputView.getIceMenuNumber()); + menuOrder = new MenuOrder(IceMenu.getMenu(orderNumber)); + } + if (menuType == 2) { + orderNumber = Integer.parseInt(inputView.getHotMenuNumber()); + menuOrder = new MenuOrder(HotMenu.getMenu(orderNumber)); + } + } catch (IllegalArgumentException e) { + outputView.printError(e.getMessage()); + return getMenu(menuType); + } + return menuOrder; + } +} diff --git a/src/domain/MenuOrder.java b/src/domain/MenuOrder.java new file mode 100644 index 0000000..77bc11d --- /dev/null +++ b/src/domain/MenuOrder.java @@ -0,0 +1,25 @@ +package domain; + +import domain.menu.HotMenu; +import domain.menu.IceMenu; +import domain.menu.Menu; + +public class MenuOrder { + private Menu menu; + + public MenuOrder(Menu menu) { + this.menu = menu; + } + + private void validateOrder(Menu menu) { + if (menu == HotMenu.NONE || menu == IceMenu.NONE ) { + throw new IllegalArgumentException("잘못된 주문입니다.\n"); + } + } + + private + + public int getPrice() { + return menu.getPrice(); + } +} diff --git a/src/domain/menu/HotMenu.java b/src/domain/menu/HotMenu.java new file mode 100644 index 0000000..8fb4989 --- /dev/null +++ b/src/domain/menu/HotMenu.java @@ -0,0 +1,45 @@ +package domain.menu; + +import java.util.Arrays; + +public enum HotMenu implements Menu { + TOP(1, "TOP커피", 1_800), + HONEY_WATER(2, "꿀물", 1_500), + HONGSAM(3, "홍삼차", 1_700), + DANPAT(4, "단팥죽", 2_100), + NONE(-1, "없음", 0); + + private int number; + private String name; + private int price; + + HotMenu(int number, String name, int price) { + this.number = number; + this.name = name; + this.price = price; + } + + public static Menu getMenu(int number) { + return Arrays.stream(HotMenu.values()) + .filter(hotMenu -> hotMenu.number == number) + .findFirst() + .orElse(NONE); + } + + @Override + public int getNumber() { + return this.number; + } + + @Override + public int getPrice() { + return this.price; + } + + @Override + public String getName() { + return this.name; + } + + +} diff --git a/src/domain/menu/IceMenu.java b/src/domain/menu/IceMenu.java new file mode 100644 index 0000000..c5dcf82 --- /dev/null +++ b/src/domain/menu/IceMenu.java @@ -0,0 +1,48 @@ +package domain.menu; + +import java.util.Arrays; + +public enum IceMenu implements Menu { + SPRITE(1, "스프라이트", 1_500), + COKA(2, "코카콜라", 1_300), + SOLE(3, "솔의눈", 1_000), + PEPSI(4, "펩시 콜라", 1_100), + NONE(-1, "없음", 0); + private int number; + private String name; + private int price; + + IceMenu(int number, String name, int price) { + this.number = number; + this.name = name; + this.price = price; + } + + public static Menu getMenu(int number) { + return Arrays.stream(IceMenu.values()) + .filter(iceMenu -> iceMenu.number == number) + .findFirst() + .orElse(NONE); + } + + @Override + public int getNumber() { + return this.number; + } + + @Override + public int getPrice() { + return this.price; + } + + @Override + public String getName() { + return this.name; + } + +// +// @Override +// public String toString() { +// +// } +} diff --git a/src/domain/menu/Menu.java b/src/domain/menu/Menu.java new file mode 100644 index 0000000..08a733a --- /dev/null +++ b/src/domain/menu/Menu.java @@ -0,0 +1,14 @@ +package domain.menu; + +public interface Menu { + String INTRODUCTION_MESSAGE = "------------------------------\n" + + "음료를 선택 해주세요!\n" + + "\n" + + "[1] 차가운 음료\n" + + "[2] 따뜻한 음료\n"; + + int getNumber(); + int getPrice(); + String getName(); + +} diff --git a/src/domain/payment/Card.java b/src/domain/payment/Card.java new file mode 100644 index 0000000..aec1e95 --- /dev/null +++ b/src/domain/payment/Card.java @@ -0,0 +1,14 @@ +package domain.payment; + +import domain.menu.Menu; + +public class Card extends Payment { + public Card(Menu menu) { + super(menu); + } + + @Override + public int getChangeAmount() { + return 0; + } +} diff --git a/src/domain/payment/Cash.java b/src/domain/payment/Cash.java new file mode 100644 index 0000000..0c5061a --- /dev/null +++ b/src/domain/payment/Cash.java @@ -0,0 +1,28 @@ +package domain.payment; + +import domain.menu.IceMenu; +import domain.menu.Menu; + +import java.util.List; + +public class Cash extends Payment { + + public Cash(int payAmount) { + this.payAmount = payAmount; + } + + @Override + public int getChangeAmount() { + + } + + class MoneyType { + private String name; + private int value; + + public MoneyType(String name, int value) { + this.name = name; + this.value = value; + } + } +} diff --git a/src/domain/payment/Payment.java b/src/domain/payment/Payment.java new file mode 100644 index 0000000..e965061 --- /dev/null +++ b/src/domain/payment/Payment.java @@ -0,0 +1,8 @@ +package domain.payment; + +import domain.menu.Menu; + +public abstract class Payment { + private int payAmount; + public abstract int getChangeAmount(); +} diff --git a/src/ui/ConsoleView.java b/src/ui/ConsoleView.java new file mode 100644 index 0000000..f3ce4e2 --- /dev/null +++ b/src/ui/ConsoleView.java @@ -0,0 +1,19 @@ +package ui; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Scanner; + +public class ConsoleView implements View{ + @Override + public String in() { + Scanner sc = new Scanner(System.in); + return sc.nextLine(); + } + + @Override + public void out(String data) { + System.out.println(data); + } +} diff --git a/src/ui/InputView.java b/src/ui/InputView.java new file mode 100644 index 0000000..9857172 --- /dev/null +++ b/src/ui/InputView.java @@ -0,0 +1,43 @@ +package ui; + +import domain.menu.HotMenu; +import domain.menu.IceMenu; +import domain.menu.Menu; + +public class InputView extends ConsoleView { + public String getMenuType() { + out(Menu.INTRODUCTION_MESSAGE); + return in(); + } + + public String getIceMenuNumber() { + StringBuilder sb = new StringBuilder(); + sb.append("------------------------------\n" + "[차가운 음료]\n\n"); + for (Menu menu : IceMenu.values()) { + if (menu == IceMenu.NONE) { + continue; + } + sb.append("[" + menu.getNumber() + "] " + menu.getName() + " : " + String.format("%,d", menu.getPrice() + "원\n")); + } + out(sb.toString()); + return in(); + } + + public String getHotMenuNumber() { + StringBuilder sb = new StringBuilder(); + sb.append("------------------------------\n" + "[뜨거운 음료]\n\n"); + for (Menu menu : HotMenu.values()) { + if (menu == HotMenu.NONE) { + continue; + } + sb.append("[" + menu.getNumber() + "] " + menu.getName() + " : " + String.format("%,d", menu.getPrice() + "원")); + } + out(sb.toString()); + return in(); + } + + public String getPaymentType() { + out("------------------------------\n" + "[결제 방식 선택]"); + return in(); + } +} diff --git a/src/ui/OutputView.java b/src/ui/OutputView.java new file mode 100644 index 0000000..eb4f754 --- /dev/null +++ b/src/ui/OutputView.java @@ -0,0 +1,7 @@ +package ui; + +public class OutputView extends ConsoleView{ + public void printError(String message) { + out("[에러] : " + message); + } +} diff --git a/src/ui/View.java b/src/ui/View.java new file mode 100644 index 0000000..24cdaf1 --- /dev/null +++ b/src/ui/View.java @@ -0,0 +1,6 @@ +package ui; + +public interface View { + String in(); + void out(String data); +} diff --git a/vendingmachine.iml b/vendingmachine.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/vendingmachine.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file