From 2d95a43dc09c9d19e7df6bd987a2da70a33b8450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:02:54 +0900 Subject: [PATCH 01/32] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29bb..22674ced0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,22 @@ +## 기능 목록 + +- [ ] 추천 시작 안내 메시지 출력 + +- [ ] 코치의 이름 입력 + - [ ] 각 이름은 2~4글자가 아닐 경우 예외 발생 + - [ ] 코치 수가 2명~5명이 아닐 경우 예외 발생 + +- [ ] 각 코치마다 못 먹는 음식 입력 + - [ ] 0~2개가 아닐 경우 예외 + +- [ ] 카테고리 추천 + - [ ] 월~금까지 먹을 카테고리를 추천한다. + - [ ] 이미 2번 추천된 카테고리일 경우 재추천 + +- [ ] 코치 별 음식 추천 + - [ ] 요일마다 코치가 먹을 음식을 추천한다. + - [ ] 이미 한 번 먹은 음식일 경우 재추천 + - [ ] 코치가 못먹는 음식일 경우 재추천 + +- [ ] 추천 결과 출력 +- [ ] 추천 완료 안내 \ No newline at end of file From 433f4ef0ef9c394a5317af67dfa618837341cec2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:08:41 +0900 Subject: [PATCH 02/32] =?UTF-8?q?feat(OutputView):=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=8B=9C=EC=9E=91=20=EC=95=88=EB=82=B4=20=EB=A9=94=EC=8B=9C?= =?UTF-8?q?=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=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 --- docs/README.md | 2 +- src/main/java/menu/Application.java | 5 ++++- src/main/java/menu/constant/OutputMessage.java | 16 ++++++++++++++++ .../java/menu/controller/MenuController.java | 13 +++++++++++++ src/main/java/menu/view/OutputView.java | 10 ++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 src/main/java/menu/constant/OutputMessage.java create mode 100644 src/main/java/menu/controller/MenuController.java create mode 100644 src/main/java/menu/view/OutputView.java diff --git a/docs/README.md b/docs/README.md index 22674ced0..a01c24d63 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ ## 기능 목록 -- [ ] 추천 시작 안내 메시지 출력 +- [x] 추천 시작 안내 메시지 출력 - [ ] 코치의 이름 입력 - [ ] 각 이름은 2~4글자가 아닐 경우 예외 발생 diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6340b6f33..6b04e2e23 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -1,7 +1,10 @@ package menu; +import menu.controller.MenuController; + public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + MenuController menuController = new MenuController(); + menuController.start(); } } diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java new file mode 100644 index 000000000..7607b31a4 --- /dev/null +++ b/src/main/java/menu/constant/OutputMessage.java @@ -0,0 +1,16 @@ +package menu.constant; + +public enum OutputMessage { + + START_RECOMMEND("점심 메뉴 추천을 시작합니다."); + + private final String message; + + OutputMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java new file mode 100644 index 000000000..11925e294 --- /dev/null +++ b/src/main/java/menu/controller/MenuController.java @@ -0,0 +1,13 @@ +package menu.controller; + +import menu.view.OutputView; + +public class MenuController { + + private final OutputView outputView = new OutputView(); + + public void start() { + outputView.printStart(); + } + +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java new file mode 100644 index 000000000..9f21ff4d0 --- /dev/null +++ b/src/main/java/menu/view/OutputView.java @@ -0,0 +1,10 @@ +package menu.view; + +import menu.constant.OutputMessage; + +public class OutputView { + + public void printStart() { + System.out.println(OutputMessage.START_RECOMMEND.getMessage()); + } +} From 053ca07fa5b5572ab017d3cc0563593e3d1afe55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:16:13 +0900 Subject: [PATCH 03/32] =?UTF-8?q?feat(InputView):=20=EC=BD=94=EC=B9=98?= =?UTF-8?q?=EC=9D=98=20=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=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 --- docs/README.md | 3 ++- src/main/java/menu/constant/OutputMessage.java | 3 ++- .../java/menu/controller/MenuController.java | 9 +++++++++ src/main/java/menu/view/InputView.java | 16 ++++++++++++++++ src/main/java/menu/view/OutputView.java | 9 +++++++++ 5 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/main/java/menu/view/InputView.java diff --git a/docs/README.md b/docs/README.md index a01c24d63..884587c70 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,8 @@ - [x] 추천 시작 안내 메시지 출력 -- [ ] 코치의 이름 입력 +- [x] 코치의 이름 입력 + - [ ] `,`로 나누지 않은 경우 예외 발생 - [ ] 각 이름은 2~4글자가 아닐 경우 예외 발생 - [ ] 코치 수가 2명~5명이 아닐 경우 예외 발생 diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index 7607b31a4..e2c9233a5 100644 --- a/src/main/java/menu/constant/OutputMessage.java +++ b/src/main/java/menu/constant/OutputMessage.java @@ -2,7 +2,8 @@ public enum OutputMessage { - START_RECOMMEND("점심 메뉴 추천을 시작합니다."); + START_RECOMMEND("점심 메뉴 추천을 시작합니다."), + READ_NAMES("코치의 이름을 입력해 주세요. (, 로 구분)"); private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 11925e294..8a988215d 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,13 +1,22 @@ package menu.controller; +import menu.view.InputView; import menu.view.OutputView; +import java.util.List; + public class MenuController { private final OutputView outputView = new OutputView(); + private final InputView inputView = new InputView(); public void start() { outputView.printStart(); + readNames(); } + private void readNames() { + outputView.printCoachNames(); + List names = inputView.readNames(); + } } diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java new file mode 100644 index 000000000..dda57bdc6 --- /dev/null +++ b/src/main/java/menu/view/InputView.java @@ -0,0 +1,16 @@ +package menu.view; + +import camp.nextstep.edu.missionutils.Console; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class InputView { + + public List readNames() { + String names = Console.readLine(); + return Stream.of(names.split(",")) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 9f21ff4d0..54ccf3c51 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -6,5 +6,14 @@ public class OutputView { public void printStart() { System.out.println(OutputMessage.START_RECOMMEND.getMessage()); + printNewLine(); + } + + public void printCoachNames() { + System.out.println(OutputMessage.READ_NAMES.getMessage()); + } + + public void printNewLine() { + System.out.println(); } } From fd1af1b42e6c3a351b25809662f75dd3d2a07675 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:20:05 +0900 Subject: [PATCH 04/32] =?UTF-8?q?feat(InputValidator):=20`,`=EB=A1=9C=20?= =?UTF-8?q?=EB=82=98=EB=88=84=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/menu/constant/ExceptionMessage.java | 18 ++++++++++++++++++ .../java/menu/validator/InputValidator.java | 17 +++++++++++++++++ src/main/java/menu/view/InputView.java | 4 ++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/main/java/menu/constant/ExceptionMessage.java create mode 100644 src/main/java/menu/validator/InputValidator.java diff --git a/docs/README.md b/docs/README.md index 884587c70..58463afba 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,7 +3,7 @@ - [x] 추천 시작 안내 메시지 출력 - [x] 코치의 이름 입력 - - [ ] `,`로 나누지 않은 경우 예외 발생 + - [x] `,`로 나누지 않은 경우 예외 발생 - [ ] 각 이름은 2~4글자가 아닐 경우 예외 발생 - [ ] 코치 수가 2명~5명이 아닐 경우 예외 발생 diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java new file mode 100644 index 000000000..63475e1fa --- /dev/null +++ b/src/main/java/menu/constant/ExceptionMessage.java @@ -0,0 +1,18 @@ +package menu.constant; + +public enum ExceptionMessage { + + INCORRECT_DELIMITER("','로 구분하여 입력해야합니다."); + + private static final String PREFIX = "[ERROR] "; + private final String message; + + ExceptionMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return PREFIX + message; + } +} \ No newline at end of file diff --git a/src/main/java/menu/validator/InputValidator.java b/src/main/java/menu/validator/InputValidator.java new file mode 100644 index 000000000..427d2dfdc --- /dev/null +++ b/src/main/java/menu/validator/InputValidator.java @@ -0,0 +1,17 @@ +package menu.validator; + +import menu.constant.ExceptionMessage; + +import java.util.regex.Pattern; + +public class InputValidator { + + private static final String DELIMITER_REGEXP = "^[a-zA-Zㄱ-힣0-9,]*$"; + + public void validateDelimiter(String input) { + if (!Pattern.matches(DELIMITER_REGEXP, input)) { + ExceptionMessage exceptionMessage = ExceptionMessage.INCORRECT_DELIMITER; + throw new IllegalArgumentException(exceptionMessage.toString()); + } + } +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index dda57bdc6..8b0dfb8c6 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -1,6 +1,7 @@ package menu.view; import camp.nextstep.edu.missionutils.Console; +import menu.validator.InputValidator; import java.util.List; import java.util.stream.Collectors; @@ -8,8 +9,11 @@ public class InputView { + private final InputValidator inputValidator = new InputValidator(); + public List readNames() { String names = Console.readLine(); + inputValidator.validateDelimiter(names); return Stream.of(names.split(",")) .collect(Collectors.toList()); } From 943a93d6c8236fcce68e357e1af25241b756e676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:27:30 +0900 Subject: [PATCH 05/32] =?UTF-8?q?feat(Name):=20=EA=B0=81=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9D=80=202~4=EA=B8=80=EC=9E=90=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/menu/constant/ExceptionMessage.java | 3 ++- src/main/java/menu/domain/Name.java | 26 +++++++++++++++++++ src/main/java/menu/view/InputView.java | 4 ++- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/main/java/menu/domain/Name.java diff --git a/docs/README.md b/docs/README.md index 58463afba..c5887c35b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ - [x] 코치의 이름 입력 - [x] `,`로 나누지 않은 경우 예외 발생 - - [ ] 각 이름은 2~4글자가 아닐 경우 예외 발생 + - [x] 각 이름은 2~4글자가 아닐 경우 예외 발생 - [ ] 코치 수가 2명~5명이 아닐 경우 예외 발생 - [ ] 각 코치마다 못 먹는 음식 입력 diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java index 63475e1fa..c717801cb 100644 --- a/src/main/java/menu/constant/ExceptionMessage.java +++ b/src/main/java/menu/constant/ExceptionMessage.java @@ -2,7 +2,8 @@ public enum ExceptionMessage { - INCORRECT_DELIMITER("','로 구분하여 입력해야합니다."); + INCORRECT_DELIMITER("','로 구분하여 입력해야합니다."), + INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."); private static final String PREFIX = "[ERROR] "; private final String message; diff --git a/src/main/java/menu/domain/Name.java b/src/main/java/menu/domain/Name.java new file mode 100644 index 000000000..1b8a1d254 --- /dev/null +++ b/src/main/java/menu/domain/Name.java @@ -0,0 +1,26 @@ +package menu.domain; + +import menu.constant.ExceptionMessage; + +public class Name { + + private static final int MIN_LENGTH = 2; + private static final int MAX_LENGTH = 4; + + private final String value; + + public Name(String value) { + validateLength(value); + this.value = value; + } + + public void validateLength(String value) { + if (!(MIN_LENGTH <= value.length() && value.length() <= MAX_LENGTH)) { + throw new IllegalArgumentException(ExceptionMessage.INCORRECT_NAME_RANGE.toString()); + } + } + + public String getValue() { + return value; + } +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 8b0dfb8c6..d0a353eb8 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -1,6 +1,7 @@ package menu.view; import camp.nextstep.edu.missionutils.Console; +import menu.domain.Name; import menu.validator.InputValidator; import java.util.List; @@ -11,10 +12,11 @@ public class InputView { private final InputValidator inputValidator = new InputValidator(); - public List readNames() { + public List readNames() { String names = Console.readLine(); inputValidator.validateDelimiter(names); return Stream.of(names.split(",")) + .map(Name::new) .collect(Collectors.toList()); } } From 9de35743c617481c1af0440e210612f0a9ea385e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:37:51 +0900 Subject: [PATCH 06/32] =?UTF-8?q?feat(Names):=20=EC=BD=94=EC=B9=98=20?= =?UTF-8?q?=EC=88=98=EA=B0=80=202=EB=AA=85~5=EB=AA=85=EC=9D=B4=20=EC=95=84?= =?UTF-8?q?=EB=8B=90=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/menu/constant/ExceptionMessage.java | 3 ++- .../java/menu/controller/MenuController.java | 9 +++---- src/main/java/menu/domain/Names.java | 25 +++++++++++++++++++ src/main/java/menu/view/InputView.java | 10 +++++--- 5 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/main/java/menu/domain/Names.java diff --git a/docs/README.md b/docs/README.md index c5887c35b..15221c500 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,7 +5,7 @@ - [x] 코치의 이름 입력 - [x] `,`로 나누지 않은 경우 예외 발생 - [x] 각 이름은 2~4글자가 아닐 경우 예외 발생 - - [ ] 코치 수가 2명~5명이 아닐 경우 예외 발생 + - [x] 코치 수가 2명~5명이 아닐 경우 예외 발생 - [ ] 각 코치마다 못 먹는 음식 입력 - [ ] 0~2개가 아닐 경우 예외 diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java index c717801cb..1e5654c98 100644 --- a/src/main/java/menu/constant/ExceptionMessage.java +++ b/src/main/java/menu/constant/ExceptionMessage.java @@ -3,7 +3,8 @@ public enum ExceptionMessage { INCORRECT_DELIMITER("','로 구분하여 입력해야합니다."), - INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."); + INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."), + INCORRECT_COACH_NUMBER("코치는 2명 이상, 5명 이하만 입력할 수 있습니다."); private static final String PREFIX = "[ERROR] "; private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 8a988215d..f6a8b9ebd 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,10 +1,9 @@ package menu.controller; +import menu.domain.Names; import menu.view.InputView; import menu.view.OutputView; -import java.util.List; - public class MenuController { private final OutputView outputView = new OutputView(); @@ -12,11 +11,11 @@ public class MenuController { public void start() { outputView.printStart(); - readNames(); + Names names = readNames(); } - private void readNames() { + private Names readNames() { outputView.printCoachNames(); - List names = inputView.readNames(); + return inputView.readNames(); } } diff --git a/src/main/java/menu/domain/Names.java b/src/main/java/menu/domain/Names.java new file mode 100644 index 000000000..0cb5691e2 --- /dev/null +++ b/src/main/java/menu/domain/Names.java @@ -0,0 +1,25 @@ +package menu.domain; + +import menu.constant.ExceptionMessage; + +import java.util.ArrayList; +import java.util.List; + +public class Names { + + private static final int MIN_RANGE = 2; + private static final int MAX_RANGE = 5; + + private final List elements; + + public Names(List names) { + validateRange(names); + this.elements = new ArrayList<>(names); + } + + private void validateRange(List names) { + if (!(MIN_RANGE <= names.size() && names.size() <= MAX_RANGE)) { + throw new IllegalArgumentException(ExceptionMessage.INCORRECT_NAME_RANGE.toString()); + } + } +} \ No newline at end of file diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index d0a353eb8..35ed11542 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -2,6 +2,7 @@ import camp.nextstep.edu.missionutils.Console; import menu.domain.Name; +import menu.domain.Names; import menu.validator.InputValidator; import java.util.List; @@ -12,11 +13,12 @@ public class InputView { private final InputValidator inputValidator = new InputValidator(); - public List readNames() { - String names = Console.readLine(); - inputValidator.validateDelimiter(names); - return Stream.of(names.split(",")) + public Names readNames() { + String input = Console.readLine(); + inputValidator.validateDelimiter(input); + List names = Stream.of(input.split(",")) .map(Name::new) .collect(Collectors.toList()); + return new Names(names); } } From 52d611a3fcdf142c5abb147698a97c88d12f23ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:47:47 +0900 Subject: [PATCH 07/32] =?UTF-8?q?feat(Coaches):=20=EC=9E=85=EB=A0=A5?= =?UTF-8?q?=ED=95=9C=20=EC=9D=B4=EB=A6=84=EC=9C=BC=EB=A1=9C=20=EC=BD=94?= =?UTF-8?q?=EC=B9=98=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/menu/controller/MenuController.java | 6 +++--- src/main/java/menu/domain/Coach.java | 10 ++++++++++ src/main/java/menu/domain/Coaches.java | 16 ++++++++++++++++ src/main/java/menu/domain/Names.java | 5 +++++ src/main/java/menu/view/InputView.java | 5 +++-- 5 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 src/main/java/menu/domain/Coach.java create mode 100644 src/main/java/menu/domain/Coaches.java diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index f6a8b9ebd..ada1f9f27 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,6 +1,6 @@ package menu.controller; -import menu.domain.Names; +import menu.domain.Coaches; import menu.view.InputView; import menu.view.OutputView; @@ -11,10 +11,10 @@ public class MenuController { public void start() { outputView.printStart(); - Names names = readNames(); + Coaches coaches = readNames(); } - private Names readNames() { + private Coaches readNames() { outputView.printCoachNames(); return inputView.readNames(); } diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java new file mode 100644 index 000000000..6e4a08963 --- /dev/null +++ b/src/main/java/menu/domain/Coach.java @@ -0,0 +1,10 @@ +package menu.domain; + +public class Coach { + + private final Name name; + + public Coach(Name name) { + this.name = name; + } +} diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java new file mode 100644 index 000000000..de4c8b8f4 --- /dev/null +++ b/src/main/java/menu/domain/Coaches.java @@ -0,0 +1,16 @@ +package menu.domain; + +import java.util.List; +import java.util.stream.Collectors; + +public class Coaches { + + private final List coaches; + + public Coaches(Names names) { + this.coaches = names.getElements() + .stream() + .map(Coach::new) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/menu/domain/Names.java b/src/main/java/menu/domain/Names.java index 0cb5691e2..f1d88fcfe 100644 --- a/src/main/java/menu/domain/Names.java +++ b/src/main/java/menu/domain/Names.java @@ -3,6 +3,7 @@ import menu.constant.ExceptionMessage; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class Names { @@ -22,4 +23,8 @@ private void validateRange(List names) { throw new IllegalArgumentException(ExceptionMessage.INCORRECT_NAME_RANGE.toString()); } } + + public List getElements() { + return Collections.unmodifiableList(elements); + } } \ No newline at end of file diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 35ed11542..c7899531c 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -1,6 +1,7 @@ package menu.view; import camp.nextstep.edu.missionutils.Console; +import menu.domain.Coaches; import menu.domain.Name; import menu.domain.Names; import menu.validator.InputValidator; @@ -13,12 +14,12 @@ public class InputView { private final InputValidator inputValidator = new InputValidator(); - public Names readNames() { + public Coaches readNames() { String input = Console.readLine(); inputValidator.validateDelimiter(input); List names = Stream.of(input.split(",")) .map(Name::new) .collect(Collectors.toList()); - return new Names(names); + return new Coaches(new Names(names)); } } From f5d402178df408ee5ec8e1c4300749b822133d9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 17:58:25 +0900 Subject: [PATCH 08/32] =?UTF-8?q?feat(InputView):=20=EA=B0=81=20=EC=BD=94?= =?UTF-8?q?=EC=B9=98=EB=A7=88=EB=8B=A4=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20?= =?UTF-8?q?=EC=9D=8C=EC=8B=9D=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/menu/constant/OutputMessage.java | 3 ++- src/main/java/menu/controller/MenuController.java | 9 +++++++++ src/main/java/menu/domain/Coach.java | 4 ++++ src/main/java/menu/domain/Coaches.java | 5 +++++ src/main/java/menu/view/InputView.java | 11 ++++++++++- src/main/java/menu/view/OutputView.java | 5 +++++ 7 files changed, 36 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 15221c500..3c35344a0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,7 +7,7 @@ - [x] 각 이름은 2~4글자가 아닐 경우 예외 발생 - [x] 코치 수가 2명~5명이 아닐 경우 예외 발생 -- [ ] 각 코치마다 못 먹는 음식 입력 +- [x] 각 코치마다 못 먹는 음식 입력 - [ ] 0~2개가 아닐 경우 예외 - [ ] 카테고리 추천 diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index e2c9233a5..9871daff0 100644 --- a/src/main/java/menu/constant/OutputMessage.java +++ b/src/main/java/menu/constant/OutputMessage.java @@ -3,7 +3,8 @@ public enum OutputMessage { START_RECOMMEND("점심 메뉴 추천을 시작합니다."), - READ_NAMES("코치의 이름을 입력해 주세요. (, 로 구분)"); + READ_NAMES("코치의 이름을 입력해 주세요. (, 로 구분)"), + READ_EXCLUDED_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."); private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index ada1f9f27..80acf1b79 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -12,10 +12,19 @@ public class MenuController { public void start() { outputView.printStart(); Coaches coaches = readNames(); + readExcludedFood(coaches); } private Coaches readNames() { outputView.printCoachNames(); return inputView.readNames(); } + + private void readExcludedFood(Coaches coaches) { + coaches.getCoaches() + .forEach(coach -> { + outputView.printExcludedMenu(coach.getName()); + inputView.readExcludedMenu(); + }); + } } diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 6e4a08963..3314ed797 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -7,4 +7,8 @@ public class Coach { public Coach(Name name) { this.name = name; } + + public String getName() { + return name.getValue(); + } } diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java index de4c8b8f4..6c0d40901 100644 --- a/src/main/java/menu/domain/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -1,5 +1,6 @@ package menu.domain; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -13,4 +14,8 @@ public Coaches(Names names) { .map(Coach::new) .collect(Collectors.toList()); } + + public List getCoaches() { + return Collections.unmodifiableList(coaches); + } } diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index c7899531c..8d645e5e5 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -12,14 +12,23 @@ public class InputView { + private static final String REGEX = ","; + private final InputValidator inputValidator = new InputValidator(); public Coaches readNames() { String input = Console.readLine(); inputValidator.validateDelimiter(input); - List names = Stream.of(input.split(",")) + List names = Stream.of(input.split(REGEX)) .map(Name::new) .collect(Collectors.toList()); return new Coaches(new Names(names)); } + + public List readExcludedMenu() { + String input = Console.readLine(); + inputValidator.validateDelimiter(input); + return Stream.of(input.split(REGEX)) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 54ccf3c51..de772e8ab 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -16,4 +16,9 @@ public void printCoachNames() { public void printNewLine() { System.out.println(); } + + public void printExcludedMenu(String name) { + System.out.printf(OutputMessage.READ_EXCLUDED_MENU.getMessage(), name); + printNewLine(); + } } From 0de4f818b0024aff1da0dd62dabf47b4a13f3a2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 18:06:18 +0900 Subject: [PATCH 09/32] =?UTF-8?q?feat(ExcludedMenu):=20=EB=AA=BB=20?= =?UTF-8?q?=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/MenuController.java | 2 +- src/main/java/menu/domain/Coach.java | 7 +++++++ src/main/java/menu/domain/ExcludedMenu.java | 13 +++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/main/java/menu/domain/ExcludedMenu.java diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 80acf1b79..a0e315100 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -24,7 +24,7 @@ private void readExcludedFood(Coaches coaches) { coaches.getCoaches() .forEach(coach -> { outputView.printExcludedMenu(coach.getName()); - inputView.readExcludedMenu(); + coach.addExcludedMenu(inputView.readExcludedMenu()); }); } } diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 3314ed797..8c652d430 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -1,13 +1,20 @@ package menu.domain; +import java.util.List; + public class Coach { private final Name name; + private final ExcludedMenu excludedMenu = new ExcludedMenu(); public Coach(Name name) { this.name = name; } + public void addExcludedMenu(List menu) { + excludedMenu.addElements(menu); + } + public String getName() { return name.getValue(); } diff --git a/src/main/java/menu/domain/ExcludedMenu.java b/src/main/java/menu/domain/ExcludedMenu.java new file mode 100644 index 000000000..90a1fdc67 --- /dev/null +++ b/src/main/java/menu/domain/ExcludedMenu.java @@ -0,0 +1,13 @@ +package menu.domain; + +import java.util.ArrayList; +import java.util.List; + +public class ExcludedMenu { + + private final List elements = new ArrayList<>(); + + public void addElements(List menus) { + elements.addAll(menus); + } +} From 8b6f5ca4296708faec4e7ee7a3a5a1b61ee64eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 18:17:28 +0900 Subject: [PATCH 10/32] =?UTF-8?q?feat(MenuController):=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/MenuController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index a0e315100..5c69899de 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -11,8 +11,13 @@ public class MenuController { public void start() { outputView.printStart(); + readCoaches(); + } + + private Coaches readCoaches() { Coaches coaches = readNames(); readExcludedFood(coaches); + return coaches; } private Coaches readNames() { From 9d5dcfc2561f0a4e49b73acfa3614d9567e7ab8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 18:23:16 +0900 Subject: [PATCH 11/32] =?UTF-8?q?feat(Days):=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EC=B6=94=EC=B2=9C=20=EC=9A=94=EC=9D=BC=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/constant/Days.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/menu/constant/Days.java diff --git a/src/main/java/menu/constant/Days.java b/src/main/java/menu/constant/Days.java new file mode 100644 index 000000000..b588b6212 --- /dev/null +++ b/src/main/java/menu/constant/Days.java @@ -0,0 +1,21 @@ +package menu.constant; + +public enum Days { + + MONDAY("월요일"), + TUESDAY("화요일"), + WEDNESDAY("수요일"), + THURSDAY("목요일"), + FRIDAY("금요일"); + + private final String day; + + Days(String day) { + this.day = day; + } + + @Override + public String toString() { + return day; + } +} \ No newline at end of file From 6481fb448c70735205b8a6c877d93781205b2cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 18:37:51 +0900 Subject: [PATCH 12/32] =?UTF-8?q?feat(Categories):=20=EC=9A=94=EC=9D=BC?= =?UTF-8?q?=EB=B3=84=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=B6=94?= =?UTF-8?q?=EC=B2=9C=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/menu/domain/Categories.java | 23 +++++++++++++++ src/main/java/menu/domain/Category.java | 34 +++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/main/java/menu/domain/Categories.java create mode 100644 src/main/java/menu/domain/Category.java diff --git a/src/main/java/menu/domain/Categories.java b/src/main/java/menu/domain/Categories.java new file mode 100644 index 000000000..744cdbaee --- /dev/null +++ b/src/main/java/menu/domain/Categories.java @@ -0,0 +1,23 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.ArrayList; +import java.util.List; + +public class Categories { + + private final List elements; + + public Categories() { + this.elements = recommendCategory(); + } + + private List recommendCategory() { + List categories = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + categories.add(Category.getRecommendFood(Randoms.pickNumberInRange(1, 5))); + } + return categories; + } +} diff --git a/src/main/java/menu/domain/Category.java b/src/main/java/menu/domain/Category.java new file mode 100644 index 000000000..e8717e220 --- /dev/null +++ b/src/main/java/menu/domain/Category.java @@ -0,0 +1,34 @@ +package menu.domain; + +import menu.constant.ExceptionMessage; + +import java.util.Arrays; + +public enum Category { + + JAPANESE(1, "일식"), + KOREAN(2, "한식"), + CHINESE(3, "중식"), + ASIAN(4, "아시안"), + WESTERN(5, "양식"); + + private final int index; + private final String type; + + Category(int index, String type) { + this.index = index; + this.type = type; + } + + public static Category getRecommendFood(int randomNumber) { + return Arrays.stream(Category.values()) + .filter(category -> category.index == randomNumber) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INCORRECT_RECOMMEND.toString())); + } + + @Override + public String toString() { + return type; + } +} From 3c816eb9e6ce88f70409e2d65e135bc4f57f7ebb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 18:53:31 +0900 Subject: [PATCH 13/32] =?UTF-8?q?feat(Categories):=20=EC=9D=B4=EB=AF=B8=20?= =?UTF-8?q?2=EB=B2=88=20=EC=B6=94=EC=B2=9C=EB=90=9C=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=9E=AC?= =?UTF-8?q?=EC=B6=94=EC=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 ++--- .../java/menu/constant/ExceptionMessage.java | 3 ++- src/main/java/menu/domain/Categories.java | 25 +++++++++++++++++-- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 3c35344a0..b1e93b308 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,9 +10,9 @@ - [x] 각 코치마다 못 먹는 음식 입력 - [ ] 0~2개가 아닐 경우 예외 -- [ ] 카테고리 추천 - - [ ] 월~금까지 먹을 카테고리를 추천한다. - - [ ] 이미 2번 추천된 카테고리일 경우 재추천 +- [x] 카테고리 추천 + - [x] 월~금까지 먹을 카테고리를 추천한다. + - [x] 이미 2번 추천된 카테고리일 경우 재추천 - [ ] 코치 별 음식 추천 - [ ] 요일마다 코치가 먹을 음식을 추천한다. diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java index 1e5654c98..3a16dc807 100644 --- a/src/main/java/menu/constant/ExceptionMessage.java +++ b/src/main/java/menu/constant/ExceptionMessage.java @@ -4,7 +4,8 @@ public enum ExceptionMessage { INCORRECT_DELIMITER("','로 구분하여 입력해야합니다."), INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."), - INCORRECT_COACH_NUMBER("코치는 2명 이상, 5명 이하만 입력할 수 있습니다."); + INCORRECT_COACH_NUMBER("코치는 2명 이상, 5명 이하만 입력할 수 있습니다."), + INCORRECT_RECOMMEND("등록되지 않은 카테고리입니다."); private static final String PREFIX = "[ERROR] "; private final String message; diff --git a/src/main/java/menu/domain/Categories.java b/src/main/java/menu/domain/Categories.java index 744cdbaee..b0be87794 100644 --- a/src/main/java/menu/domain/Categories.java +++ b/src/main/java/menu/domain/Categories.java @@ -7,17 +7,38 @@ public class Categories { + private static final int RECOMMEND_COUNT = 5; + private static final int MAX_RECOMMEND_COUNT = 2; + private static final int START_RANDOM_NUMBER = 1; + private static final int END_RANDOM_NUMBER = 5; + private final List elements; public Categories() { this.elements = recommendCategory(); + System.out.print(elements); } private List recommendCategory() { List categories = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - categories.add(Category.getRecommendFood(Randoms.pickNumberInRange(1, 5))); + while (categories.size() < RECOMMEND_COUNT) { + Category category = randomRecommend(); + if (isDuplicateRecommend(categories, category)) { + continue; + } + categories.add(category); } return categories; } + + private Category randomRecommend() { + int random = Randoms.pickNumberInRange(START_RANDOM_NUMBER, END_RANDOM_NUMBER); + return Category.getRecommendFood(random); + } + + private boolean isDuplicateRecommend(List categories, Category recommendCategory) { + return categories.stream() + .filter(category -> category == recommendCategory) + .count() >= MAX_RECOMMEND_COUNT; + } } From 49eb086f943c7c15b0f9c7543505f56203d2ecd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 18:54:27 +0900 Subject: [PATCH 14/32] =?UTF-8?q?feat(Names):=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Names.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/menu/domain/Names.java b/src/main/java/menu/domain/Names.java index f1d88fcfe..053841e4c 100644 --- a/src/main/java/menu/domain/Names.java +++ b/src/main/java/menu/domain/Names.java @@ -20,7 +20,7 @@ public Names(List names) { private void validateRange(List names) { if (!(MIN_RANGE <= names.size() && names.size() <= MAX_RANGE)) { - throw new IllegalArgumentException(ExceptionMessage.INCORRECT_NAME_RANGE.toString()); + throw new IllegalArgumentException(ExceptionMessage.INCORRECT_COACH_NUMBER.toString()); } } From 1812ba3e1be775a05f8aab7d16793bd659beaced Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 18:59:02 +0900 Subject: [PATCH 15/32] =?UTF-8?q?feat(Menu):=20=EB=93=B1=EB=A1=9D=EB=90=9C?= =?UTF-8?q?=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EB=B3=84=20=EB=A9=94?= =?UTF-8?q?=EB=89=B4=20=EA=B4=80=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Menu.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/menu/domain/Menu.java diff --git a/src/main/java/menu/domain/Menu.java b/src/main/java/menu/domain/Menu.java new file mode 100644 index 000000000..c88b77994 --- /dev/null +++ b/src/main/java/menu/domain/Menu.java @@ -0,0 +1,18 @@ +package menu.domain; + +import java.util.List; + +public enum Menu { + JAPANESE(Category.JAPANESE, List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")), + KOREAN(Category.KOREAN, List.of("김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기", "떡볶이", "제육볶음")), + CHINESE(Category.CHINESE, List.of("깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육", "토마토 달걀볶음", "고추잡채")), + ASIAN(Category.ASIAN, List.of("팟타이", "카오 팟", "나시고렝", "파인애플", "볶음밥", "쌀국수", "똠얌꿍", "반미", "월남쌈", "분짜")), + WESTERN(Category.WESTERN, List.of("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", "피자", "파니니")); + + private final Category category; + private final List foods; + Menu(Category category, List foods) { + this.category = category; + this.foods = foods; + } +} \ No newline at end of file From efbfa2b1f73e66225a562586293bb934bdbe9f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:00:12 +0900 Subject: [PATCH 16/32] =?UTF-8?q?feat(Menu):=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EC=9D=98=20=EC=A0=84=EC=B2=B4=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EA=B0=80=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Menu.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/menu/domain/Menu.java b/src/main/java/menu/domain/Menu.java index c88b77994..94d158677 100644 --- a/src/main/java/menu/domain/Menu.java +++ b/src/main/java/menu/domain/Menu.java @@ -1,5 +1,8 @@ package menu.domain; +import menu.constant.ExceptionMessage; + +import java.util.Arrays; import java.util.List; public enum Menu { @@ -15,4 +18,12 @@ public enum Menu { this.category = category; this.foods = foods; } + + public static List getMenuByCategory(Category category) { + return Arrays.stream(Menu.values()) + .filter(value -> value.category == category) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INCORRECT_RECOMMEND.toString())) + .foods; + } } \ No newline at end of file From 465dd497c3b52490cd4cc163f05c0227d5540566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:11:14 +0900 Subject: [PATCH 17/32] =?UTF-8?q?feat(RecommendMenu):=20=EB=A9=94=EB=89=B4?= =?UTF-8?q?=20=EC=B6=94=EC=B2=9C=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/menu/domain/Coach.java | 5 +++++ src/main/java/menu/domain/RecommendMenu.java | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/main/java/menu/domain/RecommendMenu.java diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 8c652d430..716355b41 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -6,6 +6,7 @@ public class Coach { private final Name name; private final ExcludedMenu excludedMenu = new ExcludedMenu(); + private final RecommendMenu recommendMenu = new RecommendMenu(); public Coach(Name name) { this.name = name; @@ -15,6 +16,10 @@ public void addExcludedMenu(List menu) { excludedMenu.addElements(menu); } + public void recommendMenu(Category category) { + recommendMenu.recommendMenu(category); + } + public String getName() { return name.getValue(); } diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java new file mode 100644 index 000000000..a056f9c79 --- /dev/null +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -0,0 +1,19 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.ArrayList; +import java.util.List; + +public class RecommendMenu { + + private static final int RECOMMEND_NUMBER = 0; + + private final List menus = new ArrayList<>(); + + public void recommendMenu(Category category) { + String recommendMenu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); + menus.add(recommendMenu); + System.out.print(menus); + } +} From 9e4fba22bc02a490f14750f33c68ebff2155ac82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:18:44 +0900 Subject: [PATCH 18/32] =?UTF-8?q?feat(MenuService):=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=EB=B3=84=20=EC=BD=94=EC=B9=98=20=EB=A9=94?= =?UTF-8?q?=EB=89=B4=20=EC=B6=94=EC=B2=9C=20=EA=B8=B0=EB=8A=A5=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 --- .../java/menu/controller/MenuController.java | 4 +++- src/main/java/menu/domain/Categories.java | 6 ++++- src/main/java/menu/domain/Coaches.java | 4 ++++ src/main/java/menu/service/MenuService.java | 23 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/main/java/menu/service/MenuService.java diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 5c69899de..32dc52c52 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,6 +1,7 @@ package menu.controller; import menu.domain.Coaches; +import menu.service.MenuService; import menu.view.InputView; import menu.view.OutputView; @@ -11,7 +12,8 @@ public class MenuController { public void start() { outputView.printStart(); - readCoaches(); + MenuService menuService = new MenuService(readCoaches()); + menuService.recommend(); } private Coaches readCoaches() { diff --git a/src/main/java/menu/domain/Categories.java b/src/main/java/menu/domain/Categories.java index b0be87794..457a54851 100644 --- a/src/main/java/menu/domain/Categories.java +++ b/src/main/java/menu/domain/Categories.java @@ -3,6 +3,7 @@ import camp.nextstep.edu.missionutils.Randoms; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class Categories { @@ -16,7 +17,6 @@ public class Categories { public Categories() { this.elements = recommendCategory(); - System.out.print(elements); } private List recommendCategory() { @@ -41,4 +41,8 @@ private boolean isDuplicateRecommend(List categories, Category recomme .filter(category -> category == recommendCategory) .count() >= MAX_RECOMMEND_COUNT; } + + public List getElements() { + return Collections.unmodifiableList(elements); + } } diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java index 6c0d40901..09b410cdc 100644 --- a/src/main/java/menu/domain/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -15,6 +15,10 @@ public Coaches(Names names) { .collect(Collectors.toList()); } + public void recommendByCategory(Category category) { + coaches.forEach(coach -> coach.recommendMenu(category)); + } + public List getCoaches() { return Collections.unmodifiableList(coaches); } diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java new file mode 100644 index 000000000..b538f91f1 --- /dev/null +++ b/src/main/java/menu/service/MenuService.java @@ -0,0 +1,23 @@ +package menu.service; + +import menu.domain.Categories; +import menu.domain.Coaches; + +public class MenuService { + + private final Coaches coaches; + + public MenuService(Coaches coaches) { + this.coaches = coaches; + } + + public void recommend() { + Categories categories = recommendCategory(); + categories.getElements() + .forEach(coaches::recommendByCategory); + } + + private Categories recommendCategory() { + return new Categories(); + } +} From 284dc559c3b8546d64917835345aa46e2f551fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:23:35 +0900 Subject: [PATCH 19/32] =?UTF-8?q?feat(RecommendMenu):=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=20=ED=95=9C=20=EB=B2=88=20=EB=A8=B9=EC=9D=80=20=EC=9D=8C?= =?UTF-8?q?=EC=8B=9D=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=9E=AC=EC=B6=94?= =?UTF-8?q?=EC=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/menu/domain/Coach.java | 2 +- src/main/java/menu/domain/RecommendMenu.java | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index b1e93b308..272881ca6 100644 --- a/docs/README.md +++ b/docs/README.md @@ -15,8 +15,8 @@ - [x] 이미 2번 추천된 카테고리일 경우 재추천 - [ ] 코치 별 음식 추천 - - [ ] 요일마다 코치가 먹을 음식을 추천한다. - - [ ] 이미 한 번 먹은 음식일 경우 재추천 + - [x] 요일마다 코치가 먹을 음식을 추천한다. + - [x] 이미 한 번 먹은 음식일 경우 재추천 - [ ] 코치가 못먹는 음식일 경우 재추천 - [ ] 추천 결과 출력 diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 716355b41..1885fe916 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -17,7 +17,7 @@ public void addExcludedMenu(List menu) { } public void recommendMenu(Category category) { - recommendMenu.recommendMenu(category); + recommendMenu.recommend(category); } public String getName() { diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java index a056f9c79..858e669c4 100644 --- a/src/main/java/menu/domain/RecommendMenu.java +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -11,9 +11,15 @@ public class RecommendMenu { private final List menus = new ArrayList<>(); - public void recommendMenu(Category category) { + public void recommend(Category category) { String recommendMenu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); + while (isDuplicate(recommendMenu)) { + recommendMenu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); + } menus.add(recommendMenu); - System.out.print(menus); + } + + private boolean isDuplicate(String menu) { + return menus.contains(menu); } } From 3cd0b3e215c8e5a26fa31b51f3df8098ff1cfbfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:26:01 +0900 Subject: [PATCH 20/32] =?UTF-8?q?fix(ExcludedMenu):=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Coach.java | 4 ++-- src/main/java/menu/domain/RecommendMenu.java | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 1885fe916..f9269948a 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -5,7 +5,7 @@ public class Coach { private final Name name; - private final ExcludedMenu excludedMenu = new ExcludedMenu(); + private final RecommendMenu recommendMenu = new RecommendMenu(); public Coach(Name name) { @@ -13,7 +13,7 @@ public Coach(Name name) { } public void addExcludedMenu(List menu) { - excludedMenu.addElements(menu); + recommendMenu.addExcludedMenu(menu); } public void recommendMenu(Category category) { diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java index 858e669c4..955a22140 100644 --- a/src/main/java/menu/domain/RecommendMenu.java +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -10,6 +10,11 @@ public class RecommendMenu { private static final int RECOMMEND_NUMBER = 0; private final List menus = new ArrayList<>(); + private final ExcludedMenu excludedMenu = new ExcludedMenu(); + + public void addExcludedMenu(List menu) { + excludedMenu.addElements(menu); + } public void recommend(Category category) { String recommendMenu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); From 148b32c8b02c71c8d8de2bf67425e6f69320b8fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:33:56 +0900 Subject: [PATCH 21/32] =?UTF-8?q?feat(RecommendMenu):=20=EC=BD=94=EC=B9=98?= =?UTF-8?q?=EA=B0=80=20=EB=AA=BB=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D?= =?UTF-8?q?=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EC=9E=AC=EC=B6=94=EC=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 4 ++-- src/main/java/menu/domain/ExcludedMenu.java | 4 ++++ src/main/java/menu/domain/RecommendMenu.java | 12 ++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 272881ca6..f7ad6086e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -14,10 +14,10 @@ - [x] 월~금까지 먹을 카테고리를 추천한다. - [x] 이미 2번 추천된 카테고리일 경우 재추천 -- [ ] 코치 별 음식 추천 +- [x] 코치 별 음식 추천 - [x] 요일마다 코치가 먹을 음식을 추천한다. - [x] 이미 한 번 먹은 음식일 경우 재추천 - - [ ] 코치가 못먹는 음식일 경우 재추천 + - [x] 코치가 못먹는 음식일 경우 재추천 - [ ] 추천 결과 출력 - [ ] 추천 완료 안내 \ No newline at end of file diff --git a/src/main/java/menu/domain/ExcludedMenu.java b/src/main/java/menu/domain/ExcludedMenu.java index 90a1fdc67..a88837f80 100644 --- a/src/main/java/menu/domain/ExcludedMenu.java +++ b/src/main/java/menu/domain/ExcludedMenu.java @@ -10,4 +10,8 @@ public class ExcludedMenu { public void addElements(List menus) { elements.addAll(menus); } + + public boolean canEat(String menu) { + return !(elements.contains(menu)); + } } diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java index 955a22140..1a5760831 100644 --- a/src/main/java/menu/domain/RecommendMenu.java +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -17,14 +17,18 @@ public void addExcludedMenu(List menu) { } public void recommend(Category category) { - String recommendMenu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); - while (isDuplicate(recommendMenu)) { - recommendMenu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); + String menu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); + while (isDuplicate(menu) || isExcludedMenu(menu)) { + menu = Randoms.shuffle(Menu.getMenuByCategory(category)).get(RECOMMEND_NUMBER); } - menus.add(recommendMenu); + menus.add(menu); } private boolean isDuplicate(String menu) { return menus.contains(menu); } + + private boolean isExcludedMenu(String menu) { + return !excludedMenu.canEat(menu); + } } From 5acef53bf41531dd3021deda25c7f864215acbc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:36:35 +0900 Subject: [PATCH 22/32] =?UTF-8?q?feat(OutputView):=20=EA=B2=B0=EA=B3=BC=20?= =?UTF-8?q?=EC=95=88=EB=82=B4=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/constant/OutputMessage.java | 4 +++- src/main/java/menu/view/OutputView.java | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index 9871daff0..7d58312ad 100644 --- a/src/main/java/menu/constant/OutputMessage.java +++ b/src/main/java/menu/constant/OutputMessage.java @@ -4,7 +4,9 @@ public enum OutputMessage { START_RECOMMEND("점심 메뉴 추천을 시작합니다."), READ_NAMES("코치의 이름을 입력해 주세요. (, 로 구분)"), - READ_EXCLUDED_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."); + READ_EXCLUDED_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."), + RECOMMEND_RESULT("메뉴 추천 결과입니다."), + COMPLETE_RECOMMEND("추천을 완료했습니다."); private final String message; diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index de772e8ab..27d9b824a 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -21,4 +21,8 @@ public void printExcludedMenu(String name) { System.out.printf(OutputMessage.READ_EXCLUDED_MENU.getMessage(), name); printNewLine(); } + + public void printResultMessage() { + System.out.print(OutputMessage.RECOMMEND_RESULT.getMessage()); + } } From a03c0eec8ff2d0dd8784e2aeca22b37b6c76287e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:42:35 +0900 Subject: [PATCH 23/32] =?UTF-8?q?feat(OutputView):=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=9A=94=EC=9D=BC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/menu/constant/OutputMessage.java | 3 ++- .../java/menu/constant/ResultElement.java | 20 +++++++++++++++++ src/main/java/menu/view/OutputView.java | 22 +++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/main/java/menu/constant/ResultElement.java diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index 7d58312ad..98c0f7aa1 100644 --- a/src/main/java/menu/constant/OutputMessage.java +++ b/src/main/java/menu/constant/OutputMessage.java @@ -6,7 +6,8 @@ public enum OutputMessage { READ_NAMES("코치의 이름을 입력해 주세요. (, 로 구분)"), READ_EXCLUDED_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."), RECOMMEND_RESULT("메뉴 추천 결과입니다."), - COMPLETE_RECOMMEND("추천을 완료했습니다."); + COMPLETE_RECOMMEND("추천을 완료했습니다."), + DAYS("구분"); private final String message; diff --git a/src/main/java/menu/constant/ResultElement.java b/src/main/java/menu/constant/ResultElement.java new file mode 100644 index 000000000..839b60516 --- /dev/null +++ b/src/main/java/menu/constant/ResultElement.java @@ -0,0 +1,20 @@ +package menu.constant; + +public enum ResultElement { + + START("[ "), + END(" ]"), + DELIMITER(" | "); + + + private final String element; + + ResultElement(String element) { + this.element = element; + } + + @Override + public String toString() { + return this.element; + } +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 27d9b824a..69c7c71e6 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -1,6 +1,11 @@ package menu.view; +import menu.constant.Days; import menu.constant.OutputMessage; +import menu.constant.ResultElement; + +import java.util.Arrays; +import java.util.StringJoiner; public class OutputView { @@ -22,7 +27,20 @@ public void printExcludedMenu(String name) { printNewLine(); } - public void printResultMessage() { - System.out.print(OutputMessage.RECOMMEND_RESULT.getMessage()); + public void printRecommendResult() { + printResultMessage(); + printDays(); + } + + private void printResultMessage() { + System.out.println(OutputMessage.RECOMMEND_RESULT.getMessage()); + } + + private void printDays() { + StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); + stringJoiner.add(OutputMessage.DAYS.getMessage()); + Arrays.stream(Days.values()) + .forEach((day) -> stringJoiner.add(day.toString())); + System.out.println(stringJoiner); } } From d1923b9122fca15fa117aad0ffef6e0caa57b568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:51:05 +0900 Subject: [PATCH 24/32] =?UTF-8?q?feat(OutputView):=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/constant/OutputMessage.java | 3 ++- .../java/menu/controller/MenuController.java | 1 + src/main/java/menu/domain/Categories.java | 18 +++++++++++++++--- src/main/java/menu/service/MenuService.java | 7 ++++--- src/main/java/menu/view/OutputView.java | 8 +++++++- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index 98c0f7aa1..ab8e84a37 100644 --- a/src/main/java/menu/constant/OutputMessage.java +++ b/src/main/java/menu/constant/OutputMessage.java @@ -7,7 +7,8 @@ public enum OutputMessage { READ_EXCLUDED_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."), RECOMMEND_RESULT("메뉴 추천 결과입니다."), COMPLETE_RECOMMEND("추천을 완료했습니다."), - DAYS("구분"); + DAYS("구분"), + CATEGORIES("카테고리"); private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 32dc52c52..590e2921a 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -14,6 +14,7 @@ public void start() { outputView.printStart(); MenuService menuService = new MenuService(readCoaches()); menuService.recommend(); + outputView.printRecommendResult(menuService.getCategories()); } private Coaches readCoaches() { diff --git a/src/main/java/menu/domain/Categories.java b/src/main/java/menu/domain/Categories.java index 457a54851..f173af650 100644 --- a/src/main/java/menu/domain/Categories.java +++ b/src/main/java/menu/domain/Categories.java @@ -1,10 +1,10 @@ package menu.domain; import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.OutputMessage; +import menu.constant.ResultElement; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.*; public class Categories { @@ -45,4 +45,16 @@ private boolean isDuplicateRecommend(List categories, Category recomme public List getElements() { return Collections.unmodifiableList(elements); } + + public String getCategories() { + String delimiter = ResultElement.DELIMITER.toString(); + String start = ResultElement.START.toString(); + String end = ResultElement.END.toString(); + + StringJoiner stringJoiner = new StringJoiner(delimiter, start, end); + + stringJoiner.add(OutputMessage.CATEGORIES.getMessage()); + elements.forEach(element -> stringJoiner.add(element.toString())); + return stringJoiner.toString(); + } } diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index b538f91f1..3f77d6214 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -6,18 +6,19 @@ public class MenuService { private final Coaches coaches; + private final Categories categories; public MenuService(Coaches coaches) { this.coaches = coaches; + this.categories = new Categories(); } public void recommend() { - Categories categories = recommendCategory(); categories.getElements() .forEach(coaches::recommendByCategory); } - private Categories recommendCategory() { - return new Categories(); + public Categories getCategories() { + return categories; } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 69c7c71e6..e91576847 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -3,6 +3,7 @@ import menu.constant.Days; import menu.constant.OutputMessage; import menu.constant.ResultElement; +import menu.domain.Categories; import java.util.Arrays; import java.util.StringJoiner; @@ -27,9 +28,10 @@ public void printExcludedMenu(String name) { printNewLine(); } - public void printRecommendResult() { + public void printRecommendResult(Categories categories) { printResultMessage(); printDays(); + printCategories(categories); } private void printResultMessage() { @@ -43,4 +45,8 @@ private void printDays() { .forEach((day) -> stringJoiner.add(day.toString())); System.out.println(stringJoiner); } + + private void printCategories(Categories categories) { + System.out.println(categories.getCategories()); + } } From 1238c62974ba5c64cec5c6d8e90e7ae3f89f0783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 19:59:59 +0900 Subject: [PATCH 25/32] =?UTF-8?q?feat(OutputView):=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/menu/constant/ResultElement.java | 3 ++- src/main/java/menu/controller/MenuController.java | 2 +- src/main/java/menu/domain/Coach.java | 15 +++++++++++++++ src/main/java/menu/domain/Coaches.java | 10 ++++++++++ src/main/java/menu/domain/RecommendMenu.java | 9 +++++++++ src/main/java/menu/service/MenuService.java | 4 ++++ src/main/java/menu/view/OutputView.java | 8 +++++++- 8 files changed, 49 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index f7ad6086e..975bf4737 100644 --- a/docs/README.md +++ b/docs/README.md @@ -19,5 +19,5 @@ - [x] 이미 한 번 먹은 음식일 경우 재추천 - [x] 코치가 못먹는 음식일 경우 재추천 -- [ ] 추천 결과 출력 +- [x] 추천 결과 출력 - [ ] 추천 완료 안내 \ No newline at end of file diff --git a/src/main/java/menu/constant/ResultElement.java b/src/main/java/menu/constant/ResultElement.java index 839b60516..eee719990 100644 --- a/src/main/java/menu/constant/ResultElement.java +++ b/src/main/java/menu/constant/ResultElement.java @@ -4,7 +4,8 @@ public enum ResultElement { START("[ "), END(" ]"), - DELIMITER(" | "); + DELIMITER(" | "), + NEW_LINE("\n"); private final String element; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 590e2921a..ebc042383 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -14,7 +14,7 @@ public void start() { outputView.printStart(); MenuService menuService = new MenuService(readCoaches()); menuService.recommend(); - outputView.printRecommendResult(menuService.getCategories()); + outputView.printRecommendResult(menuService.getCategories(), menuService.getCoaches()); } private Coaches readCoaches() { diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index f9269948a..e970aa818 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -1,6 +1,9 @@ package menu.domain; +import menu.constant.ResultElement; + import java.util.List; +import java.util.StringJoiner; public class Coach { @@ -23,4 +26,16 @@ public void recommendMenu(Category category) { public String getName() { return name.getValue(); } + + public String getRecommendMenu() { + String delimiter = ResultElement.DELIMITER.toString(); + String start = ResultElement.START.toString(); + String end = ResultElement.END.toString(); + + StringJoiner stringJoiner = new StringJoiner(delimiter, start, end); + + stringJoiner.add(name.getValue()); + stringJoiner.add(recommendMenu.getMenus()); + return stringJoiner.toString(); + } } diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java index 09b410cdc..ac534143f 100644 --- a/src/main/java/menu/domain/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -1,5 +1,7 @@ package menu.domain; +import menu.constant.ResultElement; + import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -22,4 +24,12 @@ public void recommendByCategory(Category category) { public List getCoaches() { return Collections.unmodifiableList(coaches); } + + public String getRecommend() { + StringBuilder stringBuilder = new StringBuilder(); + coaches.forEach(coach -> + stringBuilder.append(coach.getRecommendMenu()) + .append(ResultElement.NEW_LINE)); + return stringBuilder.toString(); + } } diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java index 1a5760831..264cd0b5f 100644 --- a/src/main/java/menu/domain/RecommendMenu.java +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -1,9 +1,11 @@ package menu.domain; import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.ResultElement; import java.util.ArrayList; import java.util.List; +import java.util.StringJoiner; public class RecommendMenu { @@ -31,4 +33,11 @@ private boolean isDuplicate(String menu) { private boolean isExcludedMenu(String menu) { return !excludedMenu.canEat(menu); } + + public String getMenus() { + StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString()); + + menus.forEach(stringJoiner::add); + return stringJoiner.toString(); + } } diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index 3f77d6214..1abec2971 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -21,4 +21,8 @@ public void recommend() { public Categories getCategories() { return categories; } + + public Coaches getCoaches() { + return coaches; + } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index e91576847..a7d6a17b3 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -4,6 +4,7 @@ import menu.constant.OutputMessage; import menu.constant.ResultElement; import menu.domain.Categories; +import menu.domain.Coaches; import java.util.Arrays; import java.util.StringJoiner; @@ -28,10 +29,11 @@ public void printExcludedMenu(String name) { printNewLine(); } - public void printRecommendResult(Categories categories) { + public void printRecommendResult(Categories categories, Coaches coaches) { printResultMessage(); printDays(); printCategories(categories); + printCoaches(coaches); } private void printResultMessage() { @@ -49,4 +51,8 @@ private void printDays() { private void printCategories(Categories categories) { System.out.println(categories.getCategories()); } + + private void printCoaches(Coaches coaches) { + System.out.println(coaches.getRecommend()); + } } From a53173a42e114071a7ea6a3873c1ca364689c7a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 20:02:12 +0900 Subject: [PATCH 26/32] =?UTF-8?q?feat(OutputView):=20=EC=B6=94=EC=B2=9C=20?= =?UTF-8?q?=EC=99=84=EB=A3=8C=20=EC=95=88=EB=82=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/view/OutputView.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index a7d6a17b3..06bf630b8 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -34,6 +34,7 @@ public void printRecommendResult(Categories categories, Coaches coaches) { printDays(); printCategories(categories); printCoaches(coaches); + printCompleteMessage(); } private void printResultMessage() { @@ -55,4 +56,8 @@ private void printCategories(Categories categories) { private void printCoaches(Coaches coaches) { System.out.println(coaches.getRecommend()); } + + private void printCompleteMessage() { + System.out.println(OutputMessage.COMPLETE_RECOMMEND.getMessage()); + } } From e1a07ba0a2ea9e09f9414011c172cd3fdc0a0f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 20:02:24 +0900 Subject: [PATCH 27/32] =?UTF-8?q?docs:=20=EA=B5=AC=ED=98=84=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B2=B4=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 975bf4737..ce6bb534f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,4 +20,4 @@ - [x] 코치가 못먹는 음식일 경우 재추천 - [x] 추천 결과 출력 -- [ ] 추천 완료 안내 \ No newline at end of file +- [x] 추천 완료 안내 \ No newline at end of file From f95d828d66a94d1c82c1327244de1249ae811ba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 20:17:30 +0900 Subject: [PATCH 28/32] =?UTF-8?q?feat(ExcludedMenu):=20=EB=AA=BB=EB=A8=B9?= =?UTF-8?q?=EB=8A=94=20=EC=9D=8C=EC=8B=9D=202=EA=B0=9C=20=EC=9D=B4?= =?UTF-8?q?=EC=83=81=20=EC=9E=85=EB=A0=A5=20=EC=8B=9C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/menu/constant/ExceptionMessage.java | 3 ++- src/main/java/menu/domain/ExcludedMenu.java | 11 +++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index ce6bb534f..32dd65890 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,7 +8,7 @@ - [x] 코치 수가 2명~5명이 아닐 경우 예외 발생 - [x] 각 코치마다 못 먹는 음식 입력 - - [ ] 0~2개가 아닐 경우 예외 + - [x] 0~2개가 아닐 경우 예외 - [x] 카테고리 추천 - [x] 월~금까지 먹을 카테고리를 추천한다. diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java index 3a16dc807..0c66010fd 100644 --- a/src/main/java/menu/constant/ExceptionMessage.java +++ b/src/main/java/menu/constant/ExceptionMessage.java @@ -5,7 +5,8 @@ public enum ExceptionMessage { INCORRECT_DELIMITER("','로 구분하여 입력해야합니다."), INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."), INCORRECT_COACH_NUMBER("코치는 2명 이상, 5명 이하만 입력할 수 있습니다."), - INCORRECT_RECOMMEND("등록되지 않은 카테고리입니다."); + INCORRECT_RECOMMEND("등록되지 않은 카테고리입니다."), + EXCLUDED_FOOD_SIZE("못먹는 음식은 0~2개까지 입력가능합니다."); private static final String PREFIX = "[ERROR] "; private final String message; diff --git a/src/main/java/menu/domain/ExcludedMenu.java b/src/main/java/menu/domain/ExcludedMenu.java index a88837f80..228e1330d 100644 --- a/src/main/java/menu/domain/ExcludedMenu.java +++ b/src/main/java/menu/domain/ExcludedMenu.java @@ -1,16 +1,27 @@ package menu.domain; +import menu.constant.ExceptionMessage; + import java.util.ArrayList; import java.util.List; public class ExcludedMenu { + private static final int MAX_SIZE = 2; + private final List elements = new ArrayList<>(); public void addElements(List menus) { + validateSize(menus); elements.addAll(menus); } + private void validateSize(List menus) { + if (!(menus.size() <= MAX_SIZE)) { + throw new IllegalArgumentException(ExceptionMessage.EXCLUDED_FOOD_SIZE.toString()); + } + } + public boolean canEat(String menu) { return !(elements.contains(menu)); } From 89a204d24942403e39bd525640a65071bd80c444 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 20:17:50 +0900 Subject: [PATCH 29/32] =?UTF-8?q?test(Name):=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/domain/NamesTest.java | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/java/menu/domain/NamesTest.java diff --git a/src/test/java/menu/domain/NamesTest.java b/src/test/java/menu/domain/NamesTest.java new file mode 100644 index 000000000..e4be57571 --- /dev/null +++ b/src/test/java/menu/domain/NamesTest.java @@ -0,0 +1,41 @@ +package menu.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class NamesTest { + + private static final String ERROR_MESSAGE = "[ERROR]"; + + @DisplayName("코치 수가 1이하일 경우 예외가 발생한다.") + @Test + void minCaochRangeException() { + Name name = new Name("김연진"); + + assertThatThrownBy(() -> new Names(List.of(name))) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("코치 수가 1이하일 경우 예외가 발생한다.") + @Test + void maxCaochRangeException() { + Name name1 = new Name("김연진"); + Name name2 = new Name("토미"); + Name name3 = new Name("제임스"); + Name name4 = new Name("포크"); + Name name5 = new Name("이름"); + Name name6 = new Name("닉네임"); + + List names = List.of(name1, name2, name3, name4, name5, name6); + + assertThatThrownBy(() -> new Names(names)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } +} From d61cd3287fc8018706abeb1ce5de50a651b772f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 20:18:02 +0900 Subject: [PATCH 30/32] =?UTF-8?q?test(Names):=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/domain/NameTest.java | 30 +++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/test/java/menu/domain/NameTest.java diff --git a/src/test/java/menu/domain/NameTest.java b/src/test/java/menu/domain/NameTest.java new file mode 100644 index 000000000..5806b0179 --- /dev/null +++ b/src/test/java/menu/domain/NameTest.java @@ -0,0 +1,30 @@ +package menu.domain; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class NameTest { + private static final String ERROR_MESSAGE = "[ERROR]"; + + @DisplayName("이름의 길이가 4가 넘어갈 경우 예외가 발생한다.") + @Test + void nameMaxLengthException() { + String name = "김연진김연진"; + + assertThatThrownBy(() -> new Name(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @DisplayName("이름의 길이가 1이하일 경우 예외가 발생한다.") + @Test + void nameMinLengthException() { + String name = "김"; + + assertThatThrownBy(() -> new Name(name)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } +} From 3b8141d4fdd08bcd13293eb0853bf285cec23b7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 20:22:42 +0900 Subject: [PATCH 31/32] =?UTF-8?q?feat:=20=EC=98=88=EC=99=B8=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=20=EC=A7=80=EC=A0=90=EB=B6=80=ED=84=B0=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=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 --- .../java/menu/controller/MenuController.java | 13 +++++-- src/main/java/menu/view/InputView.java | 39 ++++++++++++++----- src/main/java/menu/view/OutputView.java | 4 ++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index ebc042383..8cdbf9c47 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -11,10 +11,15 @@ public class MenuController { private final InputView inputView = new InputView(); public void start() { - outputView.printStart(); - MenuService menuService = new MenuService(readCoaches()); - menuService.recommend(); - outputView.printRecommendResult(menuService.getCategories(), menuService.getCoaches()); + try { + outputView.printStart(); + MenuService menuService = new MenuService(readCoaches()); + menuService.recommend(); + outputView.printRecommendResult(menuService.getCategories(), menuService.getCoaches()); + } catch (IllegalArgumentException exception) { + outputView.printExceptionMessage(exception.getMessage()); + } + } private Coaches readCoaches() { diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 8d645e5e5..b0e447ef1 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -7,6 +7,7 @@ import menu.validator.InputValidator; import java.util.List; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -17,18 +18,36 @@ public class InputView { private final InputValidator inputValidator = new InputValidator(); public Coaches readNames() { - String input = Console.readLine(); - inputValidator.validateDelimiter(input); - List names = Stream.of(input.split(REGEX)) - .map(Name::new) - .collect(Collectors.toList()); - return new Coaches(new Names(names)); + + return attemptedInput( + () -> { + String input = Console.readLine(); + inputValidator.validateDelimiter(input); + List names = Stream.of(input.split(REGEX)) + .map(Name::new) + .collect(Collectors.toList()); + return new Coaches(new Names(names)); + } + ); } public List readExcludedMenu() { - String input = Console.readLine(); - inputValidator.validateDelimiter(input); - return Stream.of(input.split(REGEX)) - .collect(Collectors.toList()); + return attemptedInput( + () -> { + String input = Console.readLine(); + inputValidator.validateDelimiter(input); + return Stream.of(input.split(REGEX)) + .collect(Collectors.toList()); + } + ); + } + + private T attemptedInput(Supplier supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + System.out.println(exception.getMessage()); + return supplier.get(); + } } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 06bf630b8..c642ced10 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -60,4 +60,8 @@ private void printCoaches(Coaches coaches) { private void printCompleteMessage() { System.out.println(OutputMessage.COMPLETE_RECOMMEND.getMessage()); } + + public void printExceptionMessage(String message) { + System.out.println(message); + } } From 3702089884e0b3f75e009189b8b83e389ba168f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sun, 10 Sep 2023 20:32:01 +0900 Subject: [PATCH 32/32] =?UTF-8?q?fix(ExcludedMenu):=20=EB=AA=BB=EB=A8=B9?= =?UTF-8?q?=EB=8A=94=20=EC=9D=8C=EC=8B=9D=20=EC=B6=94=EA=B0=80=20=EB=B0=A9?= =?UTF-8?q?=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/MenuController.java | 13 ++++--------- src/main/java/menu/domain/Coach.java | 9 ++++----- src/main/java/menu/domain/ExcludedMenu.java | 8 ++++---- src/main/java/menu/domain/RecommendMenu.java | 6 +++--- src/main/java/menu/view/InputView.java | 7 ++++--- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 8cdbf9c47..ebc042383 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -11,15 +11,10 @@ public class MenuController { private final InputView inputView = new InputView(); public void start() { - try { - outputView.printStart(); - MenuService menuService = new MenuService(readCoaches()); - menuService.recommend(); - outputView.printRecommendResult(menuService.getCategories(), menuService.getCoaches()); - } catch (IllegalArgumentException exception) { - outputView.printExceptionMessage(exception.getMessage()); - } - + outputView.printStart(); + MenuService menuService = new MenuService(readCoaches()); + menuService.recommend(); + outputView.printRecommendResult(menuService.getCategories(), menuService.getCoaches()); } private Coaches readCoaches() { diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index e970aa818..a03b1b527 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -2,7 +2,6 @@ import menu.constant.ResultElement; -import java.util.List; import java.util.StringJoiner; public class Coach { @@ -15,10 +14,6 @@ public Coach(Name name) { this.name = name; } - public void addExcludedMenu(List menu) { - recommendMenu.addExcludedMenu(menu); - } - public void recommendMenu(Category category) { recommendMenu.recommend(category); } @@ -38,4 +33,8 @@ public String getRecommendMenu() { stringJoiner.add(recommendMenu.getMenus()); return stringJoiner.toString(); } + + public void addExcludedMenu(ExcludedMenu excludedMenu) { + recommendMenu.addExcludedMenu(excludedMenu); + } } diff --git a/src/main/java/menu/domain/ExcludedMenu.java b/src/main/java/menu/domain/ExcludedMenu.java index 228e1330d..f613e80c7 100644 --- a/src/main/java/menu/domain/ExcludedMenu.java +++ b/src/main/java/menu/domain/ExcludedMenu.java @@ -9,11 +9,11 @@ public class ExcludedMenu { private static final int MAX_SIZE = 2; - private final List elements = new ArrayList<>(); + private final List elements; - public void addElements(List menus) { - validateSize(menus); - elements.addAll(menus); + public ExcludedMenu(List elements) { + validateSize(elements); + this.elements = new ArrayList<>(elements); } private void validateSize(List menus) { diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java index 264cd0b5f..c98cd7090 100644 --- a/src/main/java/menu/domain/RecommendMenu.java +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -12,10 +12,10 @@ public class RecommendMenu { private static final int RECOMMEND_NUMBER = 0; private final List menus = new ArrayList<>(); - private final ExcludedMenu excludedMenu = new ExcludedMenu(); + private ExcludedMenu excludedMenu; - public void addExcludedMenu(List menu) { - excludedMenu.addElements(menu); + public void addExcludedMenu(ExcludedMenu excludedMenu) { + this.excludedMenu = excludedMenu; } public void recommend(Category category) { diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index b0e447ef1..392f87674 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -2,6 +2,7 @@ import camp.nextstep.edu.missionutils.Console; import menu.domain.Coaches; +import menu.domain.ExcludedMenu; import menu.domain.Name; import menu.domain.Names; import menu.validator.InputValidator; @@ -18,7 +19,6 @@ public class InputView { private final InputValidator inputValidator = new InputValidator(); public Coaches readNames() { - return attemptedInput( () -> { String input = Console.readLine(); @@ -31,13 +31,14 @@ public Coaches readNames() { ); } - public List readExcludedMenu() { + public ExcludedMenu readExcludedMenu() { return attemptedInput( () -> { String input = Console.readLine(); inputValidator.validateDelimiter(input); - return Stream.of(input.split(REGEX)) + List excludedMenu = Stream.of(input.split(REGEX)) .collect(Collectors.toList()); + return new ExcludedMenu(excludedMenu); } ); }