From 77e3bfbb916186c787b3d10e6c1f3f39c15ee56c Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 13:24:52 +0900 Subject: [PATCH 01/16] =?UTF-8?q?feat:=20PosFunctions=20enum=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/domain/PosFunctions.java | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/main/java/domain/PosFunctions.java diff --git a/src/main/java/domain/PosFunctions.java b/src/main/java/domain/PosFunctions.java new file mode 100644 index 00000000..61169efb --- /dev/null +++ b/src/main/java/domain/PosFunctions.java @@ -0,0 +1,7 @@ +package domain; + +public enum PosFunctions { + ORDER_REGISTRATION, + PAYMENT, + EXIT; +} From a845f933eefd3d8d369137667feaf8853d26e01a Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 13:56:32 +0900 Subject: [PATCH 02/16] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=ED=95=A0=20Pos?= =?UTF-8?q?=20=EA=B8=B0=EB=8A=A5=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EA=B8=B0=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 27 +++++++++++++-- src/main/java/domain/PosFunction.java | 33 +++++++++++++++++++ src/main/java/domain/PosFunctions.java | 7 ---- .../java/view/IllegalUserInputException.java | 11 +++++++ src/main/java/view/InputView.java | 16 ++++++++- src/main/java/view/OutputView.java | 11 ++++++- 6 files changed, 93 insertions(+), 12 deletions(-) create mode 100644 src/main/java/domain/PosFunction.java delete mode 100644 src/main/java/domain/PosFunctions.java create mode 100644 src/main/java/view/IllegalUserInputException.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java index ea0d34fd..81a6d3a1 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -1,15 +1,32 @@ import domain.Menu; import domain.MenuRepository; +import domain.PosFunction; import domain.Table; import domain.TableRepository; +import java.util.Arrays; +import java.util.List; import view.InputView; import view.OutputView; -import java.util.List; - public class Application { - // TODO 구현 진행 + public static void main(String[] args) { + PosFunction posFunction; + + do { + OutputView.printPosFunctions(Arrays.asList(PosFunction.values())); + posFunction = PosFunction.of(InputView.inputPosFunction()); + + if (posFunction == PosFunction.ORDER_REGISTRATION) { + register_order(); + } + if (posFunction == PosFunction.PAYMENT) { + pay(); + } + } while (posFunction != PosFunction.EXIT); + } + + private static void register_order() { final List tables = TableRepository.tables(); OutputView.printTables(tables); @@ -18,4 +35,8 @@ public static void main(String[] args) { final List menus = MenuRepository.menus(); OutputView.printMenus(menus); } + + private static void pay() { + + } } diff --git a/src/main/java/domain/PosFunction.java b/src/main/java/domain/PosFunction.java new file mode 100644 index 00000000..809914df --- /dev/null +++ b/src/main/java/domain/PosFunction.java @@ -0,0 +1,33 @@ +package domain; + +import java.util.Arrays; + +public enum PosFunction { + ORDER_REGISTRATION(1, "주문등록"), + PAYMENT(2, "결제하기"), + EXIT(3, "프로그램 종료"); + + private int code; + private String korean; + + PosFunction(int code, String korean) { + this.code = code; + this.korean = korean; + } + + public static PosFunction of(int code) { + return Arrays.stream(PosFunction.values()) + .filter(posFunction -> posFunction.code == code) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 Pos 기능번호입니다.")); + } + + public int getCode() { + return this.code; + } + + @Override + public String toString() { + return this.korean; + } +} diff --git a/src/main/java/domain/PosFunctions.java b/src/main/java/domain/PosFunctions.java deleted file mode 100644 index 61169efb..00000000 --- a/src/main/java/domain/PosFunctions.java +++ /dev/null @@ -1,7 +0,0 @@ -package domain; - -public enum PosFunctions { - ORDER_REGISTRATION, - PAYMENT, - EXIT; -} diff --git a/src/main/java/view/IllegalUserInputException.java b/src/main/java/view/IllegalUserInputException.java new file mode 100644 index 00000000..7a2a6552 --- /dev/null +++ b/src/main/java/view/IllegalUserInputException.java @@ -0,0 +1,11 @@ +package view; + +public class IllegalUserInputException extends RuntimeException { + + public IllegalUserInputException() { + } + + public IllegalUserInputException(String message) { + super(message); + } +} diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index d5db24e2..e8d07609 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -3,10 +3,24 @@ import java.util.Scanner; public class InputView { + private static final Scanner scanner = new Scanner(System.in); + public static int inputPosFunction() { + System.out.println("## 원하는 기능을 선택하세요."); + return readIntegerByOneLine(); + } + public static int inputTableNumber() { System.out.println("## 주문할 테이블을 선택하세요."); - return scanner.nextInt(); + return readIntegerByOneLine(); + } + + private static int readIntegerByOneLine() { + try { + return Integer.parseInt(scanner.nextLine()); + } catch (NumberFormatException e) { + throw new IllegalUserInputException("정수만 입력 가능합니다."); + } } } diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index edb25cc4..ebc3aed0 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -1,15 +1,24 @@ package view; import domain.Menu; +import domain.PosFunction; import domain.Table; - import java.util.List; public class OutputView { + private static final String TOP_LINE = "┌ ─ ┐"; private static final String TABLE_FORMAT = "| %s |"; private static final String BOTTOM_LINE = "└ ─ ┘"; + public static void printPosFunctions(final List posFunctions) { + System.out.println("## 메인 화면"); + posFunctions.forEach( + posFunction -> System.out.println( + posFunction.getCode() + " - " + posFunction.toString())); + System.out.println(); + } + public static void printTables(final List
tables) { System.out.println("## 테이블 목록"); final int size = tables.size(); From e8152036b49bd8bc988e21dd1802cf0c50569050 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 14:00:52 +0900 Subject: [PATCH 03/16] =?UTF-8?q?feat:=20=EC=A3=BC=EB=AC=B8=EC=8B=9C=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=20=EB=B0=8F=20=EC=88=98=EB=9F=89=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=EB=B0=9B=EA=B8=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 5 +++++ src/main/java/view/InputView.java | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/Application.java b/src/main/java/Application.java index 81a6d3a1..b8a5703e 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -34,6 +34,11 @@ private static void register_order() { final List menus = MenuRepository.menus(); OutputView.printMenus(menus); + + final int menuNumber = InputView.inputMenuNumber(); + final int menuCount = InputView.inputMenuCount(); + + } private static void pay() { diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index e8d07609..ba125aa7 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -16,6 +16,16 @@ public static int inputTableNumber() { return readIntegerByOneLine(); } + public static int inputMenuNumber() { + System.out.println("## 등록할 메뉴를 선택하세요."); + return readIntegerByOneLine(); + } + + public static int inputMenuCount() { + System.out.println("## 메뉴의 수량을 선택하세요."); + return readIntegerByOneLine(); + } + private static int readIntegerByOneLine() { try { return Integer.parseInt(scanner.nextLine()); From e367f03ad32081fc855b471f5b3d4c107bc44644 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 14:39:52 +0900 Subject: [PATCH 04/16] =?UTF-8?q?feat:=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=97=90=20=EB=A9=94=EB=89=B4=20=EB=93=B1=EB=A1=9D=ED=95=98?= =?UTF-8?q?=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 25 ++++++++++++++++++++----- src/main/java/domain/Menu.java | 4 ++++ src/main/java/domain/Table.java | 21 +++++++++++++++++++++ src/test/java/domain/TableTest.java | 28 ++++++++++++++++++++++++++++ src/test/java/empty.txt | 0 5 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/test/java/domain/TableTest.java delete mode 100644 src/test/java/empty.txt diff --git a/src/main/java/Application.java b/src/main/java/Application.java index b8a5703e..1e9f1c58 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -5,11 +5,15 @@ import domain.TableRepository; import java.util.Arrays; import java.util.List; +import view.IllegalUserInputException; import view.InputView; import view.OutputView; public class Application { + private static final List
tables = TableRepository.tables(); + private static final List menus = MenuRepository.menus(); + public static void main(String[] args) { PosFunction posFunction; @@ -27,18 +31,29 @@ public static void main(String[] args) { } private static void register_order() { - final List
tables = TableRepository.tables(); OutputView.printTables(tables); + final Table table = readTable(); - final int tableNumber = InputView.inputTableNumber(); - - final List menus = MenuRepository.menus(); OutputView.printMenus(menus); + final Menu menuToRegister = readMenu(); - final int menuNumber = InputView.inputMenuNumber(); final int menuCount = InputView.inputMenuCount(); + table.registerMenu(menuToRegister, menuCount); + } + + private static Table readTable() { + return tables.stream() + .filter(table -> table.isNumber(InputView.inputTableNumber())) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); + } + private static Menu readMenu() { + return menus.stream() + .filter(targetMenu -> targetMenu.isNumber(InputView.inputMenuNumber())) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); } private static void pay() { diff --git a/src/main/java/domain/Menu.java b/src/main/java/domain/Menu.java index 9f5a078e..034a276a 100644 --- a/src/main/java/domain/Menu.java +++ b/src/main/java/domain/Menu.java @@ -13,6 +13,10 @@ public Menu(final int number, final String name, final Category category, final this.price = price; } + public boolean isNumber(final int number) { + return this.number == number; + } + @Override public String toString() { return category + " " + number + " - " + name + " : " + price + "원"; diff --git a/src/main/java/domain/Table.java b/src/main/java/domain/Table.java index 500c517e..4d73424e 100644 --- a/src/main/java/domain/Table.java +++ b/src/main/java/domain/Table.java @@ -1,14 +1,35 @@ package domain; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + public class Table { + private final int number; + private final Map orderHistory = new HashMap<>(); public Table(final int number) { this.number = number; } + public void registerMenu(Menu menu, int menuCount) { + if (!orderHistory.containsKey(menu)) { + orderHistory.put(menu, 0); + } + orderHistory.put(menu, orderHistory.get(menu) + menuCount); + } + + public Map getOrderHistory() { + return Collections.unmodifiableMap(orderHistory); + } + @Override public String toString() { return Integer.toString(number); } + + public boolean isNumber(int number) { + return this.number == number; + } } diff --git a/src/test/java/domain/TableTest.java b/src/test/java/domain/TableTest.java new file mode 100644 index 00000000..d3afb135 --- /dev/null +++ b/src/test/java/domain/TableTest.java @@ -0,0 +1,28 @@ +package domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; + +class TableTest { + + @Test + void registerMenu() { + Table table = new Table(1); + + Menu testMenu1 = new Menu(1, "가짜메뉴1", Category.CHICKEN, 1_000); + Menu testMenu2 = new Menu(2, "가짜메뉴2", Category.CHICKEN, 1_3990); + + table.registerMenu(testMenu1, 1); + table.registerMenu(testMenu1, 1); + table.registerMenu(testMenu2, 3); + + Map expected = new HashMap<>(); + expected.put(testMenu1, 2); + expected.put(testMenu2, 3); + + assertThat(table.getOrderHistory()).isEqualTo(expected); + } +} \ No newline at end of file diff --git a/src/test/java/empty.txt b/src/test/java/empty.txt deleted file mode 100644 index e69de29b..00000000 From 2e693e62c3b5326530beba2d7b0cd3cc743f93c5 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 14:43:57 +0900 Subject: [PATCH 05/16] =?UTF-8?q?test:=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EA=B0=9D=EC=B2=B4=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=93=A4?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/domain/TableTest.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/test/java/domain/TableTest.java b/src/test/java/domain/TableTest.java index d3afb135..2b5c1950 100644 --- a/src/test/java/domain/TableTest.java +++ b/src/test/java/domain/TableTest.java @@ -8,10 +8,10 @@ class TableTest { + private Table table = new Table(1); + @Test void registerMenu() { - Table table = new Table(1); - Menu testMenu1 = new Menu(1, "가짜메뉴1", Category.CHICKEN, 1_000); Menu testMenu2 = new Menu(2, "가짜메뉴2", Category.CHICKEN, 1_3990); @@ -25,4 +25,15 @@ void registerMenu() { assertThat(table.getOrderHistory()).isEqualTo(expected); } + + @Test + void isNumber() { + assertThat(table.isNumber(1)).isTrue(); + assertThat(table.isNumber(5)).isFalse(); + } + + @Test + void testToString() { + assertThat(table.toString()).isEqualTo(1 + ""); + } } \ No newline at end of file From 129b95a7d3d0ed8a22a1b736728049e63fedc1f7 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 14:50:26 +0900 Subject: [PATCH 06/16] =?UTF-8?q?feat:=20=EC=A3=BC=EB=AC=B8=EB=82=B4?= =?UTF-8?q?=EC=97=AD=EC=9D=B4=20=EC=9E=88=EB=8A=94=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=EC=9D=B8=EC=A7=80=20=ED=99=95=EC=9D=B8=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 4 +--- src/main/java/domain/Table.java | 4 ++++ src/test/java/domain/TableTest.java | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/Application.java b/src/main/java/Application.java index 1e9f1c58..30319e13 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -37,9 +37,7 @@ private static void register_order() { OutputView.printMenus(menus); final Menu menuToRegister = readMenu(); - final int menuCount = InputView.inputMenuCount(); - - table.registerMenu(menuToRegister, menuCount); + table.registerMenu(menuToRegister, InputView.inputMenuCount()); } private static Table readTable() { diff --git a/src/main/java/domain/Table.java b/src/main/java/domain/Table.java index 4d73424e..1940e5d2 100644 --- a/src/main/java/domain/Table.java +++ b/src/main/java/domain/Table.java @@ -20,6 +20,10 @@ public void registerMenu(Menu menu, int menuCount) { orderHistory.put(menu, orderHistory.get(menu) + menuCount); } + public boolean hasOrdered() { + return !orderHistory.isEmpty(); + } + public Map getOrderHistory() { return Collections.unmodifiableMap(orderHistory); } diff --git a/src/test/java/domain/TableTest.java b/src/test/java/domain/TableTest.java index 2b5c1950..115de505 100644 --- a/src/test/java/domain/TableTest.java +++ b/src/test/java/domain/TableTest.java @@ -4,11 +4,17 @@ import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class TableTest { - private Table table = new Table(1); + private Table table; + + @BeforeEach + void setUp() { + table = new Table(1); + } @Test void registerMenu() { @@ -36,4 +42,13 @@ void isNumber() { void testToString() { assertThat(table.toString()).isEqualTo(1 + ""); } + + @Test + void hasOrdered() { + assertThat(table.hasOrdered()).isFalse(); + + Menu testMenu = new Menu(1, "가짜메뉴", Category.CHICKEN, 1_3990); + table.registerMenu(testMenu, 1); + assertThat(table.hasOrdered()).isTrue(); + } } \ No newline at end of file From 32eab3e79d403fe6a2b3b73417e6ebbbb5cfb2e7 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 15:32:56 +0900 Subject: [PATCH 07/16] =?UTF-8?q?feat:=20=EC=A3=BC=EB=AC=B8=EB=82=B4?= =?UTF-8?q?=EC=97=AD=EC=9D=B4=20=EC=9E=88=EB=8A=94=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=20=EC=B6=9C=EB=A0=A5=EC=8B=9C=20$=20=ED=91=9C?= =?UTF-8?q?=EC=8B=9C=EA=B0=80=20=EC=B6=9C=EB=A0=A5=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 21 +++++++-- src/main/java/domain/PosFunction.java | 13 ++++++ src/main/java/domain/Table.java | 4 ++ src/main/java/view/OutputView.java | 56 +++++++++++++++-------- src/test/java/domain/PosFunctionTest.java | 42 +++++++++++++++++ 5 files changed, 113 insertions(+), 23 deletions(-) create mode 100644 src/test/java/domain/PosFunctionTest.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java index 30319e13..b3530a5a 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -3,8 +3,8 @@ import domain.PosFunction; import domain.Table; import domain.TableRepository; -import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import view.IllegalUserInputException; import view.InputView; import view.OutputView; @@ -18,7 +18,7 @@ public static void main(String[] args) { PosFunction posFunction; do { - OutputView.printPosFunctions(Arrays.asList(PosFunction.values())); + OutputView.printPosFunctions(PosFunction.getPosFunctionsByCodeKoreanMap()); posFunction = PosFunction.of(InputView.inputPosFunction()); if (posFunction == PosFunction.ORDER_REGISTRATION) { @@ -31,7 +31,7 @@ public static void main(String[] args) { } private static void register_order() { - OutputView.printTables(tables); + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); final Table table = readTable(); OutputView.printMenus(menus); @@ -40,6 +40,21 @@ private static void register_order() { table.registerMenu(menuToRegister, InputView.inputMenuCount()); } + private static List getTableNumbers() { + return tables.stream() + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + + private static List getOrderedTableNumbers() { + return tables.stream() + .filter(Table::hasOrdered) + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + private static Table readTable() { return tables.stream() .filter(table -> table.isNumber(InputView.inputTableNumber())) diff --git a/src/main/java/domain/PosFunction.java b/src/main/java/domain/PosFunction.java index 809914df..f21f13ee 100644 --- a/src/main/java/domain/PosFunction.java +++ b/src/main/java/domain/PosFunction.java @@ -1,6 +1,9 @@ package domain; import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; public enum PosFunction { ORDER_REGISTRATION(1, "주문등록"), @@ -26,6 +29,16 @@ public int getCode() { return this.code; } + public static Map getPosFunctionsByCodeKoreanMap() { + Map posFunctions = new HashMap<>(); + + Arrays.stream(PosFunction.values()) + .forEach(posFunction -> + posFunctions.put(posFunction.code, posFunction.korean)); + + return Collections.unmodifiableMap(posFunctions); + } + @Override public String toString() { return this.korean; diff --git a/src/main/java/domain/Table.java b/src/main/java/domain/Table.java index 1940e5d2..60404b76 100644 --- a/src/main/java/domain/Table.java +++ b/src/main/java/domain/Table.java @@ -36,4 +36,8 @@ public String toString() { public boolean isNumber(int number) { return this.number == number; } + + public int getNumber() { + return this.number; + } } diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index ebc3aed0..e09522de 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -1,49 +1,65 @@ package view; import domain.Menu; -import domain.PosFunction; -import domain.Table; import java.util.List; +import java.util.Map; public class OutputView { private static final String TOP_LINE = "┌ ─ ┐"; private static final String TABLE_FORMAT = "| %s |"; - private static final String BOTTOM_LINE = "└ ─ ┘"; + private static final String BOTTOM_LINE_WHEN_NOT_ORDERED = "└ ─ ┘"; + private static final String BOTTOM_LINE_WHEN_ORDERED = "└ $ ┘"; - public static void printPosFunctions(final List posFunctions) { + public static void printPosFunctions(final Map posFunctions) { System.out.println("## 메인 화면"); posFunctions.forEach( - posFunction -> System.out.println( - posFunction.getCode() + " - " + posFunction.toString())); + (key, value) -> System.out.println(key + " - " + value)); System.out.println(); } - public static void printTables(final List
tables) { + public static void printTables(final List tableNumbers, + final List orderedTableNumbers) { + System.out.println("## 테이블 목록"); - final int size = tables.size(); - printLine(TOP_LINE, size); - printTableNumbers(tables); - printLine(BOTTOM_LINE, size); + final int size = tableNumbers.size(); + printTopLine(size); + printTableNumbers(tableNumbers); + printBottomLine(size, orderedTableNumbers); } - public static void printMenus(final List menus) { - for (final Menu menu : menus) { - System.out.println(menu); + private static void printTopLine(final int count) { + for (int index = 0; index < count; index++) { + System.out.print(TOP_LINE); } + System.out.println(); } - private static void printLine(final String line, final int count) { - for (int index = 0; index < count; index++) { - System.out.print(line); + private static void printTableNumbers(List tableNumbers) { + for (final int tableNumber : tableNumbers) { + System.out.printf(TABLE_FORMAT, tableNumber + ""); } System.out.println(); } - private static void printTableNumbers(final List
tables) { - for (final Table table : tables) { - System.out.printf(TABLE_FORMAT, table); + private static void printBottomLine(int count, List orderedTableNumbers) { + for (int tableNumber = 1; tableNumber <= count; tableNumber++) { + printOneTableBottomLine(orderedTableNumbers.contains(tableNumber)); } System.out.println(); } + + private static void printOneTableBottomLine(boolean isOrderedTable) { + if (isOrderedTable) { + System.out.print(BOTTOM_LINE_WHEN_ORDERED); + return; + } + System.out.print(BOTTOM_LINE_WHEN_NOT_ORDERED); + } + + public static void printMenus(final List menus) { + for (final Menu menu : menus) { + System.out.println(menu); + } + } } diff --git a/src/test/java/domain/PosFunctionTest.java b/src/test/java/domain/PosFunctionTest.java new file mode 100644 index 00000000..1d3765a5 --- /dev/null +++ b/src/test/java/domain/PosFunctionTest.java @@ -0,0 +1,42 @@ +package domain; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Test; + +class PosFunctionTest { + + @Test + void of() { + assertThat(PosFunction.of(1)).isEqualTo(PosFunction.ORDER_REGISTRATION); + assertThat(PosFunction.of(2)).isEqualTo(PosFunction.PAYMENT); + assertThat(PosFunction.of(3)).isEqualTo(PosFunction.EXIT); + } + + @Test + void getCode() { + assertThat(PosFunction.ORDER_REGISTRATION.getCode()).isEqualTo(1); + assertThat(PosFunction.PAYMENT.getCode()).isEqualTo(2); + assertThat(PosFunction.EXIT.getCode()).isEqualTo(3); + } + + @Test + void getPosFunctionsByCodeKoreanMap() { + Map expected = new HashMap<>(); + expected.put(1, "주문등록"); + expected.put(2, "결제하기"); + expected.put(3, "프로그램 종료"); + + assertThat(PosFunction.getPosFunctionsByCodeKoreanMap()) + .isEqualTo(expected); + } + + @Test + void testToString() { + assertThat(PosFunction.ORDER_REGISTRATION.toString()).isEqualTo("주문등록"); + assertThat(PosFunction.PAYMENT.toString()).isEqualTo("결제하기"); + assertThat(PosFunction.EXIT.toString()).isEqualTo("프로그램 종료"); + } +} \ No newline at end of file From 8cfb40e743433e5366e0006e32480070c22358e7 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 15:50:59 +0900 Subject: [PATCH 08/16] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EC=8B=9C=20?= =?UTF-8?q?=EA=B2=B0=EC=A0=9C=ED=95=A0=20=ED=85=8C=EC=9D=B4=EB=B8=94?= =?UTF-8?q?=EC=9D=98=20=EC=A3=BC=EB=AC=B8=EB=82=B4=EC=97=AD=EC=9D=84=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8F=84=EB=A1=9D=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 11 +++++++++-- src/main/java/domain/Menu.java | 8 ++++++++ src/main/java/view/InputView.java | 2 +- src/main/java/view/OutputView.java | 7 +++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/Application.java b/src/main/java/Application.java index b3530a5a..c5fd8a16 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -56,20 +56,27 @@ private static List getOrderedTableNumbers() { } private static Table readTable() { + int tableNumber = InputView.inputTableNumber(); + return tables.stream() - .filter(table -> table.isNumber(InputView.inputTableNumber())) + .filter(table -> table.isNumber(tableNumber)) .findFirst() .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); } private static Menu readMenu() { + int menuNumber = InputView.inputMenuNumber(); + return menus.stream() - .filter(targetMenu -> targetMenu.isNumber(InputView.inputMenuNumber())) + .filter(targetMenu -> targetMenu.isNumber(menuNumber)) .findFirst() .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); } private static void pay() { + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); + final Table table = readTable(); + OutputView.printOrderHistory(table.getOrderHistory()); } } diff --git a/src/main/java/domain/Menu.java b/src/main/java/domain/Menu.java index 034a276a..9dac9b91 100644 --- a/src/main/java/domain/Menu.java +++ b/src/main/java/domain/Menu.java @@ -17,6 +17,14 @@ public boolean isNumber(final int number) { return this.number == number; } + public String getName() { + return this.name; + } + + public int getPrice() { + return this.price; + } + @Override public String toString() { return category + " " + number + " - " + name + " : " + price + "원"; diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index ba125aa7..b81bad82 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -12,7 +12,7 @@ public static int inputPosFunction() { } public static int inputTableNumber() { - System.out.println("## 주문할 테이블을 선택하세요."); + System.out.println("## 테이블을 선택하세요."); return readIntegerByOneLine(); } diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index e09522de..b699daf3 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -62,4 +62,11 @@ public static void printMenus(final List menus) { System.out.println(menu); } } + + public static void printOrderHistory(final Map orderHistory) { + System.out.println("메뉴\t수량\t금액"); + orderHistory.forEach((menu, count) -> + System.out.println(menu.getName() + "\t" + count + "\t" + menu.getPrice()) + ); + } } From 1f1ca3ef27f65293badba539d6482970c7663846 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 15:53:14 +0900 Subject: [PATCH 09/16] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EB=B0=A9?= =?UTF-8?q?=EB=B2=95=20enum=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 2 ++ src/main/java/domain/PaymentMethod.java | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/java/domain/PaymentMethod.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java index c5fd8a16..a8194c62 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -78,5 +78,7 @@ private static void pay() { final Table table = readTable(); OutputView.printOrderHistory(table.getOrderHistory()); + + } } diff --git a/src/main/java/domain/PaymentMethod.java b/src/main/java/domain/PaymentMethod.java new file mode 100644 index 00000000..da5889c1 --- /dev/null +++ b/src/main/java/domain/PaymentMethod.java @@ -0,0 +1,23 @@ +package domain; + +import java.util.Arrays; +import view.IllegalUserInputException; + +public enum PaymentMethod { + CREDIT_CARD(1), + CASH(2); + + private int code; + + PaymentMethod(int code) { + this.code = code; + } + + public PaymentMethod of(int code) { + return Arrays.stream(values()) + .filter(paymentMethod -> paymentMethod.code == code) + .findFirst() + .orElseThrow(() -> + new IllegalUserInputException("존재하지 않는 결제방식 번호입니다.")); + } +} From 5dc3b16911acffa0cbfc2d8ec6c83e3983be393c Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 16:15:19 +0900 Subject: [PATCH 10/16] =?UTF-8?q?feat:=20=EA=B2=B0=EC=A0=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 9 +++++++++ src/main/java/domain/PaymentMethod.java | 5 ++--- src/main/java/domain/Table.java | 16 +++++++++++++--- src/main/java/view/InputView.java | 5 +++++ src/main/java/view/OutputView.java | 17 ++++++++++++++--- src/test/java/domain/PaymentMethodTest.java | 18 ++++++++++++++++++ 6 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 src/test/java/domain/PaymentMethodTest.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java index a8194c62..3aac2cb7 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -1,5 +1,6 @@ import domain.Menu; import domain.MenuRepository; +import domain.PaymentMethod; import domain.PosFunction; import domain.Table; import domain.TableRepository; @@ -79,6 +80,14 @@ private static void pay() { OutputView.printOrderHistory(table.getOrderHistory()); + final PaymentMethod paymentMethod = readPaymentMethodOf(table); + OutputView.printFinalPaymentAmount(table.getPaymentAmount()); + table.pay(paymentMethod); + } + + private static PaymentMethod readPaymentMethodOf(Table table) { + OutputView.printMakingPaymentMessage(table.getNumber()); + return PaymentMethod.of(InputView.inputPaymentMethod()); } } diff --git a/src/main/java/domain/PaymentMethod.java b/src/main/java/domain/PaymentMethod.java index da5889c1..18d696ca 100644 --- a/src/main/java/domain/PaymentMethod.java +++ b/src/main/java/domain/PaymentMethod.java @@ -1,7 +1,6 @@ package domain; import java.util.Arrays; -import view.IllegalUserInputException; public enum PaymentMethod { CREDIT_CARD(1), @@ -13,11 +12,11 @@ public enum PaymentMethod { this.code = code; } - public PaymentMethod of(int code) { + public static PaymentMethod of(int code) { return Arrays.stream(values()) .filter(paymentMethod -> paymentMethod.code == code) .findFirst() .orElseThrow(() -> - new IllegalUserInputException("존재하지 않는 결제방식 번호입니다.")); + new IllegalArgumentException("존재하지 않는 결제방식 번호입니다.")); } } diff --git a/src/main/java/domain/Table.java b/src/main/java/domain/Table.java index 60404b76..4c8187ec 100644 --- a/src/main/java/domain/Table.java +++ b/src/main/java/domain/Table.java @@ -28,9 +28,14 @@ public Map getOrderHistory() { return Collections.unmodifiableMap(orderHistory); } - @Override - public String toString() { - return Integer.toString(number); + public int getPaymentAmount() { + return orderHistory.keySet().stream() + .mapToInt(Menu::getPrice) + .sum(); + } + + public void pay(PaymentMethod paymentMethod) { + this.orderHistory.clear(); } public boolean isNumber(int number) { @@ -40,4 +45,9 @@ public boolean isNumber(int number) { public int getNumber() { return this.number; } + + @Override + public String toString() { + return Integer.toString(number); + } } diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index b81bad82..a2684f0c 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -26,6 +26,11 @@ public static int inputMenuCount() { return readIntegerByOneLine(); } + public static int inputPaymentMethod() { + System.out.println("## 신용카드는 1번, 현금은 2번"); + return readIntegerByOneLine(); + } + private static int readIntegerByOneLine() { try { return Integer.parseInt(scanner.nextLine()); diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index b699daf3..4cc0c38c 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -25,7 +25,7 @@ public static void printTables(final List tableNumbers, final int size = tableNumbers.size(); printTopLine(size); printTableNumbers(tableNumbers); - printBottomLine(size, orderedTableNumbers); + printBottomLine(tableNumbers, orderedTableNumbers); } private static void printTopLine(final int count) { @@ -42,8 +42,10 @@ private static void printTableNumbers(List tableNumbers) { System.out.println(); } - private static void printBottomLine(int count, List orderedTableNumbers) { - for (int tableNumber = 1; tableNumber <= count; tableNumber++) { + private static void printBottomLine(List tableNumbers, + List orderedTableNumbers) { + + for (Integer tableNumber : tableNumbers) { printOneTableBottomLine(orderedTableNumbers.contains(tableNumber)); } System.out.println(); @@ -69,4 +71,13 @@ public static void printOrderHistory(final Map orderHistory) { System.out.println(menu.getName() + "\t" + count + "\t" + menu.getPrice()) ); } + + public static void printMakingPaymentMessage(int tableNumber) { + System.out.println(tableNumber + "번 테이블의 결제를 진행합니다."); + } + + public static void printFinalPaymentAmount(int paymentAmount) { + System.out.println("## 최종 결제할 금액"); + System.out.println(paymentAmount + "원"); + } } diff --git a/src/test/java/domain/PaymentMethodTest.java b/src/test/java/domain/PaymentMethodTest.java new file mode 100644 index 00000000..dcb96e8f --- /dev/null +++ b/src/test/java/domain/PaymentMethodTest.java @@ -0,0 +1,18 @@ +package domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.jupiter.api.Test; + +class PaymentMethodTest { + + @Test + void of() { + assertThat(PaymentMethod.of(1)).isEqualTo(PaymentMethod.CREDIT_CARD); + assertThat(PaymentMethod.of(2)).isEqualTo(PaymentMethod.CASH); + + assertThatThrownBy(() -> PaymentMethod.of(0)) + .isInstanceOf(IllegalArgumentException.class); + } +} \ No newline at end of file From 3cc284c121d77c5c3bafc556336067047c26d56e Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 16:17:51 +0900 Subject: [PATCH 11/16] =?UTF-8?q?refactor:=20OutputView=20=EC=97=90=20?= =?UTF-8?q?=EC=A0=81=EC=A0=88=ED=95=9C=20=EC=A4=84=EB=B0=94=EA=BF=88=20?= =?UTF-8?q?=EC=82=BD=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/OutputView.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index 4cc0c38c..82019fa4 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -15,7 +15,7 @@ public static void printPosFunctions(final Map posFunctions) { System.out.println("## 메인 화면"); posFunctions.forEach( (key, value) -> System.out.println(key + " - " + value)); - System.out.println(); + System.out.println("\n"); } public static void printTables(final List tableNumbers, @@ -26,6 +26,7 @@ public static void printTables(final List tableNumbers, printTopLine(size); printTableNumbers(tableNumbers); printBottomLine(tableNumbers, orderedTableNumbers); + System.out.println(); } private static void printTopLine(final int count) { @@ -63,6 +64,7 @@ public static void printMenus(final List menus) { for (final Menu menu : menus) { System.out.println(menu); } + System.out.println(); } public static void printOrderHistory(final Map orderHistory) { @@ -70,6 +72,7 @@ public static void printOrderHistory(final Map orderHistory) { orderHistory.forEach((menu, count) -> System.out.println(menu.getName() + "\t" + count + "\t" + menu.getPrice()) ); + System.out.println(); } public static void printMakingPaymentMessage(int tableNumber) { @@ -79,5 +82,6 @@ public static void printMakingPaymentMessage(int tableNumber) { public static void printFinalPaymentAmount(int paymentAmount) { System.out.println("## 최종 결제할 금액"); System.out.println(paymentAmount + "원"); + System.out.println(); } } From a38797ea53e5dcdfbcccc960deac20ec8149f295 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 16:21:50 +0900 Subject: [PATCH 12/16] =?UTF-8?q?refactor:=20=EC=97=90=EB=9F=AC=EA=B0=80?= =?UTF-8?q?=20=EB=82=98=EB=8F=84=20=ED=94=84=EB=A1=9C=EA=B7=B8=EB=9E=A8?= =?UTF-8?q?=EC=9D=B4=20=EC=A0=95=EC=83=81=EC=A2=85=EB=A3=8C=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 89 +------------------- src/main/java/controller/Controller.java | 103 +++++++++++++++++++++++ src/main/java/view/OutputView.java | 4 + 3 files changed, 109 insertions(+), 87 deletions(-) create mode 100644 src/main/java/controller/Controller.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java index 3aac2cb7..78c78c4d 100644 --- a/src/main/java/Application.java +++ b/src/main/java/Application.java @@ -1,93 +1,8 @@ -import domain.Menu; -import domain.MenuRepository; -import domain.PaymentMethod; -import domain.PosFunction; -import domain.Table; -import domain.TableRepository; -import java.util.List; -import java.util.stream.Collectors; -import view.IllegalUserInputException; -import view.InputView; -import view.OutputView; +import controller.Controller; public class Application { - private static final List
tables = TableRepository.tables(); - private static final List menus = MenuRepository.menus(); - public static void main(String[] args) { - PosFunction posFunction; - - do { - OutputView.printPosFunctions(PosFunction.getPosFunctionsByCodeKoreanMap()); - posFunction = PosFunction.of(InputView.inputPosFunction()); - - if (posFunction == PosFunction.ORDER_REGISTRATION) { - register_order(); - } - if (posFunction == PosFunction.PAYMENT) { - pay(); - } - } while (posFunction != PosFunction.EXIT); - } - - private static void register_order() { - OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); - final Table table = readTable(); - - OutputView.printMenus(menus); - final Menu menuToRegister = readMenu(); - - table.registerMenu(menuToRegister, InputView.inputMenuCount()); - } - - private static List getTableNumbers() { - return tables.stream() - .mapToInt(Table::getNumber) - .boxed() - .collect(Collectors.toList()); - } - - private static List getOrderedTableNumbers() { - return tables.stream() - .filter(Table::hasOrdered) - .mapToInt(Table::getNumber) - .boxed() - .collect(Collectors.toList()); - } - - private static Table readTable() { - int tableNumber = InputView.inputTableNumber(); - - return tables.stream() - .filter(table -> table.isNumber(tableNumber)) - .findFirst() - .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); - } - - private static Menu readMenu() { - int menuNumber = InputView.inputMenuNumber(); - - return menus.stream() - .filter(targetMenu -> targetMenu.isNumber(menuNumber)) - .findFirst() - .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); - } - - private static void pay() { - OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); - final Table table = readTable(); - - OutputView.printOrderHistory(table.getOrderHistory()); - - final PaymentMethod paymentMethod = readPaymentMethodOf(table); - - OutputView.printFinalPaymentAmount(table.getPaymentAmount()); - table.pay(paymentMethod); - } - - private static PaymentMethod readPaymentMethodOf(Table table) { - OutputView.printMakingPaymentMessage(table.getNumber()); - return PaymentMethod.of(InputView.inputPaymentMethod()); + Controller.run(); } } diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java new file mode 100644 index 00000000..a8cf179e --- /dev/null +++ b/src/main/java/controller/Controller.java @@ -0,0 +1,103 @@ +package controller; + +import domain.Menu; +import domain.MenuRepository; +import domain.PaymentMethod; +import domain.PosFunction; +import domain.Table; +import domain.TableRepository; +import java.util.List; +import java.util.stream.Collectors; +import view.IllegalUserInputException; +import view.InputView; +import view.OutputView; + +public class Controller { + + private static final List
tables = TableRepository.tables(); + private static final List menus = MenuRepository.menus(); + + public static void run() { + try { + runWithoutExceptionCatch(); + } catch (Exception e) { + OutputView.printExceptionMessage(e.getMessage()); + } + } + + private static void runWithoutExceptionCatch() { + PosFunction posFunction; + + do { + OutputView.printPosFunctions(PosFunction.getPosFunctionsByCodeKoreanMap()); + posFunction = PosFunction.of(InputView.inputPosFunction()); + + if (posFunction == PosFunction.ORDER_REGISTRATION) { + register_order(); + } + if (posFunction == PosFunction.PAYMENT) { + pay(); + } + } while (posFunction != PosFunction.EXIT); + } + + private static void register_order() { + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); + final Table table = readTable(); + + OutputView.printMenus(menus); + final Menu menuToRegister = readMenu(); + + table.registerMenu(menuToRegister, InputView.inputMenuCount()); + } + + private static List getTableNumbers() { + return tables.stream() + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + + private static List getOrderedTableNumbers() { + return tables.stream() + .filter(Table::hasOrdered) + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + + private static Table readTable() { + int tableNumber = InputView.inputTableNumber(); + + return tables.stream() + .filter(table -> table.isNumber(tableNumber)) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); + } + + private static Menu readMenu() { + int menuNumber = InputView.inputMenuNumber(); + + return menus.stream() + .filter(targetMenu -> targetMenu.isNumber(menuNumber)) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); + } + + private static void pay() { + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); + final Table table = readTable(); + + OutputView.printOrderHistory(table.getOrderHistory()); + + final PaymentMethod paymentMethod = readPaymentMethodOf(table); + + OutputView.printFinalPaymentAmount(table.getPaymentAmount()); + table.pay(paymentMethod); + } + + private static PaymentMethod readPaymentMethodOf(Table table) { + OutputView.printMakingPaymentMessage(table.getNumber()); + return PaymentMethod.of(InputView.inputPaymentMethod()); + } +} diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index 82019fa4..59fa9f3b 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -84,4 +84,8 @@ public static void printFinalPaymentAmount(int paymentAmount) { System.out.println(paymentAmount + "원"); System.out.println(); } + + public static void printExceptionMessage(String exceptionMessage) { + System.out.println(exceptionMessage); + } } From 7c29ee7a3c1df1953555f206056365bb130adc2a Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 16:27:55 +0900 Subject: [PATCH 13/16] =?UTF-8?q?refactor:=20=EB=84=88=EB=AC=B4=20?= =?UTF-8?q?=EA=B8=B4=20=EC=BB=A8=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=EB=A5=BC=20=EC=AA=BC=EA=B0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/controller/Controller.java | 84 +++--------------------- src/main/java/domain/Table.java | 8 +++ src/main/java/service/PosService.java | 78 ++++++++++++++++++++++ 3 files changed, 95 insertions(+), 75 deletions(-) create mode 100644 src/main/java/service/PosService.java diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index a8cf179e..ff98c1e7 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -1,22 +1,12 @@ package controller; -import domain.Menu; -import domain.MenuRepository; -import domain.PaymentMethod; import domain.PosFunction; -import domain.Table; -import domain.TableRepository; -import java.util.List; -import java.util.stream.Collectors; -import view.IllegalUserInputException; +import service.PosService; import view.InputView; import view.OutputView; public class Controller { - private static final List
tables = TableRepository.tables(); - private static final List menus = MenuRepository.menus(); - public static void run() { try { runWithoutExceptionCatch(); @@ -32,72 +22,16 @@ private static void runWithoutExceptionCatch() { OutputView.printPosFunctions(PosFunction.getPosFunctionsByCodeKoreanMap()); posFunction = PosFunction.of(InputView.inputPosFunction()); - if (posFunction == PosFunction.ORDER_REGISTRATION) { - register_order(); - } - if (posFunction == PosFunction.PAYMENT) { - pay(); - } + runOnce(posFunction); } while (posFunction != PosFunction.EXIT); } - private static void register_order() { - OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); - final Table table = readTable(); - - OutputView.printMenus(menus); - final Menu menuToRegister = readMenu(); - - table.registerMenu(menuToRegister, InputView.inputMenuCount()); - } - - private static List getTableNumbers() { - return tables.stream() - .mapToInt(Table::getNumber) - .boxed() - .collect(Collectors.toList()); - } - - private static List getOrderedTableNumbers() { - return tables.stream() - .filter(Table::hasOrdered) - .mapToInt(Table::getNumber) - .boxed() - .collect(Collectors.toList()); - } - - private static Table readTable() { - int tableNumber = InputView.inputTableNumber(); - - return tables.stream() - .filter(table -> table.isNumber(tableNumber)) - .findFirst() - .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); - } - - private static Menu readMenu() { - int menuNumber = InputView.inputMenuNumber(); - - return menus.stream() - .filter(targetMenu -> targetMenu.isNumber(menuNumber)) - .findFirst() - .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); - } - - private static void pay() { - OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); - final Table table = readTable(); - - OutputView.printOrderHistory(table.getOrderHistory()); - - final PaymentMethod paymentMethod = readPaymentMethodOf(table); - - OutputView.printFinalPaymentAmount(table.getPaymentAmount()); - table.pay(paymentMethod); - } - - private static PaymentMethod readPaymentMethodOf(Table table) { - OutputView.printMakingPaymentMessage(table.getNumber()); - return PaymentMethod.of(InputView.inputPaymentMethod()); + private static void runOnce(PosFunction posFunction) { + if (posFunction == PosFunction.ORDER_REGISTRATION) { + PosService.registerOrder(); + } + if (posFunction == PosFunction.PAYMENT) { + PosService.pay(); + } } } diff --git a/src/main/java/domain/Table.java b/src/main/java/domain/Table.java index 4c8187ec..b432dc1d 100644 --- a/src/main/java/domain/Table.java +++ b/src/main/java/domain/Table.java @@ -29,15 +29,23 @@ public Map getOrderHistory() { } public int getPaymentAmount() { + validatePayable(); return orderHistory.keySet().stream() .mapToInt(Menu::getPrice) .sum(); } public void pay(PaymentMethod paymentMethod) { + validatePayable(); this.orderHistory.clear(); } + public void validatePayable() { + if (!hasOrdered()) { + throw new IllegalStateException("결제할 주문내역이 없습니다."); + } + } + public boolean isNumber(int number) { return this.number == number; } diff --git a/src/main/java/service/PosService.java b/src/main/java/service/PosService.java new file mode 100644 index 00000000..26236f9e --- /dev/null +++ b/src/main/java/service/PosService.java @@ -0,0 +1,78 @@ +package service; + +import domain.Menu; +import domain.MenuRepository; +import domain.PaymentMethod; +import domain.Table; +import domain.TableRepository; +import java.util.List; +import java.util.stream.Collectors; +import view.IllegalUserInputException; +import view.InputView; +import view.OutputView; + +public class PosService { + + private static final List
tables = TableRepository.tables(); + private static final List menus = MenuRepository.menus(); + + public static void registerOrder() { + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); + final Table table = readTable(); + + OutputView.printMenus(menus); + final Menu menuToRegister = readMenu(); + + table.registerMenu(menuToRegister, InputView.inputMenuCount()); + } + + private static List getTableNumbers() { + return tables.stream() + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + + private static List getOrderedTableNumbers() { + return tables.stream() + .filter(Table::hasOrdered) + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + + private static Table readTable() { + int tableNumber = InputView.inputTableNumber(); + + return tables.stream() + .filter(table -> table.isNumber(tableNumber)) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); + } + + private static Menu readMenu() { + int menuNumber = InputView.inputMenuNumber(); + + return menus.stream() + .filter(targetMenu -> targetMenu.isNumber(menuNumber)) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); + } + + public static void pay() { + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); + final Table table = readTable(); + + OutputView.printOrderHistory(table.getOrderHistory()); + + final PaymentMethod paymentMethod = readPaymentMethodOf(table); + + OutputView.printFinalPaymentAmount(table.getPaymentAmount()); + table.pay(paymentMethod); + } + + private static PaymentMethod readPaymentMethodOf(Table table) { + OutputView.printMakingPaymentMessage(table.getNumber()); + return PaymentMethod.of(InputView.inputPaymentMethod()); + } +} From 3037c72b14b2d89030277374c84a7aec1fcd7631 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 16:33:51 +0900 Subject: [PATCH 14/16] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=97=85=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 +++++++++++++++++++- src/main/java/service/PosService.java | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c31ca54c..51d114a9 100644 --- a/README.md +++ b/README.md @@ -1 +1,19 @@ -# java-chicken-2019 \ No newline at end of file +# java-chicken-2019 + +## 기능목록 +기능 출력하기 +원하는 기능 선택하기 +테이블 목록 출력하기 (주어짐) +테이블 선택하기 (주어짐) +메뉴 출력하기 (주어짐) +등록할 메뉴 선택하기 +메뉴의 수량 입력하기 +주문내역 출력하기 +카드결제 할지 현금결제 할지 선택하기 +최종 결제할 금액 출력하기 +주문 정보 등록하기 +결제 금액 계산하기 +할인율 계산하기 +테이블 별로 주문 내역 관리하기 +테이블 당 주문 내역 관리하기 +결제 완료된 테이블 결제 완료 처리하기 \ No newline at end of file diff --git a/src/main/java/service/PosService.java b/src/main/java/service/PosService.java index 26236f9e..196b48f2 100644 --- a/src/main/java/service/PosService.java +++ b/src/main/java/service/PosService.java @@ -62,6 +62,7 @@ private static Menu readMenu() { public static void pay() { OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); final Table table = readTable(); + table.validatePayable(); OutputView.printOrderHistory(table.getOrderHistory()); From 4419c026130855e8fece0607d8ebb1691239795d Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 16:46:42 +0900 Subject: [PATCH 15/16] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=96=B8=EC=96=B4=ED=91=9C=ED=98=84=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=EA=B0=9D=EC=B2=B4=EC=84=A4=EA=B3=84=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 51d114a9..22ef51c3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # java-chicken-2019 ## 기능목록 -기능 출력하기 +Pos 기 기능 출력하기 원하는 기능 선택하기 테이블 목록 출력하기 (주어짐) 테이블 선택하기 (주어짐) @@ -16,4 +16,15 @@ 할인율 계산하기 테이블 별로 주문 내역 관리하기 테이블 당 주문 내역 관리하기 -결제 완료된 테이블 결제 완료 처리하기 \ No newline at end of file +결제 완료된 테이블 결제 완료 처리하기 + +## 객체 설계 +- Menu + - 아는 것 : 메뉴 자신의 번호, 이름, 종류, 가격 +- PaymentMethod + - 아는 것 : 지불 방식 스스로에 대해 대응되는 번호(code) +- PosFunction + - 아는 것 : pos 기계의 기능 스스로에 대해 대응되는 번호(code), 자신의 한국어 이름 +- Table + - 아는 것 : 주문내역, + - 하는 것 : 자신에 대한 주문내역 등록, 결제하기 \ No newline at end of file From e9f99df4e15b6f4fc4bd8023a45432c1868a8111 Mon Sep 17 00:00:00 2001 From: yelimkim98 Date: Fri, 10 Apr 2020 16:55:24 +0900 Subject: [PATCH 16/16] =?UTF-8?q?refactor:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC-=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC=EC=A1=B0?= =?UTF-8?q?=EA=B0=80=20=EC=9E=98=EB=AA=BB=EB=90=9C=EA=B2=83=EA=B0=99?= =?UTF-8?q?=EC=95=84=EC=84=9C=20service=20=EA=B3=84=EC=B8=B5=EC=9D=84=20?= =?UTF-8?q?=EC=A7=80=EC=9B=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/controller/Controller.java | 77 ++++++++++++++++++++++- src/main/java/service/PosService.java | 79 ------------------------ 2 files changed, 74 insertions(+), 82 deletions(-) delete mode 100644 src/main/java/service/PosService.java diff --git a/src/main/java/controller/Controller.java b/src/main/java/controller/Controller.java index ff98c1e7..8f74db78 100644 --- a/src/main/java/controller/Controller.java +++ b/src/main/java/controller/Controller.java @@ -1,12 +1,22 @@ package controller; +import domain.Menu; +import domain.MenuRepository; +import domain.PaymentMethod; import domain.PosFunction; -import service.PosService; +import domain.Table; +import domain.TableRepository; +import java.util.List; +import java.util.stream.Collectors; +import view.IllegalUserInputException; import view.InputView; import view.OutputView; public class Controller { + private static final List
tables = TableRepository.tables(); + private static final List menus = MenuRepository.menus(); + public static void run() { try { runWithoutExceptionCatch(); @@ -28,10 +38,71 @@ private static void runWithoutExceptionCatch() { private static void runOnce(PosFunction posFunction) { if (posFunction == PosFunction.ORDER_REGISTRATION) { - PosService.registerOrder(); + registerOrder(); } if (posFunction == PosFunction.PAYMENT) { - PosService.pay(); + pay(); } } + + private static void registerOrder() { + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); + final Table table = readTable(); + + OutputView.printMenus(menus); + final Menu menuToRegister = readMenu(); + + table.registerMenu(menuToRegister, InputView.inputMenuCount()); + } + + private static List getTableNumbers() { + return tables.stream() + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + + private static List getOrderedTableNumbers() { + return tables.stream() + .filter(Table::hasOrdered) + .mapToInt(Table::getNumber) + .boxed() + .collect(Collectors.toList()); + } + + private static Table readTable() { + int tableNumber = InputView.inputTableNumber(); + + return tables.stream() + .filter(table -> table.isNumber(tableNumber)) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); + } + + private static Menu readMenu() { + int menuNumber = InputView.inputMenuNumber(); + + return menus.stream() + .filter(targetMenu -> targetMenu.isNumber(menuNumber)) + .findFirst() + .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); + } + + private static void pay() { + OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); + final Table table = readTable(); + table.validatePayable(); + + OutputView.printOrderHistory(table.getOrderHistory()); + + final PaymentMethod paymentMethod = readPaymentMethodOf(table); + + OutputView.printFinalPaymentAmount(table.getPaymentAmount()); + table.pay(paymentMethod); + } + + private static PaymentMethod readPaymentMethodOf(Table table) { + OutputView.printMakingPaymentMessage(table.getNumber()); + return PaymentMethod.of(InputView.inputPaymentMethod()); + } } diff --git a/src/main/java/service/PosService.java b/src/main/java/service/PosService.java deleted file mode 100644 index 196b48f2..00000000 --- a/src/main/java/service/PosService.java +++ /dev/null @@ -1,79 +0,0 @@ -package service; - -import domain.Menu; -import domain.MenuRepository; -import domain.PaymentMethod; -import domain.Table; -import domain.TableRepository; -import java.util.List; -import java.util.stream.Collectors; -import view.IllegalUserInputException; -import view.InputView; -import view.OutputView; - -public class PosService { - - private static final List
tables = TableRepository.tables(); - private static final List menus = MenuRepository.menus(); - - public static void registerOrder() { - OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); - final Table table = readTable(); - - OutputView.printMenus(menus); - final Menu menuToRegister = readMenu(); - - table.registerMenu(menuToRegister, InputView.inputMenuCount()); - } - - private static List getTableNumbers() { - return tables.stream() - .mapToInt(Table::getNumber) - .boxed() - .collect(Collectors.toList()); - } - - private static List getOrderedTableNumbers() { - return tables.stream() - .filter(Table::hasOrdered) - .mapToInt(Table::getNumber) - .boxed() - .collect(Collectors.toList()); - } - - private static Table readTable() { - int tableNumber = InputView.inputTableNumber(); - - return tables.stream() - .filter(table -> table.isNumber(tableNumber)) - .findFirst() - .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 테이블입니다.")); - } - - private static Menu readMenu() { - int menuNumber = InputView.inputMenuNumber(); - - return menus.stream() - .filter(targetMenu -> targetMenu.isNumber(menuNumber)) - .findFirst() - .orElseThrow(() -> new IllegalUserInputException("존재하지 않는 메뉴입니다.")); - } - - public static void pay() { - OutputView.printTables(getTableNumbers(), getOrderedTableNumbers()); - final Table table = readTable(); - table.validatePayable(); - - OutputView.printOrderHistory(table.getOrderHistory()); - - final PaymentMethod paymentMethod = readPaymentMethodOf(table); - - OutputView.printFinalPaymentAmount(table.getPaymentAmount()); - table.pay(paymentMethod); - } - - private static PaymentMethod readPaymentMethodOf(Table table) { - OutputView.printMakingPaymentMessage(table.getNumber()); - return PaymentMethod.of(InputView.inputPaymentMethod()); - } -}