From f85b2d7b36bdfa235c80af41177933504f06b386 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 14:08:47 +0900 Subject: [PATCH 01/53] =?UTF-8?q?chore:=20=EA=B8=B0=EB=8A=A5=EA=B5=AC?= =?UTF-8?q?=ED=98=84/=EC=97=90=EB=9F=AC=20=EC=B2=98=EB=A6=AC=20=EC=A0=95?= =?UTF-8?q?=EC=9D=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29bb..bee0f02d9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,32 @@ +## 기능 구현 + +- InputView + - 코치의 이름을 입력받는다. + - 코치의 이름은 최소 2글자, 최대 4글자이다. + - 먹지 못하는 메뉴가 없으면 빈 값을 입력한다. + +- Coach + - 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - 각 코치는 최소 0개, 최대 2개의 못 먹는 메뉴가 있다. + +- Category + - 1이면 일식, 2면 한식, 3이면 중식, 4면 아시안, 5면 양식을 추천한다. + - 한 주에 같은 카테고리는 최대 2회까지만 고를 수 있다. + +- Menu + - 카테고리에 맞는 메뉴를 생성 + - 카테고리에 포함되는 메뉴 목록을 List 형태로 준비한다. + - 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. + +- OutputView + - 메뉴 추천 결과를 출력한다. + +- Coaches + - 각 코치들의 못 먹는 메뉴를 저장한다. + +## 에러 처리 + +- InputValidate + - 사용자가 잘못된 값을 입력할 경우 IllegalArgumentException를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. + Exception이 아닌 IllegalArgumentException, IllegalStateException 등과 같은 명확한 유형을 처리한다. + - , 로 구분해서 입력한다. \ No newline at end of file From 22705ac10af852b414bfe26e006b45b5f53a14ef Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:10:20 +0900 Subject: [PATCH 02/53] =?UTF-8?q?feat:=20InputView=20inputCoachName=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputView.java | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/menu/InputView.java diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java new file mode 100644 index 000000000..ee40a72dd --- /dev/null +++ b/src/main/java/menu/InputView.java @@ -0,0 +1,32 @@ +package menu; + +import java.util.Scanner; +import java.util.function.Supplier; + +public class InputView { + + private final InputValidator inputValidator = new InputValidator(); + private final OutputView outputView = new OutputView(); + private final Scanner scanner = new Scanner(System.in); + + public Coaches inputCoachName(){ + return read(() -> { + outputView.printProgressCoachNameMessage(); + String names = scanner.next(); + inputValidator.validateContainComma(names); + return new Coaches(names); + }); + } + + + + private T read(Supplier supplier){ + while (true){ + try { + return supplier.get(); + } catch (IllegalArgumentException e){ + outputView.printErrorMessage(e.getMessage()); + } + } + } +} From ba85652620d80a058adecd7e62078c5649609f32 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:10:44 +0900 Subject: [PATCH 03/53] =?UTF-8?q?feat:=20InputValidator=20validateContainC?= =?UTF-8?q?omma=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputValidator.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/menu/InputValidator.java diff --git a/src/main/java/menu/InputValidator.java b/src/main/java/menu/InputValidator.java new file mode 100644 index 000000000..f5631ad8e --- /dev/null +++ b/src/main/java/menu/InputValidator.java @@ -0,0 +1,12 @@ +package menu; + +public class InputValidator { + + public static final String DIVISION = ","; + + public void validateContainComma(String names){ + if (!names.contains(DIVISION)){ + throw new IllegalArgumentException(ErrorMessage.DIVISION_COMMA_ERROR.getMessage()); + } + } +} From 5a32f968cf3b928fca7d83b9ea140f08b578f0e2 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:10:58 +0900 Subject: [PATCH 04/53] =?UTF-8?q?feat:=20ErrorMessage=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ErrorMessage.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/menu/ErrorMessage.java diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/ErrorMessage.java new file mode 100644 index 000000000..0c40b476a --- /dev/null +++ b/src/main/java/menu/ErrorMessage.java @@ -0,0 +1,18 @@ +package menu; + +public enum ErrorMessage { + DIVISION_COMMA_ERROR("(, 로 구분)되지 않았습니다."), + COACH_NAME_LENGTH_ERROR("코치 이름은 최소 2글자, 최대 4글자까지 입력가능 합니다."), + COACH_NUMBER_ERROR("코치는 최소 2명, 최대 5명자까지 입력가능 합니다."); + + private static final String error = "[ERROR] "; + private final String message; + + ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return error + message; + } +} From d663d670e8e16936d3ddefa94e67cd79e864d9d6 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:11:06 +0900 Subject: [PATCH 05/53] =?UTF-8?q?feat:=20ProgressMessage=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ProgressMessage.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/main/java/menu/ProgressMessage.java diff --git a/src/main/java/menu/ProgressMessage.java b/src/main/java/menu/ProgressMessage.java new file mode 100644 index 000000000..d39e267eb --- /dev/null +++ b/src/main/java/menu/ProgressMessage.java @@ -0,0 +1,14 @@ +package menu; + +public enum ProgressMessage { + INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"); + private final String message; + + ProgressMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} From 11d9ad55784081e7a4f2d0abc3fa3bc118468e71 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:11:18 +0900 Subject: [PATCH 06/53] =?UTF-8?q?feat:=20Coach=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Coach.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/main/java/menu/Coach.java diff --git a/src/main/java/menu/Coach.java b/src/main/java/menu/Coach.java new file mode 100644 index 000000000..f8c8a2fa9 --- /dev/null +++ b/src/main/java/menu/Coach.java @@ -0,0 +1,21 @@ +package menu; + +public class Coach { + + private static final int MIN_NAME_LENGTH = 2; + private static final int MAX_NAME_LENGTH = 4; + private final String name; + public final ForbiddenMenu forbiddenMenu; + + public Coach(String name) { + validateCoachNameLength(name); + this.name = name; + this.forbiddenMenu = new ForbiddenMenu(); + } + + private void validateCoachNameLength(String name) { + if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH){ + throw new IllegalArgumentException(ErrorMessage.COACH_NAME_LENGTH_ERROR.getMessage()); + } + } +} From 0e6aab4b174e6375ae362ca55aafb56fa5de5bb5 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:11:24 +0900 Subject: [PATCH 07/53] =?UTF-8?q?feat:=20Coaches=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Coaches.java | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/main/java/menu/Coaches.java diff --git a/src/main/java/menu/Coaches.java b/src/main/java/menu/Coaches.java new file mode 100644 index 000000000..1f7287c6b --- /dev/null +++ b/src/main/java/menu/Coaches.java @@ -0,0 +1,35 @@ +package menu; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static menu.InputValidator.DIVISION; + +public class Coaches { + + private static final int MIN_COACH_NUMBER = 2; + private static final int MAX_COACH_NUMBER = 5; + private final List coaches = new ArrayList<>(); + + public Coaches(String names) { + String[] coachNames = names.split(DIVISION); + validateCoachNumber(coachNames.length); + addCoaches(coachNames); + } + + private void validateCoachNumber(int number) { + if (number < MIN_COACH_NUMBER || number > MAX_COACH_NUMBER){ + throw new IllegalArgumentException(ErrorMessage.COACH_NUMBER_ERROR.getMessage()); + } + } + + private void addCoaches(String[] coachNames) { + coaches.addAll(Arrays.stream(coachNames) + .map(String::trim) + .map(Coach::new) + .collect(Collectors.toList())); + } + +} From d9641b0a111efa95ba6bb1f17d92333e77b1c8fe Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:11:34 +0900 Subject: [PATCH 08/53] =?UTF-8?q?feat:=20OutputView=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/OutputView.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/menu/OutputView.java diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java new file mode 100644 index 000000000..4703adb2f --- /dev/null +++ b/src/main/java/menu/OutputView.java @@ -0,0 +1,12 @@ +package menu; + +public class OutputView { + + public void printErrorMessage(String error){ + System.out.println(error); + } + + public void printProgressCoachNameMessage(){ + System.out.println(ProgressMessage.INPUT_COACH_NAME); + } +} From c01cb8407d64d1d68545a18c52fffec4b0e09ef4 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:11:44 +0900 Subject: [PATCH 09/53] =?UTF-8?q?feat:=20ForbiddenMenu=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ForbiddenMenu.java | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 src/main/java/menu/ForbiddenMenu.java diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/ForbiddenMenu.java new file mode 100644 index 000000000..d8d92546e --- /dev/null +++ b/src/main/java/menu/ForbiddenMenu.java @@ -0,0 +1,8 @@ +package menu; + +import java.util.ArrayList; +import java.util.List; + +public class ForbiddenMenu { + List forbiddenMenus = new ArrayList<>(); +} From e250bc47187624112a41d16aed3ab35650f5c3c2 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:11:58 +0900 Subject: [PATCH 10/53] =?UTF-8?q?test:=20=EC=9E=85=EB=A0=A5=ED=95=9C=20?= =?UTF-8?q?=EA=B0=92=EC=97=90=20,=EB=A5=BC=20=ED=8F=AC=ED=95=A8=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EC=9E=88=EC=A7=80=20=EC=95=8A=EC=9C=BC=EB=A9=B4=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=EA=B0=80=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/InputValidatorTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/java/menu/InputValidatorTest.java diff --git a/src/test/java/menu/InputValidatorTest.java b/src/test/java/menu/InputValidatorTest.java new file mode 100644 index 000000000..597f4da3b --- /dev/null +++ b/src/test/java/menu/InputValidatorTest.java @@ -0,0 +1,18 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +class InputValidatorTest { + private static final String error = "[ERROR] "; + InputValidator inputValidator = new InputValidator(); + + @Test + @DisplayName("입력한 값에 ,를 포함하고 있지 않으면 에러가 발생한다.") + void validateContainComma(){ + assertThatThrownBy(() -> inputValidator.validateContainComma("토미/제임스/포코")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } +} From 25e6c483823181702da6a6b70cb4ba2e249d0c57 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:12:08 +0900 Subject: [PATCH 11/53] =?UTF-8?q?test:=20=EC=BD=94=EC=B9=98=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=EC=9D=B4=202~4=EA=B8=80=EC=9E=90=EA=B0=80=20=EC=95=84?= =?UTF-8?q?=EB=8B=88=EB=A9=B4=20=EC=97=90=EB=9F=AC=EA=B0=80=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 --- src/test/java/menu/CoachTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/java/menu/CoachTest.java diff --git a/src/test/java/menu/CoachTest.java b/src/test/java/menu/CoachTest.java new file mode 100644 index 000000000..8f4465c01 --- /dev/null +++ b/src/test/java/menu/CoachTest.java @@ -0,0 +1,18 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +class CoachTest { + + private static final String error = "[ERROR] "; + + @Test + @DisplayName("코치 이름이 2~4글자가 아니면 에러가 발생한다.") + void validateCoachNameLength(){ + assertThatThrownBy(() -> new Coach("준")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } +} From 4f1b0d75a1f68f6854151dcd38c2ecac3bf0c1fd Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:12:14 +0900 Subject: [PATCH 12/53] =?UTF-8?q?test:=20=EC=BD=94=EC=B9=98=EC=9D=98=20?= =?UTF-8?q?=EC=88=98=EA=B0=80=202~5=EB=AA=85=20=EC=82=AC=EC=9D=B4=EA=B0=80?= =?UTF-8?q?=20=EC=95=84=EB=8B=88=EB=9D=BC=EB=A9=B4=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EA=B0=80=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CoachesTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/java/menu/CoachesTest.java diff --git a/src/test/java/menu/CoachesTest.java b/src/test/java/menu/CoachesTest.java new file mode 100644 index 000000000..32da60099 --- /dev/null +++ b/src/test/java/menu/CoachesTest.java @@ -0,0 +1,18 @@ +package menu; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; + +public class CoachesTest { + + private static final String error = "[ERROR] "; + + @Test + @DisplayName("코치의 수가 2~5명 사이가 아니라면 에러가 발생한다.") + void validateCoachNumbers(){ + assertThatThrownBy(() -> new Coaches("토미")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } +} From 66fab2e8a3c449935ac31a25d5b826829b71165b Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:13:57 +0900 Subject: [PATCH 13/53] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=EA=B5=AC?= =?UTF-8?q?=ED=98=84/=EC=97=90=EB=9F=AC=EC=B2=98=EB=A6=AC=20=EC=B2=B4?= =?UTF-8?q?=ED=81=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index bee0f02d9..20df7dd3c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,12 +1,12 @@ ## 기능 구현 - InputView - - 코치의 이름을 입력받는다. - - 코치의 이름은 최소 2글자, 최대 4글자이다. + - [x] 코치의 이름을 입력받는다. + - [x] 코치의 이름은 최소 2글자, 최대 4글자이다. - 먹지 못하는 메뉴가 없으면 빈 값을 입력한다. - Coach - - 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. + - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. - 각 코치는 최소 0개, 최대 2개의 못 먹는 메뉴가 있다. - Category @@ -22,11 +22,12 @@ - 메뉴 추천 결과를 출력한다. - Coaches + - [x] 코치들을 저장 - 각 코치들의 못 먹는 메뉴를 저장한다. ## 에러 처리 - InputValidate - - 사용자가 잘못된 값을 입력할 경우 IllegalArgumentException를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. + - [x] 사용자가 잘못된 값을 입력할 경우 IllegalArgumentException를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. Exception이 아닌 IllegalArgumentException, IllegalStateException 등과 같은 명확한 유형을 처리한다. - - , 로 구분해서 입력한다. \ No newline at end of file + - [x] , 로 구분해서 입력한다. \ No newline at end of file From 358409742aa320ab7fbff8696ea4829b2531545a Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:45:13 +0900 Subject: [PATCH 14/53] =?UTF-8?q?feat:=20ErrorMessage=20COACH=5FFORBIDDEN?= =?UTF-8?q?=5FMENU=5FNUMBER=5FERROR=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ErrorMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/ErrorMessage.java index 0c40b476a..38353690b 100644 --- a/src/main/java/menu/ErrorMessage.java +++ b/src/main/java/menu/ErrorMessage.java @@ -3,7 +3,8 @@ public enum ErrorMessage { DIVISION_COMMA_ERROR("(, 로 구분)되지 않았습니다."), COACH_NAME_LENGTH_ERROR("코치 이름은 최소 2글자, 최대 4글자까지 입력가능 합니다."), - COACH_NUMBER_ERROR("코치는 최소 2명, 최대 5명자까지 입력가능 합니다."); + COACH_NUMBER_ERROR("코치는 최소 2명, 최대 5명자까지 입력가능 합니다."), + COACH_FORBIDDEN_MENU_NUMBER_ERROR("각 코치가 못 먹는 메뉴는 최소 0개, 최대 2개의 입니다."); private static final String error = "[ERROR] "; private final String message; From 40dd03671eb5ca80d6ac91bb1a7c53b3ac0e2e4e Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:45:38 +0900 Subject: [PATCH 15/53] =?UTF-8?q?feat:=20InputValidator=20validateForbidde?= =?UTF-8?q?nMenuNumber=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputValidator.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/menu/InputValidator.java b/src/main/java/menu/InputValidator.java index f5631ad8e..c2f0a672a 100644 --- a/src/main/java/menu/InputValidator.java +++ b/src/main/java/menu/InputValidator.java @@ -3,10 +3,18 @@ public class InputValidator { public static final String DIVISION = ","; + private static final int MAX_FORBIDDEN_MENU_SIZE = 2; - public void validateContainComma(String names){ - if (!names.contains(DIVISION)){ + public void validateContainComma(String names) { + if (!names.contains(DIVISION)) { throw new IllegalArgumentException(ErrorMessage.DIVISION_COMMA_ERROR.getMessage()); } } + + public void validateForbiddenMenuNumber(String menus) { + String[] menuNames = menus.split(DIVISION); + if (menuNames.length > MAX_FORBIDDEN_MENU_SIZE) { + throw new IllegalArgumentException(ErrorMessage.COACH_FORBIDDEN_MENU_NUMBER_ERROR.getMessage()); + } + } } From 9dd2f453d4b3dcbf954bf3c171a78a0d19274c58 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:46:00 +0900 Subject: [PATCH 16/53] =?UTF-8?q?feat:=20InputView=20inputForbiddenMenus?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/InputView.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java index ee40a72dd..07578a458 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/InputView.java @@ -18,7 +18,14 @@ public Coaches inputCoachName(){ }); } - + public String inputForbiddenMenus(Coach coach){ + return read(() -> { + outputView.printProgressCoachForbiddenMessage(coach.getName()); + String menus = scanner.next(); + inputValidator.validateForbiddenMenuNumber(menus); + return menus; + }); + } private T read(Supplier supplier){ while (true){ From d1c2237ea13389cce9bcf3e0c4c94d56f6783534 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:46:12 +0900 Subject: [PATCH 17/53] =?UTF-8?q?feat:=20OutputView=20printProgressCoachFo?= =?UTF-8?q?rbiddenMessage=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/OutputView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java index 4703adb2f..d01c6e94e 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/OutputView.java @@ -9,4 +9,8 @@ public void printErrorMessage(String error){ public void printProgressCoachNameMessage(){ System.out.println(ProgressMessage.INPUT_COACH_NAME); } + + public void printProgressCoachForbiddenMessage(String name){ + System.out.printf((ProgressMessage.INPUT_COACH_FORBIDDEN_MENU.getMessage()) + "%n", name); + } } From 74ac9d45e6973f03ac6911816c82137df59fb394 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:46:22 +0900 Subject: [PATCH 18/53] =?UTF-8?q?feat:=20ProgressMessage=20INPUT=5FCOACH?= =?UTF-8?q?=5FFORBIDDEN=5FMENU=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ProgressMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/ProgressMessage.java b/src/main/java/menu/ProgressMessage.java index d39e267eb..8fd897a0a 100644 --- a/src/main/java/menu/ProgressMessage.java +++ b/src/main/java/menu/ProgressMessage.java @@ -1,7 +1,8 @@ package menu; public enum ProgressMessage { - INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"); + INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), + INPUT_COACH_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."); private final String message; ProgressMessage(String message) { From a8ffda39904aad35350f948361841426c3aa5451 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:46:35 +0900 Subject: [PATCH 19/53] =?UTF-8?q?feat:=20Coach=20getName=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/Coach.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/menu/Coach.java b/src/main/java/menu/Coach.java index f8c8a2fa9..71c1b035b 100644 --- a/src/main/java/menu/Coach.java +++ b/src/main/java/menu/Coach.java @@ -18,4 +18,8 @@ private void validateCoachNameLength(String name) { throw new IllegalArgumentException(ErrorMessage.COACH_NAME_LENGTH_ERROR.getMessage()); } } + + public String getName() { + return name; + } } From 5a7ddcae02823370085e05058bf7b6c1e2822e67 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 15:46:55 +0900 Subject: [PATCH 20/53] =?UTF-8?q?test:=20=EC=BD=94=EC=B9=98=EB=93=A4?= =?UTF-8?q?=EC=9D=98=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D?= =?UTF-8?q?=EC=9D=B4=20=EC=B5=9C=EB=8C=80=202=EA=B0=80=EC=A7=80=EA=B0=80?= =?UTF-8?q?=20=EC=95=84=EB=8B=88=EB=9D=BC=EB=A9=B4=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=EA=B0=80=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/InputValidatorTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/test/java/menu/InputValidatorTest.java b/src/test/java/menu/InputValidatorTest.java index 597f4da3b..a507b2cab 100644 --- a/src/test/java/menu/InputValidatorTest.java +++ b/src/test/java/menu/InputValidatorTest.java @@ -15,4 +15,12 @@ void validateContainComma(){ .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(error); } + + @Test + @DisplayName("코치들의 못 먹는 음식이 최대 2가지가 아니라면 에러가 발생한다.") + void validateForbiddenMenuNumber(){ + assertThatThrownBy(() -> inputValidator.validateForbiddenMenuNumber("우동,스시,비빔밥")) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(error); + } } From 61278007c197dddf38b92f973f89a2da89d7b60a Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:01:06 +0900 Subject: [PATCH 21/53] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=EB=93=A4?= =?UTF-8?q?=EC=9D=98=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Coach.java | 4 ++++ src/main/java/menu/Coaches.java | 3 +++ src/main/java/menu/ForbiddenMenu.java | 13 ++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/Coach.java b/src/main/java/menu/Coach.java index 71c1b035b..184f14ceb 100644 --- a/src/main/java/menu/Coach.java +++ b/src/main/java/menu/Coach.java @@ -19,6 +19,10 @@ private void validateCoachNameLength(String name) { } } + public void addForbiddenMenu(String menu){ + forbiddenMenu.addForbiddenMenu(menu); + } + public String getName() { return name; } diff --git a/src/main/java/menu/Coaches.java b/src/main/java/menu/Coaches.java index 1f7287c6b..c7c1fcba3 100644 --- a/src/main/java/menu/Coaches.java +++ b/src/main/java/menu/Coaches.java @@ -32,4 +32,7 @@ private void addCoaches(String[] coachNames) { .collect(Collectors.toList())); } + public List getCoaches() { + return coaches; + } } diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/ForbiddenMenu.java index d8d92546e..789709d87 100644 --- a/src/main/java/menu/ForbiddenMenu.java +++ b/src/main/java/menu/ForbiddenMenu.java @@ -1,8 +1,19 @@ package menu; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; + +import static menu.InputValidator.DIVISION; public class ForbiddenMenu { - List forbiddenMenus = new ArrayList<>(); + + private final List forbiddenMenus = new ArrayList<>(); + + public void addForbiddenMenu(String menus){ + forbiddenMenus.addAll(Arrays.stream(menus.split(DIVISION)) + .map(String::trim) + .collect(Collectors.toList())); + } } From dfe84444428436d859370625a451267da8c9725e Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:01:18 +0900 Subject: [PATCH 22/53] =?UTF-8?q?feat:=20OutputView=20printStartMenuRecomm?= =?UTF-8?q?end=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/OutputView.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java index d01c6e94e..d48c835de 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/OutputView.java @@ -2,6 +2,10 @@ public class OutputView { + public void printStartMenuRecommend(){ + System.out.println(ProgressMessage.START_MENU_RECOMMEND); + } + public void printErrorMessage(String error){ System.out.println(error); } From b5c5d0dbc920149ce85b7820b0233fe4e7d700e4 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:01:26 +0900 Subject: [PATCH 23/53] =?UTF-8?q?feat:=20ProgressMessage=20START=5FMENU=5F?= =?UTF-8?q?RECOMMEND=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ProgressMessage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/menu/ProgressMessage.java b/src/main/java/menu/ProgressMessage.java index 8fd897a0a..ae4ac1dd4 100644 --- a/src/main/java/menu/ProgressMessage.java +++ b/src/main/java/menu/ProgressMessage.java @@ -1,6 +1,7 @@ package menu; public enum ProgressMessage { + START_MENU_RECOMMEND("점심 메뉴 추천을 시작합니다."), INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), INPUT_COACH_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."); private final String message; From 646de73a506dfb4b69fc92cd1859a52916a92363 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:01:44 +0900 Subject: [PATCH 24/53] =?UTF-8?q?feat:=20MenuController=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/MenuController.java | 27 ++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/menu/MenuController.java diff --git a/src/main/java/menu/MenuController.java b/src/main/java/menu/MenuController.java new file mode 100644 index 000000000..98d597c67 --- /dev/null +++ b/src/main/java/menu/MenuController.java @@ -0,0 +1,27 @@ +package menu; + +public class MenuController { + + private final MenuService menuService; + private final InputView inputView; + private final OutputView outputView; + + public MenuController() { + this.menuService = new MenuService(); + this.inputView = new InputView(); + this.outputView = new OutputView(); + } + + public void run(){ + outputView.printStartMenuRecommend(); + Coaches coaches = inputView.inputCoachName(); + addCoachesForbiddenMenu(coaches); + } + + private void addCoachesForbiddenMenu(Coaches coaches) { + for (Coach coach : coaches.getCoaches()){ + String menu = inputView.inputForbiddenMenus(coach); + coach.addForbiddenMenu(menu); + } + } +} From 85d3a87a3489c5b9e0a2839f7cb4f1531e9741f5 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:36:40 +0900 Subject: [PATCH 25/53] =?UTF-8?q?feat:=20Categories=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Categories.java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/main/java/menu/Categories.java diff --git a/src/main/java/menu/Categories.java b/src/main/java/menu/Categories.java new file mode 100644 index 000000000..dfbdd3d75 --- /dev/null +++ b/src/main/java/menu/Categories.java @@ -0,0 +1,26 @@ +package menu; + +import java.util.Arrays; + +public enum Categories { + JAPANESE(1, "일식"), + KOREAN(2, "한식"), + CHINESE(3, "중식"), + AISIAN(4, "아시안"), + WESTERN(5, "양식"); + + private final int number; + private final String type; + + Categories(int number, String type) { + this.number = number; + this.type = type; + } + + public static Categories findCategory(int number) { + return Arrays.stream(values()) + .filter(categories -> categories.number == number) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.CATEGORY_NUMBER_ERROR.getMessage())); + } +} From ec22fb85e452b534e894738a44e4ee198342e674 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:36:47 +0900 Subject: [PATCH 26/53] =?UTF-8?q?feat:=20Days=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Days.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/menu/Days.java diff --git a/src/main/java/menu/Days.java b/src/main/java/menu/Days.java new file mode 100644 index 000000000..babf21727 --- /dev/null +++ b/src/main/java/menu/Days.java @@ -0,0 +1,30 @@ +package menu; + +public enum Days { + MONDAY("월요일"), + TUESDAY("화요일"), + WEDNESDAY("수요일"), + THURSDAY("목요일"), + FRIDAY("금요일"); + + private static final String TAG = "구분"; + private final String day; + + Days(String day) { + this.day = day; + } + + public static String divisionDays(){ + StringBuilder sb = new StringBuilder(); + sb.append(ScreenElement.FIRST_ELEMENT).append(TAG); + for(Days days : Days.values()){ + sb.append(ScreenElement.MIDDLE_DIVISION).append(days.getDay()); + } + sb.append(ScreenElement.LAST_ELEMENT); + return sb.toString(); + } + + public String getDay() { + return day; + } +} From bb6429bca896f438c74d1eabddc2c1cc934a4ac1 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:37:02 +0900 Subject: [PATCH 27/53] =?UTF-8?q?feat:=20ErrorMessage=20CATEGORY=5FNUMBER?= =?UTF-8?q?=5FERROR=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ErrorMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/ErrorMessage.java index 38353690b..aaee924f2 100644 --- a/src/main/java/menu/ErrorMessage.java +++ b/src/main/java/menu/ErrorMessage.java @@ -4,7 +4,8 @@ public enum ErrorMessage { DIVISION_COMMA_ERROR("(, 로 구분)되지 않았습니다."), COACH_NAME_LENGTH_ERROR("코치 이름은 최소 2글자, 최대 4글자까지 입력가능 합니다."), COACH_NUMBER_ERROR("코치는 최소 2명, 최대 5명자까지 입력가능 합니다."), - COACH_FORBIDDEN_MENU_NUMBER_ERROR("각 코치가 못 먹는 메뉴는 최소 0개, 최대 2개의 입니다."); + COACH_FORBIDDEN_MENU_NUMBER_ERROR("각 코치가 못 먹는 메뉴는 최소 0개, 최대 2개의 입니다."), + CATEGORY_NUMBER_ERROR("존재하지 않는 카테고리 번호입니다."); private static final String error = "[ERROR] "; private final String message; From 9fa38e81b089a3f05b11ea2e38a6d46acf9db75a Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:37:16 +0900 Subject: [PATCH 28/53] =?UTF-8?q?feat:=20ScreenElement=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ScreenElement.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/menu/ScreenElement.java diff --git a/src/main/java/menu/ScreenElement.java b/src/main/java/menu/ScreenElement.java new file mode 100644 index 000000000..b0a3ee7f7 --- /dev/null +++ b/src/main/java/menu/ScreenElement.java @@ -0,0 +1,12 @@ +package menu; + +public enum ScreenElement { + FIRST_ELEMENT("[ "), + MIDDLE_DIVISION(" | "), + LAST_ELEMENT(" ]"); + private final String value; + + ScreenElement(String value) { + this.value = value; + } +} From 70c5a6ecf0140b6dd90fdd71403fa9de7ce5d395 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:37:36 +0900 Subject: [PATCH 29/53] =?UTF-8?q?feat:=20RecommendCategory=20randomCategor?= =?UTF-8?q?y=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/RecommendCategory.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/menu/RecommendCategory.java diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/RecommendCategory.java new file mode 100644 index 000000000..68fba3c12 --- /dev/null +++ b/src/main/java/menu/RecommendCategory.java @@ -0,0 +1,20 @@ +package menu; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.ArrayList; +import java.util.List; + +public class RecommendCategory { + + private static final int MIN_CATEGORY_NUM = 1; + private static final int MAX_CATEGORY_NUM = 5; + + List categories = new ArrayList<>(); + + + public void randomCategory(){ + Categories category = Categories.findCategory(Randoms.pickNumberInRange(MIN_CATEGORY_NUM, MAX_CATEGORY_NUM)); + categories.add(category); + } +} \ No newline at end of file From 2a54266e4f425c4727e0762fb8a3fb6786ad1a7e Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 16:46:12 +0900 Subject: [PATCH 30/53] =?UTF-8?q?refactor:=20RecommendCategory=20randomCat?= =?UTF-8?q?egory=20=EC=B5=9C=EB=8C=80=202=ED=9A=8C=20=EC=A1=B0=EA=B1=B4=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 --- src/main/java/menu/Categories.java | 3 ++- src/main/java/menu/RecommendCategory.java | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/menu/Categories.java b/src/main/java/menu/Categories.java index dfbdd3d75..285d8dd0b 100644 --- a/src/main/java/menu/Categories.java +++ b/src/main/java/menu/Categories.java @@ -17,9 +17,10 @@ public enum Categories { this.type = type; } - public static Categories findCategory(int number) { + public static String findCategory(int number) { return Arrays.stream(values()) .filter(categories -> categories.number == number) + .map(categories -> categories.type) .findFirst() .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.CATEGORY_NUMBER_ERROR.getMessage())); } diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/RecommendCategory.java index 68fba3c12..4cf9e0489 100644 --- a/src/main/java/menu/RecommendCategory.java +++ b/src/main/java/menu/RecommendCategory.java @@ -7,14 +7,24 @@ public class RecommendCategory { + private static final int MAX_DUPLICATE_COUNT = 2; private static final int MIN_CATEGORY_NUM = 1; private static final int MAX_CATEGORY_NUM = 5; - List categories = new ArrayList<>(); + List categories = new ArrayList<>(); public void randomCategory(){ - Categories category = Categories.findCategory(Randoms.pickNumberInRange(MIN_CATEGORY_NUM, MAX_CATEGORY_NUM)); - categories.add(category); + String category = Categories.findCategory(Randoms.pickNumberInRange(MIN_CATEGORY_NUM, MAX_CATEGORY_NUM)); + if (canAddCategory(category)){ + categories.add(category); + } + } + + private boolean canAddCategory(String newCategory) { + long count = categories.stream() + .filter(category -> category.equals(newCategory)) + .count(); + return count < MAX_DUPLICATE_COUNT; } } \ No newline at end of file From 5b03dc3cdcd732bb81f6a0d4f3ba53c2e5bf6121 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:40:30 +0900 Subject: [PATCH 31/53] =?UTF-8?q?feat:=20main=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Application.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6340b6f33..9820fd6c5 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -2,6 +2,7 @@ public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + MenuController menuController = new MenuController(); + menuController.run(); } } From 58016b275045efdbafb92de6a887c32b2dec1b61 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:41:00 +0900 Subject: [PATCH 32/53] =?UTF-8?q?feat:=20Coach=20isNotContainRecommendMenu?= =?UTF-8?q?InForbidden=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Coach.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/menu/Coach.java b/src/main/java/menu/Coach.java index 184f14ceb..563e428f4 100644 --- a/src/main/java/menu/Coach.java +++ b/src/main/java/menu/Coach.java @@ -23,6 +23,10 @@ public void addForbiddenMenu(String menu){ forbiddenMenu.addForbiddenMenu(menu); } + public boolean isNotContainRecommendMenuInForbidden(String menu){ + return forbiddenMenu.isNotContainRecommendMenuInForbidden(menu); + } + public String getName() { return name; } From f09205bf6a5d91b7bbbf99d3819d4db9da6d552a Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:41:14 +0900 Subject: [PATCH 33/53] =?UTF-8?q?feat:=20CoachMenus=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/CoachMenus.java | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/menu/CoachMenus.java diff --git a/src/main/java/menu/CoachMenus.java b/src/main/java/menu/CoachMenus.java new file mode 100644 index 000000000..4a0738dd3 --- /dev/null +++ b/src/main/java/menu/CoachMenus.java @@ -0,0 +1,47 @@ +package menu; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +public class CoachMenus { + private final RecommendMenu recommendMenu; + private final Map> coachMenus; + + public CoachMenus() { + this.recommendMenu = new RecommendMenu(); + this.coachMenus = new HashMap<>(); + } + + public void addCoachMenu(Coach coach, List menus){ + while (true){ + String menu = recommendMenu.getMenu(menus); + if (canRecommendMenu(coach, menu)){ + coachMenus.put(coach, List.of(menu)); + break; + } + } + } + + private boolean canRecommendMenu(Coach coach, String menu){ + return coach.isNotContainRecommendMenuInForbidden(menu) && isNotDuplicateMenu(coach, menu); + } + + private boolean isNotDuplicateMenu(Coach coach, String menu){ + List menus = coachMenus.getOrDefault(coach, new ArrayList<>()); + return !menus.contains(menu); + } + + public String showCoachMenus(){ + StringBuilder sb = new StringBuilder(); + for (Coach coach : coachMenus.keySet()){ + sb.append(ScreenElement.FIRST_ELEMENT).append(coach.getName()); + for (String menu : coachMenus.get(coach)){ + sb.append(ScreenElement.MIDDLE_DIVISION).append(menu); + } + sb.append(ScreenElement.LAST_ELEMENT).append("\n"); + } + sb.append("\n"); + return sb.toString(); + } +} From 1687622523f94b0a37469d09e8a3d45748bd0783 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:41:38 +0900 Subject: [PATCH 34/53] =?UTF-8?q?feat:=20ErrorMessage=20MENU=5FTYPE=5FERRO?= =?UTF-8?q?R=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ErrorMessage.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/ErrorMessage.java index aaee924f2..f66c78786 100644 --- a/src/main/java/menu/ErrorMessage.java +++ b/src/main/java/menu/ErrorMessage.java @@ -5,7 +5,8 @@ public enum ErrorMessage { COACH_NAME_LENGTH_ERROR("코치 이름은 최소 2글자, 최대 4글자까지 입력가능 합니다."), COACH_NUMBER_ERROR("코치는 최소 2명, 최대 5명자까지 입력가능 합니다."), COACH_FORBIDDEN_MENU_NUMBER_ERROR("각 코치가 못 먹는 메뉴는 최소 0개, 최대 2개의 입니다."), - CATEGORY_NUMBER_ERROR("존재하지 않는 카테고리 번호입니다."); + CATEGORY_NUMBER_ERROR("존재하지 않는 카테고리 번호입니다."), + MENU_TYPE_ERROR("존재하지 않는 음식종류 입니다."); private static final String error = "[ERROR] "; private final String message; From 459073c21289819eb379514902ae9688349b5f18 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:41:57 +0900 Subject: [PATCH 35/53] =?UTF-8?q?feat:=20ForbiddenMenu=20isNotContainRecom?= =?UTF-8?q?mendMenuInForbidden=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ForbiddenMenu.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/ForbiddenMenu.java index 789709d87..fbae06a32 100644 --- a/src/main/java/menu/ForbiddenMenu.java +++ b/src/main/java/menu/ForbiddenMenu.java @@ -16,4 +16,8 @@ public void addForbiddenMenu(String menus){ .map(String::trim) .collect(Collectors.toList())); } + + public boolean isNotContainRecommendMenuInForbidden(String menu){ + return !forbiddenMenus.contains(menu); + } } From 0555fbc8e35f01c7894b9fd38cb4a51de48ca437 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:42:19 +0900 Subject: [PATCH 36/53] =?UTF-8?q?feat:=20Menus=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Menus.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/menu/Menus.java diff --git a/src/main/java/menu/Menus.java b/src/main/java/menu/Menus.java new file mode 100644 index 000000000..bd76cbe3c --- /dev/null +++ b/src/main/java/menu/Menus.java @@ -0,0 +1,34 @@ +package menu; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +public enum Menus { + JAPANESE("일식", List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")), + KOREAN("한식", List.of("김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기", "떡볶이", "제육볶음")), + CHINES("중식", List.of("깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육", "토마토 달걀볶음", "고추잡채")), + ASIAN("아시안", List.of("팟타이", "카오 팟", "나시고렝", "파인애플 볶음밥", "쌀국수", "똠얌꿍", "반미", "월남쌈", "분짜")), + WESTERN("양식", List.of("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", "피자", "파니니")); + + private final String type; + private final List foods; + + Menus(String type, List foods) { + this.type = type; + this.foods = foods; + } + + public static List findFoods(String type) { + return Arrays.stream(Menus.values()) + .filter(isSameType(type)) + .map(menus -> menus.foods) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException(ErrorMessage.MENU_TYPE_ERROR.getMessage())); + } + + private static Predicate isSameType(String type) { + return menus -> menus.type.equals(type); + } + +} From bf98464b533ea4d818bd84f3d13ea50c60276da6 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:42:44 +0900 Subject: [PATCH 37/53] =?UTF-8?q?feat:=20MeProgressMessage=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/ProgressMessage.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/ProgressMessage.java b/src/main/java/menu/ProgressMessage.java index ae4ac1dd4..abd73b95f 100644 --- a/src/main/java/menu/ProgressMessage.java +++ b/src/main/java/menu/ProgressMessage.java @@ -3,7 +3,9 @@ public enum ProgressMessage { START_MENU_RECOMMEND("점심 메뉴 추천을 시작합니다."), INPUT_COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), - INPUT_COACH_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."); + INPUT_COACH_FORBIDDEN_MENU("%s(이)가 못 먹는 메뉴를 입력해 주세요."), + RECOMMEND_MENU_RESULT("메뉴 추천 결과입니다."), + FINISH_RECOMMEND("추천을 완료했습니다."); private final String message; ProgressMessage(String message) { @@ -13,4 +15,9 @@ public enum ProgressMessage { public String getMessage() { return message; } + + @Override + public String toString() { + return message; + } } From 1fd8036347da2867f4bff5499470e9ef794b16e3 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:43:03 +0900 Subject: [PATCH 38/53] =?UTF-8?q?feat:=20RecommendMenu=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/RecommendMenu.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/main/java/menu/RecommendMenu.java diff --git a/src/main/java/menu/RecommendMenu.java b/src/main/java/menu/RecommendMenu.java new file mode 100644 index 000000000..2c021ffac --- /dev/null +++ b/src/main/java/menu/RecommendMenu.java @@ -0,0 +1,11 @@ +package menu; +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.List; + +public class RecommendMenu { + + public String getMenu(List menus){ + return Randoms.shuffle(menus).get(0); + } +} From 3b939d9e5d77aa46229d4709a36d26979aac09e3 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:43:24 +0900 Subject: [PATCH 39/53] =?UTF-8?q?feat:=20OutputView=20printResultMenu=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 --- src/main/java/menu/OutputView.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/OutputView.java index d48c835de..ce2946dde 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/OutputView.java @@ -4,6 +4,7 @@ public class OutputView { public void printStartMenuRecommend(){ System.out.println(ProgressMessage.START_MENU_RECOMMEND); + printEnter(); } public void printErrorMessage(String error){ @@ -17,4 +18,15 @@ public void printProgressCoachNameMessage(){ public void printProgressCoachForbiddenMessage(String name){ System.out.printf((ProgressMessage.INPUT_COACH_FORBIDDEN_MENU.getMessage()) + "%n", name); } + + public void printResultMenu(String result) { + System.out.println(ProgressMessage.RECOMMEND_MENU_RESULT); + System.out.println(Days.showDivisionDays()); + System.out.println(result); + System.out.println(ProgressMessage.FINISH_RECOMMEND); + } + + public void printEnter(){ + System.out.println(); + } } From 60ddf2e449f7bdd920aaa1ddb7c7fe21e7e59354 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:43:52 +0900 Subject: [PATCH 40/53] =?UTF-8?q?feat:=20RecommendCategory=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/RecommendCategory.java | 26 ++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/RecommendCategory.java index 4cf9e0489..250f54bd7 100644 --- a/src/main/java/menu/RecommendCategory.java +++ b/src/main/java/menu/RecommendCategory.java @@ -10,15 +10,17 @@ public class RecommendCategory { private static final int MAX_DUPLICATE_COUNT = 2; private static final int MIN_CATEGORY_NUM = 1; private static final int MAX_CATEGORY_NUM = 5; + private static final String TAG = "카테고리"; + private final List categories = new ArrayList<>(); - List categories = new ArrayList<>(); - - public void randomCategory(){ + public boolean isAddingRandomCategory(){ String category = Categories.findCategory(Randoms.pickNumberInRange(MIN_CATEGORY_NUM, MAX_CATEGORY_NUM)); if (canAddCategory(category)){ categories.add(category); + return true; } + return false; } private boolean canAddCategory(String newCategory) { @@ -27,4 +29,22 @@ private boolean canAddCategory(String newCategory) { .count(); return count < MAX_DUPLICATE_COUNT; } + + public boolean canRecommendCategory(){ + return categories.size() < MAX_CATEGORY_NUM; + } + + public String getDaysCategory(){ + return categories.get(categories.size() - 1); + } + + public String showRecommendCategory(){ + StringBuilder sb = new StringBuilder(); + sb.append(ScreenElement.FIRST_ELEMENT).append(TAG); + for (String category : categories){ + sb.append(ScreenElement.MIDDLE_DIVISION).append(category); + } + sb.append(ScreenElement.LAST_ELEMENT); + return sb.toString(); + } } \ No newline at end of file From eb4ac64a4b8243d067b6e53ba12d290ac40f387c Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:44:19 +0900 Subject: [PATCH 41/53] =?UTF-8?q?feat:=20=EC=B6=9C=EB=A0=A5=ED=98=95?= =?UTF-8?q?=ED=83=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Days.java | 2 +- src/main/java/menu/InputView.java | 2 ++ src/main/java/menu/ScreenElement.java | 5 +++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/Days.java b/src/main/java/menu/Days.java index babf21727..67cc3c8c7 100644 --- a/src/main/java/menu/Days.java +++ b/src/main/java/menu/Days.java @@ -14,7 +14,7 @@ public enum Days { this.day = day; } - public static String divisionDays(){ + public static String showDivisionDays(){ StringBuilder sb = new StringBuilder(); sb.append(ScreenElement.FIRST_ELEMENT).append(TAG); for(Days days : Days.values()){ diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/InputView.java index 07578a458..117f91842 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/InputView.java @@ -13,6 +13,7 @@ public Coaches inputCoachName(){ return read(() -> { outputView.printProgressCoachNameMessage(); String names = scanner.next(); + outputView.printEnter(); inputValidator.validateContainComma(names); return new Coaches(names); }); @@ -22,6 +23,7 @@ public String inputForbiddenMenus(Coach coach){ return read(() -> { outputView.printProgressCoachForbiddenMessage(coach.getName()); String menus = scanner.next(); + outputView.printEnter(); inputValidator.validateForbiddenMenuNumber(menus); return menus; }); diff --git a/src/main/java/menu/ScreenElement.java b/src/main/java/menu/ScreenElement.java index b0a3ee7f7..daf040550 100644 --- a/src/main/java/menu/ScreenElement.java +++ b/src/main/java/menu/ScreenElement.java @@ -9,4 +9,9 @@ public enum ScreenElement { ScreenElement(String value) { this.value = value; } + + @Override + public String toString() { + return value; + } } From 07aa15fec8583a449cd2b69adc9ede2ff4b22417 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:44:58 +0900 Subject: [PATCH 42/53] =?UTF-8?q?feat:=20MenuService=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/MenuService.java | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/menu/MenuService.java diff --git a/src/main/java/menu/MenuService.java b/src/main/java/menu/MenuService.java new file mode 100644 index 000000000..f9bc95280 --- /dev/null +++ b/src/main/java/menu/MenuService.java @@ -0,0 +1,34 @@ +package menu; + +import java.util.List; + +public class MenuService { + + private final RecommendCategory recommendCategory; + private final CoachMenus coachMenus; + + public MenuService() { + this.recommendCategory = new RecommendCategory(); + this.coachMenus = new CoachMenus(); + } + + public void addRecommendMenu(Coaches coaches){ + if (recommendCategory.isAddingRandomCategory()){ + for (Coach coach : coaches.getCoaches()) { + String category = recommendCategory.getDaysCategory(); + List menus = Menus.findFoods(category); + coachMenus.addCoachMenu(coach, menus); + } + } + } + + public boolean isRecommending(){ + return recommendCategory.canRecommendCategory(); + } + + public String showMenuResult() { + return recommendCategory.showRecommendCategory() + + "\n" + + coachMenus.showCoachMenus(); + } +} From 134c5b030e66771c2fe23ee8483842bab7d35db5 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:45:15 +0900 Subject: [PATCH 43/53] =?UTF-8?q?feat:=20MenuController=20recommendMenu=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 --- src/main/java/menu/MenuController.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/menu/MenuController.java b/src/main/java/menu/MenuController.java index 98d597c67..f552f9f67 100644 --- a/src/main/java/menu/MenuController.java +++ b/src/main/java/menu/MenuController.java @@ -16,6 +16,8 @@ public void run(){ outputView.printStartMenuRecommend(); Coaches coaches = inputView.inputCoachName(); addCoachesForbiddenMenu(coaches); + recommendMenu(coaches); + outputView.printResultMenu(menuService.showMenuResult()); } private void addCoachesForbiddenMenu(Coaches coaches) { @@ -24,4 +26,10 @@ private void addCoachesForbiddenMenu(Coaches coaches) { coach.addForbiddenMenu(menu); } } + + private void recommendMenu(Coaches coaches){ + while (menuService.isRecommending()){ + menuService.addRecommendMenu(coaches); + } + } } From 60bf57eac905b997d4e0cbc508c3245dbd782ca4 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 20:53:28 +0900 Subject: [PATCH 44/53] =?UTF-8?q?refactor:=20CoachMenus=20addCoachMenu=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=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/menu/CoachMenus.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/CoachMenus.java b/src/main/java/menu/CoachMenus.java index 4a0738dd3..2be89823c 100644 --- a/src/main/java/menu/CoachMenus.java +++ b/src/main/java/menu/CoachMenus.java @@ -16,8 +16,10 @@ public CoachMenus() { public void addCoachMenu(Coach coach, List menus){ while (true){ String menu = recommendMenu.getMenu(menus); + List recommendMenus = coachMenus.getOrDefault(coach, new ArrayList<>()); if (canRecommendMenu(coach, menu)){ - coachMenus.put(coach, List.of(menu)); + recommendMenus.add(menu); + coachMenus.put(coach, recommendMenus); break; } } From 083f5e3924cb18406bb3ea2e17d104cd79095357 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 21:06:49 +0900 Subject: [PATCH 45/53] =?UTF-8?q?feat:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=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/Application.java | 6 ++++-- src/main/java/menu/RecommendMenu.java | 11 ---------- .../java/menu/{ => constants}/Categories.java | 2 +- src/main/java/menu/{ => constants}/Days.java | 6 +++--- .../menu/{ => constants}/ErrorMessage.java | 2 +- src/main/java/menu/{ => constants}/Menus.java | 2 +- .../menu/{ => constants}/ProgressMessage.java | 2 +- .../menu/{ => constants}/ScreenElement.java | 2 +- .../menu/{ => controller}/MenuController.java | 16 +++++++++----- src/main/java/menu/{ => domain}/Coach.java | 12 ++++++----- .../java/menu/{ => domain}/CoachMenus.java | 21 +++++++++++-------- src/main/java/menu/{ => domain}/Coaches.java | 8 ++++--- .../java/menu/{ => domain}/ForbiddenMenu.java | 8 +++---- .../menu/{ => domain}/RecommendCategory.java | 16 +++++++------- src/main/java/menu/domain/RecommendMenu.java | 12 +++++++++++ .../java/menu/{ => service}/MenuService.java | 14 +++++++++---- .../java/menu/{ => view}/InputValidator.java | 4 +++- src/main/java/menu/{ => view}/InputView.java | 15 +++++++------ src/main/java/menu/{ => view}/OutputView.java | 15 +++++++------ src/test/java/menu/CoachTest.java | 6 ++++-- src/test/java/menu/CoachesTest.java | 6 ++++-- src/test/java/menu/InputValidatorTest.java | 8 ++++--- 22 files changed, 116 insertions(+), 78 deletions(-) delete mode 100644 src/main/java/menu/RecommendMenu.java rename src/main/java/menu/{ => constants}/Categories.java (96%) rename src/main/java/menu/{ => constants}/Days.java (84%) rename src/main/java/menu/{ => constants}/ErrorMessage.java (97%) rename src/main/java/menu/{ => constants}/Menus.java (98%) rename src/main/java/menu/{ => constants}/ProgressMessage.java (96%) rename src/main/java/menu/{ => constants}/ScreenElement.java (92%) rename src/main/java/menu/{ => controller}/MenuController.java (70%) rename src/main/java/menu/{ => domain}/Coach.java (86%) rename src/main/java/menu/{ => domain}/CoachMenus.java (76%) rename src/main/java/menu/{ => domain}/Coaches.java (89%) rename src/main/java/menu/{ => domain}/ForbiddenMenu.java (79%) rename src/main/java/menu/{ => domain}/RecommendCategory.java (78%) create mode 100644 src/main/java/menu/domain/RecommendMenu.java rename src/main/java/menu/{ => service}/MenuService.java (71%) rename src/main/java/menu/{ => view}/InputValidator.java (91%) rename src/main/java/menu/{ => view}/InputView.java (77%) rename src/main/java/menu/{ => view}/OutputView.java (66%) diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 9820fd6c5..58518bccb 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -1,8 +1,10 @@ package menu; +import menu.controller.MenuController; + public class Application { public static void main(String[] args) { - MenuController menuController = new MenuController(); - menuController.run(); + MenuController menuController = new MenuController(); + menuController.run(); } } diff --git a/src/main/java/menu/RecommendMenu.java b/src/main/java/menu/RecommendMenu.java deleted file mode 100644 index 2c021ffac..000000000 --- a/src/main/java/menu/RecommendMenu.java +++ /dev/null @@ -1,11 +0,0 @@ -package menu; -import camp.nextstep.edu.missionutils.Randoms; - -import java.util.List; - -public class RecommendMenu { - - public String getMenu(List menus){ - return Randoms.shuffle(menus).get(0); - } -} diff --git a/src/main/java/menu/Categories.java b/src/main/java/menu/constants/Categories.java similarity index 96% rename from src/main/java/menu/Categories.java rename to src/main/java/menu/constants/Categories.java index 285d8dd0b..ee5c91f66 100644 --- a/src/main/java/menu/Categories.java +++ b/src/main/java/menu/constants/Categories.java @@ -1,4 +1,4 @@ -package menu; +package menu.constants; import java.util.Arrays; diff --git a/src/main/java/menu/Days.java b/src/main/java/menu/constants/Days.java similarity index 84% rename from src/main/java/menu/Days.java rename to src/main/java/menu/constants/Days.java index 67cc3c8c7..0b92ca2ee 100644 --- a/src/main/java/menu/Days.java +++ b/src/main/java/menu/constants/Days.java @@ -1,4 +1,4 @@ -package menu; +package menu.constants; public enum Days { MONDAY("월요일"), @@ -14,10 +14,10 @@ public enum Days { this.day = day; } - public static String showDivisionDays(){ + public static String showDivisionDays() { StringBuilder sb = new StringBuilder(); sb.append(ScreenElement.FIRST_ELEMENT).append(TAG); - for(Days days : Days.values()){ + for (Days days : Days.values()) { sb.append(ScreenElement.MIDDLE_DIVISION).append(days.getDay()); } sb.append(ScreenElement.LAST_ELEMENT); diff --git a/src/main/java/menu/ErrorMessage.java b/src/main/java/menu/constants/ErrorMessage.java similarity index 97% rename from src/main/java/menu/ErrorMessage.java rename to src/main/java/menu/constants/ErrorMessage.java index f66c78786..5694cde59 100644 --- a/src/main/java/menu/ErrorMessage.java +++ b/src/main/java/menu/constants/ErrorMessage.java @@ -1,4 +1,4 @@ -package menu; +package menu.constants; public enum ErrorMessage { DIVISION_COMMA_ERROR("(, 로 구분)되지 않았습니다."), diff --git a/src/main/java/menu/Menus.java b/src/main/java/menu/constants/Menus.java similarity index 98% rename from src/main/java/menu/Menus.java rename to src/main/java/menu/constants/Menus.java index bd76cbe3c..016a5864e 100644 --- a/src/main/java/menu/Menus.java +++ b/src/main/java/menu/constants/Menus.java @@ -1,4 +1,4 @@ -package menu; +package menu.constants; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/menu/ProgressMessage.java b/src/main/java/menu/constants/ProgressMessage.java similarity index 96% rename from src/main/java/menu/ProgressMessage.java rename to src/main/java/menu/constants/ProgressMessage.java index abd73b95f..5d50cbfe8 100644 --- a/src/main/java/menu/ProgressMessage.java +++ b/src/main/java/menu/constants/ProgressMessage.java @@ -1,4 +1,4 @@ -package menu; +package menu.constants; public enum ProgressMessage { START_MENU_RECOMMEND("점심 메뉴 추천을 시작합니다."), diff --git a/src/main/java/menu/ScreenElement.java b/src/main/java/menu/constants/ScreenElement.java similarity index 92% rename from src/main/java/menu/ScreenElement.java rename to src/main/java/menu/constants/ScreenElement.java index daf040550..5935d3a7c 100644 --- a/src/main/java/menu/ScreenElement.java +++ b/src/main/java/menu/constants/ScreenElement.java @@ -1,4 +1,4 @@ -package menu; +package menu.constants; public enum ScreenElement { FIRST_ELEMENT("[ "), diff --git a/src/main/java/menu/MenuController.java b/src/main/java/menu/controller/MenuController.java similarity index 70% rename from src/main/java/menu/MenuController.java rename to src/main/java/menu/controller/MenuController.java index f552f9f67..2389906dd 100644 --- a/src/main/java/menu/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,4 +1,10 @@ -package menu; +package menu.controller; + +import menu.domain.Coach; +import menu.domain.Coaches; +import menu.service.MenuService; +import menu.view.InputView; +import menu.view.OutputView; public class MenuController { @@ -12,7 +18,7 @@ public MenuController() { this.outputView = new OutputView(); } - public void run(){ + public void run() { outputView.printStartMenuRecommend(); Coaches coaches = inputView.inputCoachName(); addCoachesForbiddenMenu(coaches); @@ -21,14 +27,14 @@ public void run(){ } private void addCoachesForbiddenMenu(Coaches coaches) { - for (Coach coach : coaches.getCoaches()){ + for (Coach coach : coaches.getCoaches()) { String menu = inputView.inputForbiddenMenus(coach); coach.addForbiddenMenu(menu); } } - private void recommendMenu(Coaches coaches){ - while (menuService.isRecommending()){ + private void recommendMenu(Coaches coaches) { + while (menuService.isRecommending()) { menuService.addRecommendMenu(coaches); } } diff --git a/src/main/java/menu/Coach.java b/src/main/java/menu/domain/Coach.java similarity index 86% rename from src/main/java/menu/Coach.java rename to src/main/java/menu/domain/Coach.java index 563e428f4..0e7246d59 100644 --- a/src/main/java/menu/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -1,11 +1,13 @@ -package menu; +package menu.domain; + +import menu.constants.ErrorMessage; public class Coach { private static final int MIN_NAME_LENGTH = 2; private static final int MAX_NAME_LENGTH = 4; - private final String name; public final ForbiddenMenu forbiddenMenu; + private final String name; public Coach(String name) { validateCoachNameLength(name); @@ -14,16 +16,16 @@ public Coach(String name) { } private void validateCoachNameLength(String name) { - if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH){ + if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) { throw new IllegalArgumentException(ErrorMessage.COACH_NAME_LENGTH_ERROR.getMessage()); } } - public void addForbiddenMenu(String menu){ + public void addForbiddenMenu(String menu) { forbiddenMenu.addForbiddenMenu(menu); } - public boolean isNotContainRecommendMenuInForbidden(String menu){ + public boolean isNotContainRecommendMenuInForbidden(String menu) { return forbiddenMenu.isNotContainRecommendMenuInForbidden(menu); } diff --git a/src/main/java/menu/CoachMenus.java b/src/main/java/menu/domain/CoachMenus.java similarity index 76% rename from src/main/java/menu/CoachMenus.java rename to src/main/java/menu/domain/CoachMenus.java index 2be89823c..8e4073466 100644 --- a/src/main/java/menu/CoachMenus.java +++ b/src/main/java/menu/domain/CoachMenus.java @@ -1,9 +1,12 @@ -package menu; +package menu.domain; + +import menu.constants.ScreenElement; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + public class CoachMenus { private final RecommendMenu recommendMenu; private final Map> coachMenus; @@ -13,11 +16,11 @@ public CoachMenus() { this.coachMenus = new HashMap<>(); } - public void addCoachMenu(Coach coach, List menus){ - while (true){ + public void addCoachMenu(Coach coach, List menus) { + while (true) { String menu = recommendMenu.getMenu(menus); List recommendMenus = coachMenus.getOrDefault(coach, new ArrayList<>()); - if (canRecommendMenu(coach, menu)){ + if (canRecommendMenu(coach, menu)) { recommendMenus.add(menu); coachMenus.put(coach, recommendMenus); break; @@ -25,20 +28,20 @@ public void addCoachMenu(Coach coach, List menus){ } } - private boolean canRecommendMenu(Coach coach, String menu){ + private boolean canRecommendMenu(Coach coach, String menu) { return coach.isNotContainRecommendMenuInForbidden(menu) && isNotDuplicateMenu(coach, menu); } - private boolean isNotDuplicateMenu(Coach coach, String menu){ + private boolean isNotDuplicateMenu(Coach coach, String menu) { List menus = coachMenus.getOrDefault(coach, new ArrayList<>()); return !menus.contains(menu); } - public String showCoachMenus(){ + public String showCoachMenus() { StringBuilder sb = new StringBuilder(); - for (Coach coach : coachMenus.keySet()){ + for (Coach coach : coachMenus.keySet()) { sb.append(ScreenElement.FIRST_ELEMENT).append(coach.getName()); - for (String menu : coachMenus.get(coach)){ + for (String menu : coachMenus.get(coach)) { sb.append(ScreenElement.MIDDLE_DIVISION).append(menu); } sb.append(ScreenElement.LAST_ELEMENT).append("\n"); diff --git a/src/main/java/menu/Coaches.java b/src/main/java/menu/domain/Coaches.java similarity index 89% rename from src/main/java/menu/Coaches.java rename to src/main/java/menu/domain/Coaches.java index c7c1fcba3..ff3b17ee0 100644 --- a/src/main/java/menu/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -1,11 +1,13 @@ -package menu; +package menu.domain; + +import menu.constants.ErrorMessage; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import static menu.InputValidator.DIVISION; +import static menu.view.InputValidator.DIVISION; public class Coaches { @@ -20,7 +22,7 @@ public Coaches(String names) { } private void validateCoachNumber(int number) { - if (number < MIN_COACH_NUMBER || number > MAX_COACH_NUMBER){ + if (number < MIN_COACH_NUMBER || number > MAX_COACH_NUMBER) { throw new IllegalArgumentException(ErrorMessage.COACH_NUMBER_ERROR.getMessage()); } } diff --git a/src/main/java/menu/ForbiddenMenu.java b/src/main/java/menu/domain/ForbiddenMenu.java similarity index 79% rename from src/main/java/menu/ForbiddenMenu.java rename to src/main/java/menu/domain/ForbiddenMenu.java index fbae06a32..1df011aed 100644 --- a/src/main/java/menu/ForbiddenMenu.java +++ b/src/main/java/menu/domain/ForbiddenMenu.java @@ -1,23 +1,23 @@ -package menu; +package menu.domain; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import static menu.InputValidator.DIVISION; +import static menu.view.InputValidator.DIVISION; public class ForbiddenMenu { private final List forbiddenMenus = new ArrayList<>(); - public void addForbiddenMenu(String menus){ + public void addForbiddenMenu(String menus) { forbiddenMenus.addAll(Arrays.stream(menus.split(DIVISION)) .map(String::trim) .collect(Collectors.toList())); } - public boolean isNotContainRecommendMenuInForbidden(String menu){ + public boolean isNotContainRecommendMenuInForbidden(String menu) { return !forbiddenMenus.contains(menu); } } diff --git a/src/main/java/menu/RecommendCategory.java b/src/main/java/menu/domain/RecommendCategory.java similarity index 78% rename from src/main/java/menu/RecommendCategory.java rename to src/main/java/menu/domain/RecommendCategory.java index 250f54bd7..ff8d4e83f 100644 --- a/src/main/java/menu/RecommendCategory.java +++ b/src/main/java/menu/domain/RecommendCategory.java @@ -1,6 +1,8 @@ -package menu; +package menu.domain; import camp.nextstep.edu.missionutils.Randoms; +import menu.constants.Categories; +import menu.constants.ScreenElement; import java.util.ArrayList; import java.util.List; @@ -14,9 +16,9 @@ public class RecommendCategory { private final List categories = new ArrayList<>(); - public boolean isAddingRandomCategory(){ + public boolean isAddingRandomCategory() { String category = Categories.findCategory(Randoms.pickNumberInRange(MIN_CATEGORY_NUM, MAX_CATEGORY_NUM)); - if (canAddCategory(category)){ + if (canAddCategory(category)) { categories.add(category); return true; } @@ -30,18 +32,18 @@ private boolean canAddCategory(String newCategory) { return count < MAX_DUPLICATE_COUNT; } - public boolean canRecommendCategory(){ + public boolean canRecommendCategory() { return categories.size() < MAX_CATEGORY_NUM; } - public String getDaysCategory(){ + public String getDaysCategory() { return categories.get(categories.size() - 1); } - public String showRecommendCategory(){ + public String showRecommendCategory() { StringBuilder sb = new StringBuilder(); sb.append(ScreenElement.FIRST_ELEMENT).append(TAG); - for (String category : categories){ + for (String category : categories) { sb.append(ScreenElement.MIDDLE_DIVISION).append(category); } sb.append(ScreenElement.LAST_ELEMENT); diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java new file mode 100644 index 000000000..ea0d929cf --- /dev/null +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -0,0 +1,12 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.List; + +public class RecommendMenu { + + public String getMenu(List menus) { + return Randoms.shuffle(menus).get(0); + } +} diff --git a/src/main/java/menu/MenuService.java b/src/main/java/menu/service/MenuService.java similarity index 71% rename from src/main/java/menu/MenuService.java rename to src/main/java/menu/service/MenuService.java index f9bc95280..97be8606a 100644 --- a/src/main/java/menu/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -1,4 +1,10 @@ -package menu; +package menu.service; + +import menu.constants.Menus; +import menu.domain.Coach; +import menu.domain.CoachMenus; +import menu.domain.Coaches; +import menu.domain.RecommendCategory; import java.util.List; @@ -12,8 +18,8 @@ public MenuService() { this.coachMenus = new CoachMenus(); } - public void addRecommendMenu(Coaches coaches){ - if (recommendCategory.isAddingRandomCategory()){ + public void addRecommendMenu(Coaches coaches) { + if (recommendCategory.isAddingRandomCategory()) { for (Coach coach : coaches.getCoaches()) { String category = recommendCategory.getDaysCategory(); List menus = Menus.findFoods(category); @@ -22,7 +28,7 @@ public void addRecommendMenu(Coaches coaches){ } } - public boolean isRecommending(){ + public boolean isRecommending() { return recommendCategory.canRecommendCategory(); } diff --git a/src/main/java/menu/InputValidator.java b/src/main/java/menu/view/InputValidator.java similarity index 91% rename from src/main/java/menu/InputValidator.java rename to src/main/java/menu/view/InputValidator.java index c2f0a672a..4d3e2ad7e 100644 --- a/src/main/java/menu/InputValidator.java +++ b/src/main/java/menu/view/InputValidator.java @@ -1,4 +1,6 @@ -package menu; +package menu.view; + +import menu.constants.ErrorMessage; public class InputValidator { diff --git a/src/main/java/menu/InputView.java b/src/main/java/menu/view/InputView.java similarity index 77% rename from src/main/java/menu/InputView.java rename to src/main/java/menu/view/InputView.java index 117f91842..c6d8a23de 100644 --- a/src/main/java/menu/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -1,4 +1,7 @@ -package menu; +package menu.view; + +import menu.domain.Coach; +import menu.domain.Coaches; import java.util.Scanner; import java.util.function.Supplier; @@ -9,7 +12,7 @@ public class InputView { private final OutputView outputView = new OutputView(); private final Scanner scanner = new Scanner(System.in); - public Coaches inputCoachName(){ + public Coaches inputCoachName() { return read(() -> { outputView.printProgressCoachNameMessage(); String names = scanner.next(); @@ -19,7 +22,7 @@ public Coaches inputCoachName(){ }); } - public String inputForbiddenMenus(Coach coach){ + public String inputForbiddenMenus(Coach coach) { return read(() -> { outputView.printProgressCoachForbiddenMessage(coach.getName()); String menus = scanner.next(); @@ -29,11 +32,11 @@ public String inputForbiddenMenus(Coach coach){ }); } - private T read(Supplier supplier){ - while (true){ + private T read(Supplier supplier) { + while (true) { try { return supplier.get(); - } catch (IllegalArgumentException e){ + } catch (IllegalArgumentException e) { outputView.printErrorMessage(e.getMessage()); } } diff --git a/src/main/java/menu/OutputView.java b/src/main/java/menu/view/OutputView.java similarity index 66% rename from src/main/java/menu/OutputView.java rename to src/main/java/menu/view/OutputView.java index ce2946dde..590caa201 100644 --- a/src/main/java/menu/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -1,21 +1,24 @@ -package menu; +package menu.view; + +import menu.constants.Days; +import menu.constants.ProgressMessage; public class OutputView { - public void printStartMenuRecommend(){ + public void printStartMenuRecommend() { System.out.println(ProgressMessage.START_MENU_RECOMMEND); printEnter(); } - public void printErrorMessage(String error){ + public void printErrorMessage(String error) { System.out.println(error); } - public void printProgressCoachNameMessage(){ + public void printProgressCoachNameMessage() { System.out.println(ProgressMessage.INPUT_COACH_NAME); } - public void printProgressCoachForbiddenMessage(String name){ + public void printProgressCoachForbiddenMessage(String name) { System.out.printf((ProgressMessage.INPUT_COACH_FORBIDDEN_MENU.getMessage()) + "%n", name); } @@ -26,7 +29,7 @@ public void printResultMenu(String result) { System.out.println(ProgressMessage.FINISH_RECOMMEND); } - public void printEnter(){ + public void printEnter() { System.out.println(); } } diff --git a/src/test/java/menu/CoachTest.java b/src/test/java/menu/CoachTest.java index 8f4465c01..61a858076 100644 --- a/src/test/java/menu/CoachTest.java +++ b/src/test/java/menu/CoachTest.java @@ -1,8 +1,10 @@ package menu; +import menu.domain.Coach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; class CoachTest { @@ -10,7 +12,7 @@ class CoachTest { @Test @DisplayName("코치 이름이 2~4글자가 아니면 에러가 발생한다.") - void validateCoachNameLength(){ + void validateCoachNameLength() { assertThatThrownBy(() -> new Coach("준")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(error); diff --git a/src/test/java/menu/CoachesTest.java b/src/test/java/menu/CoachesTest.java index 32da60099..0a3779f4c 100644 --- a/src/test/java/menu/CoachesTest.java +++ b/src/test/java/menu/CoachesTest.java @@ -1,8 +1,10 @@ package menu; +import menu.domain.Coaches; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; public class CoachesTest { @@ -10,7 +12,7 @@ public class CoachesTest { @Test @DisplayName("코치의 수가 2~5명 사이가 아니라면 에러가 발생한다.") - void validateCoachNumbers(){ + void validateCoachNumbers() { assertThatThrownBy(() -> new Coaches("토미")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(error); diff --git a/src/test/java/menu/InputValidatorTest.java b/src/test/java/menu/InputValidatorTest.java index a507b2cab..19fdb5207 100644 --- a/src/test/java/menu/InputValidatorTest.java +++ b/src/test/java/menu/InputValidatorTest.java @@ -1,8 +1,10 @@ package menu; +import menu.view.InputValidator; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.*; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; class InputValidatorTest { private static final String error = "[ERROR] "; @@ -10,7 +12,7 @@ class InputValidatorTest { @Test @DisplayName("입력한 값에 ,를 포함하고 있지 않으면 에러가 발생한다.") - void validateContainComma(){ + void validateContainComma() { assertThatThrownBy(() -> inputValidator.validateContainComma("토미/제임스/포코")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(error); @@ -18,7 +20,7 @@ void validateContainComma(){ @Test @DisplayName("코치들의 못 먹는 음식이 최대 2가지가 아니라면 에러가 발생한다.") - void validateForbiddenMenuNumber(){ + void validateForbiddenMenuNumber() { assertThatThrownBy(() -> inputValidator.validateForbiddenMenuNumber("우동,스시,비빔밥")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(error); From 95c6387a98248ce9777b2e50faba8217bb4687af Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 21:41:23 +0900 Subject: [PATCH 46/53] =?UTF-8?q?refactor:=20=EC=8A=A4=ED=8A=B8=EB=A6=BC?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/menu/constants/ScreenElement.java | 4 ++++ .../java/menu/controller/MenuController.java | 6 +++--- src/main/java/menu/domain/Coach.java | 2 +- src/main/java/menu/domain/CoachMenus.java | 19 +++++++++---------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/main/java/menu/constants/ScreenElement.java b/src/main/java/menu/constants/ScreenElement.java index 5935d3a7c..a60fedfff 100644 --- a/src/main/java/menu/constants/ScreenElement.java +++ b/src/main/java/menu/constants/ScreenElement.java @@ -10,6 +10,10 @@ public enum ScreenElement { this.value = value; } + public String getValue() { + return value; + } + @Override public String toString() { return value; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 2389906dd..2acbbb99a 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,6 +1,5 @@ package menu.controller; -import menu.domain.Coach; import menu.domain.Coaches; import menu.service.MenuService; import menu.view.InputView; @@ -22,15 +21,16 @@ public void run() { outputView.printStartMenuRecommend(); Coaches coaches = inputView.inputCoachName(); addCoachesForbiddenMenu(coaches); + recommendMenu(coaches); outputView.printResultMenu(menuService.showMenuResult()); } private void addCoachesForbiddenMenu(Coaches coaches) { - for (Coach coach : coaches.getCoaches()) { + coaches.getCoaches().forEach(coach -> { String menu = inputView.inputForbiddenMenus(coach); coach.addForbiddenMenu(menu); - } + }); } private void recommendMenu(Coaches coaches) { diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 0e7246d59..004dab282 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -6,7 +6,7 @@ public class Coach { private static final int MIN_NAME_LENGTH = 2; private static final int MAX_NAME_LENGTH = 4; - public final ForbiddenMenu forbiddenMenu; + private final ForbiddenMenu forbiddenMenu; private final String name; public Coach(String name) { diff --git a/src/main/java/menu/domain/CoachMenus.java b/src/main/java/menu/domain/CoachMenus.java index 8e4073466..a98895a66 100644 --- a/src/main/java/menu/domain/CoachMenus.java +++ b/src/main/java/menu/domain/CoachMenus.java @@ -6,6 +6,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; public class CoachMenus { private final RecommendMenu recommendMenu; @@ -38,15 +39,13 @@ private boolean isNotDuplicateMenu(Coach coach, String menu) { } public String showCoachMenus() { - StringBuilder sb = new StringBuilder(); - for (Coach coach : coachMenus.keySet()) { - sb.append(ScreenElement.FIRST_ELEMENT).append(coach.getName()); - for (String menu : coachMenus.get(coach)) { - sb.append(ScreenElement.MIDDLE_DIVISION).append(menu); - } - sb.append(ScreenElement.LAST_ELEMENT).append("\n"); - } - sb.append("\n"); - return sb.toString(); + return coachMenus.keySet().stream() + .map(coach -> { + String menus = coachMenus.get(coach).stream() + .collect(Collectors.joining(ScreenElement.MIDDLE_DIVISION.getValue())); + return ScreenElement.FIRST_ELEMENT + coach.getName() + + ScreenElement.MIDDLE_DIVISION + menus + ScreenElement.LAST_ELEMENT; + }) + .collect(Collectors.joining("\n")) + "\n"; } } From 0e65f418674cead54f92830a9cd2ed113b88c265 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 22:00:07 +0900 Subject: [PATCH 47/53] =?UTF-8?q?test:=20=EC=88=AB=EC=9E=90=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EB=8A=94=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=B0=BE=EB=8A=94=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoriesTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/java/menu/CategoriesTest.java diff --git a/src/test/java/menu/CategoriesTest.java b/src/test/java/menu/CategoriesTest.java new file mode 100644 index 000000000..2858cc68c --- /dev/null +++ b/src/test/java/menu/CategoriesTest.java @@ -0,0 +1,16 @@ +package menu; + +import menu.constants.Categories; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.*; +class CategoriesTest { + + @Test + @DisplayName("숫자에 맞는 카테고리를 찾는지 확인한다.") + void findCategoryByNumber(){ + String category = Categories.findCategory(1); + assertThat(category).isEqualTo("일식"); + } + +} From cdd14542253952e0da1009d044736ac786e7f8ce Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 22:03:04 +0900 Subject: [PATCH 48/53] =?UTF-8?q?test:=20=EC=9A=94=EC=9D=BC=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EA=B2=8C=20=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/DaysTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/test/java/menu/DaysTest.java diff --git a/src/test/java/menu/DaysTest.java b/src/test/java/menu/DaysTest.java new file mode 100644 index 000000000..0f2700b7e --- /dev/null +++ b/src/test/java/menu/DaysTest.java @@ -0,0 +1,16 @@ +package menu; + +import menu.constants.Days; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +class DaysTest { + + @Test + @DisplayName("요일에 맞게 출력하는지 확인한다.") + void showDivisionDays(){ + String days = Days.showDivisionDays(); + assertThat(days).isEqualTo("[ 구분 | 월요일 | 화요일 | 수요일 | 목요일 | 금요일 ]"); + } +} From c494f453bdb959d301ddf9a753c23f27e6c46a47 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 22:05:57 +0900 Subject: [PATCH 49/53] =?UTF-8?q?test:=20=ED=83=80=EC=9E=85=EC=97=90=20?= =?UTF-8?q?=EB=A7=9E=EB=8A=94=20=EC=9D=8C=EC=8B=9D=20=EC=A2=85=EB=A5=98?= =?UTF-8?q?=EB=93=A4=EC=9D=84=20=EC=B0=BE=EC=9D=84=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/MenusTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/java/menu/MenusTest.java diff --git a/src/test/java/menu/MenusTest.java b/src/test/java/menu/MenusTest.java new file mode 100644 index 000000000..d1cb5538f --- /dev/null +++ b/src/test/java/menu/MenusTest.java @@ -0,0 +1,19 @@ +package menu; + +import menu.constants.Menus; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.*; +public class MenusTest { + + @Test + @DisplayName("타입에 맞는 음식 종류들을 찾을 수 있다.") + void findMenusByType(){ + List menus = Menus.findFoods("일식"); + assertThat(menus).isEqualTo(List.of("규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼")); + } + +} From 4ae70e5a24a1ecdcb17483c0021f6298e1abe812 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 22:14:25 +0900 Subject: [PATCH 50/53] =?UTF-8?q?test:=20=EC=BD=94=EC=B9=98=EB=93=A4?= =?UTF-8?q?=EC=9D=B4=20=EC=A0=80=EC=9E=A5=EC=9D=B4=20=EB=90=98=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CoachesTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/java/menu/CoachesTest.java b/src/test/java/menu/CoachesTest.java index 0a3779f4c..7b0f65a79 100644 --- a/src/test/java/menu/CoachesTest.java +++ b/src/test/java/menu/CoachesTest.java @@ -1,10 +1,14 @@ package menu; +import menu.domain.Coach; import menu.domain.Coaches; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.util.List; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.*; public class CoachesTest { @@ -17,4 +21,15 @@ void validateCoachNumbers() { .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining(error); } + + @Test + @DisplayName("코치들이 저장이 되는지 확인한다.") + void saveCoaches() { + Coaches coaches = new Coaches("토미,제임스,포코"); + + List getCoach = coaches.getCoaches(); + + List names = getCoach.stream().map(Coach::getName).collect(Collectors.toList()); + assertThat(names).contains("토미", "제임스", "포코"); + } } From 411e61445a7c324b01ba28dd10d3166e8bf6d61b Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 22:17:55 +0900 Subject: [PATCH 51/53] =?UTF-8?q?test:=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20?= =?UTF-8?q?=EC=9D=8C=EC=8B=9D=EC=9D=84=20=EC=A0=80=EC=9E=A5=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EC=B6=94=EC=B2=9C=20=EC=9D=8C=EC=8B=9D=EC=9D=B4=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=EB=90=98=EC=A7=80=20=EC=95=8A=EC=9C=BC?= =?UTF-8?q?=EB=A9=B4=20true=EB=A5=BC=20=EB=B0=98=ED=99=98=ED=95=9C?= =?UTF-8?q?=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/ForbiddenMenuTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/test/java/menu/ForbiddenMenuTest.java diff --git a/src/test/java/menu/ForbiddenMenuTest.java b/src/test/java/menu/ForbiddenMenuTest.java new file mode 100644 index 000000000..43d3e43b5 --- /dev/null +++ b/src/test/java/menu/ForbiddenMenuTest.java @@ -0,0 +1,19 @@ +package menu; +import menu.domain.ForbiddenMenu; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +class ForbiddenMenuTest { + ForbiddenMenu forbiddenMenu = new ForbiddenMenu(); + @Test + @DisplayName("못 먹는 음식을 저장하고 추천 음식이 포함되지 않으면 true를 반환한다.") + void saveForbiddenMenuAndCheckDuplicate(){ + forbiddenMenu.addForbiddenMenu("우동,스시"); + + boolean isNotContain = forbiddenMenu.isNotContainRecommendMenuInForbidden("비빔밥"); + + assertThat(isNotContain).isTrue(); + } + +} From 41a1467b65cc9a595e073d62105490b72e44944f Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 22:24:58 +0900 Subject: [PATCH 52/53] =?UTF-8?q?test:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EA=B0=80=20=EC=B5=9C=EB=8C=80=202=EB=B2=88=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=EB=90=98=EC=A7=80=20=EC=95=8A=EC=95=98?= =?UTF-8?q?=EC=9C=BC=EB=A9=B4=20=EC=B6=94=EA=B0=80=EB=90=98=EC=96=B4=20?= =?UTF-8?q?=EB=A9=94=EB=89=B4=EB=A5=BC=20=EC=B6=94=EC=B2=9C=ED=95=A0=20?= =?UTF-8?q?=EC=88=98=20=EC=9E=88=EB=8B=A4.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/RecommendCategoryTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/java/menu/RecommendCategoryTest.java diff --git a/src/test/java/menu/RecommendCategoryTest.java b/src/test/java/menu/RecommendCategoryTest.java new file mode 100644 index 000000000..6156968f9 --- /dev/null +++ b/src/test/java/menu/RecommendCategoryTest.java @@ -0,0 +1,20 @@ +package menu; +import menu.domain.RecommendCategory; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +class RecommendCategoryTest { + + @Test + @DisplayName("카테고리가 최대 2번 중복되지 않았으면 추가되어 메뉴를 추천할 수 있다.") + void saveCategoryReturnTrue(){ + RecommendCategory recommendCategory = new RecommendCategory(); + + boolean canAdd = recommendCategory.isAddingRandomCategory(); + boolean canRecommend = recommendCategory.canRecommendCategory(); + + assertThat(canAdd).isTrue(); + assertThat(canRecommend).isTrue(); + } +} From d88f9247aa691741a33167a2e188993b4b3891e3 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Sun, 17 Sep 2023 22:37:15 +0900 Subject: [PATCH 53/53] =?UTF-8?q?docs:=20=EB=A6=AC=EB=93=9C=EB=AF=B8=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/docs/README.md b/docs/README.md index 20df7dd3c..5266eaee9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,31 +3,43 @@ - InputView - [x] 코치의 이름을 입력받는다. - [x] 코치의 이름은 최소 2글자, 최대 4글자이다. - - 먹지 못하는 메뉴가 없으면 빈 값을 입력한다. + - [x] 먹지 못하는 메뉴가 없으면 빈 값을 입력한다. - Coach + - [x] 코치 이름의 길이는 2~4글자 사이다. + - [x] 각 코치는 최소 0개, 최대 2개의 못 먹는 메뉴가 있다. + +- Coaches - [x] 코치는 최소 2명, 최대 5명까지 식사를 함께 한다. - - 각 코치는 최소 0개, 최대 2개의 못 먹는 메뉴가 있다. + - 각 코치들의 못 먹는 메뉴를 저장한다. + +- CoachMenus + - [x] 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. - Category - - 1이면 일식, 2면 한식, 3이면 중식, 4면 아시안, 5면 양식을 추천한다. - - 한 주에 같은 카테고리는 최대 2회까지만 고를 수 있다. + - [x] 1이면 일식, 2면 한식, 3이면 중식, 4면 아시안, 5면 양식을 추천한다. + +- ForbiddenMenu + - [x] 못 먹는 음식을 저장한다. -- Menu - - 카테고리에 맞는 메뉴를 생성 - - 카테고리에 포함되는 메뉴 목록을 List 형태로 준비한다. - - 각 코치에게 한 주에 중복되지 않는 메뉴를 추천해야 한다. +- RecommendCategory + - [x] 한 주에 같은 카테고리는 최대 2회까지만 고를 수 있다. + +- RecommendMenu + - [x] 카테고리에 맞는 메뉴를 생성한다, + +- Menus + - [x] 카테고리에 포함되는 메뉴 목록을 List 형태로 반환한다. - OutputView - 메뉴 추천 결과를 출력한다. -- Coaches - - [x] 코치들을 저장 - - 각 코치들의 못 먹는 메뉴를 저장한다. + ## 에러 처리 - InputValidate - [x] 사용자가 잘못된 값을 입력할 경우 IllegalArgumentException를 발생시키고, "[ERROR]"로 시작하는 에러 메시지를 출력 후 그 부분부터 입력을 다시 받는다. Exception이 아닌 IllegalArgumentException, IllegalStateException 등과 같은 명확한 유형을 처리한다. - - [x] , 로 구분해서 입력한다. \ No newline at end of file + - [x] , 로 구분해서 입력한다. + - [x] 못 먹는 음식은 코치별 0~2개 이다. \ No newline at end of file