From a9db0f3fac95cc003dda3f5bd5d4a03fdf1431ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Wed, 23 Aug 2023 21:19:36 +0900 Subject: [PATCH 01/35] =?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 | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29bb..4b037f12e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,25 @@ +### 구현 기능 목록 + +**출력** +- 실행 문구 +- 이름 입력 안내 +- 못 먹는 음식 입력 안내 +- 메뉴 추천 결과 +- 추천 완료 문구 + +**입력** +- 코치 이름 +- 못 먹는 음식 + +**카테고리 추천** +- 랜덤으로 카테고리를 뽑는다. +- 3번 이상 먹은 카테고리일 경우 다시 뽑는다. + +**음식 추천** +- 카테고리의 음식 중 하나를 뽑는다. +- 코치가 못 먹는 음식일 경우 다시 뽑는다. +- 이미 먹은 음식일 경우 다시 뽑는다. + +**오류를 발생** +- 코치의 이름이 2~4글자 이상인 경우 +- `,`로 나누어져 있지 않은 경우 \ No newline at end of file From 6707bda6764ce7cc33b6bc32fd6c6bd520cf316d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 00:55:49 +0900 Subject: [PATCH 02/35] =?UTF-8?q?feat(OutputView):=20=EC=8B=A4=ED=96=89=20?= =?UTF-8?q?=EB=AC=B8=EA=B5=AC=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 | 30 +++++++++---------- src/main/java/menu/Application.java | 5 +++- .../java/menu/constant/OutputMessage.java | 17 +++++++++++ .../java/menu/controller/MenuController.java | 12 ++++++++ src/main/java/menu/view/OutputView.java | 15 ++++++++++ 5 files changed, 63 insertions(+), 16 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 4b037f12e..4414b82a8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,25 +1,25 @@ ### 구현 기능 목록 **출력** -- 실행 문구 -- 이름 입력 안내 -- 못 먹는 음식 입력 안내 -- 메뉴 추천 결과 -- 추천 완료 문구 +- [x] 실행 문구 +- [ ] 이름 입력 안내 +- [ ] 못 먹는 음식 입력 안내 +- [ ] 메뉴 추천 결과 +- [ ] 추천 완료 문구 **입력** -- 코치 이름 -- 못 먹는 음식 +- [ ] 코치 이름 +- [ ] 못 먹는 음식 **카테고리 추천** -- 랜덤으로 카테고리를 뽑는다. -- 3번 이상 먹은 카테고리일 경우 다시 뽑는다. +- [ ] 랜덤으로 카테고리를 뽑는다. +- [ ] 3번 이상 먹은 카테고리일 경우 다시 뽑는다. **음식 추천** -- 카테고리의 음식 중 하나를 뽑는다. -- 코치가 못 먹는 음식일 경우 다시 뽑는다. -- 이미 먹은 음식일 경우 다시 뽑는다. +- [ ] 카테고리의 음식 중 하나를 뽑는다. +- [ ] 코치가 못 먹는 음식일 경우 다시 뽑는다. +- [ ] 이미 먹은 음식일 경우 다시 뽑는다. -**오류를 발생** -- 코치의 이름이 2~4글자 이상인 경우 -- `,`로 나누어져 있지 않은 경우 \ No newline at end of file +**오류 발생** +- [ ] 코치의 이름이 2~4글자 이상인 경우 +- [ ] `,`로 나누어져 있지 않은 경우 \ No newline at end of file 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..421d7e027 --- /dev/null +++ b/src/main/java/menu/constant/OutputMessage.java @@ -0,0 +1,17 @@ +package menu.constant; + +public enum OutputMessage { + + START_MESSAGE("점심 메뉴 추천을 시작합니다."); + + private final String message; + + OutputMessage(String message) { + this.message = message; + } + + @Override + public String toString() { + return this.message; + } +} \ No newline at end of file diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java new file mode 100644 index 000000000..0107a9b1c --- /dev/null +++ b/src/main/java/menu/controller/MenuController.java @@ -0,0 +1,12 @@ +package menu.controller; + +import menu.view.OutputView; + +public class MenuController { + + private final OutputView outputView = new OutputView(); + + public void start() { + outputView.printStartMessage(); + } +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java new file mode 100644 index 000000000..9407357ee --- /dev/null +++ b/src/main/java/menu/view/OutputView.java @@ -0,0 +1,15 @@ +package menu.view; + +import menu.constant.OutputMessage; + +public class OutputView { + + public void printStartMessage() { + System.out.println(OutputMessage.START_MESSAGE); + printNewLine(); + } + + private void printNewLine() { + System.out.println(); + } +} From 42b65d32f87f07e3b0e981ebe5bb8c2132a6a0cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 00:58:36 +0900 Subject: [PATCH 03/35] =?UTF-8?q?feat(OutputView):=20=EC=BD=94=EC=B9=98=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=9E=85=EB=A0=A5=20=EC=95=88=EB=82=B4=20?= =?UTF-8?q?=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/OutputMessage.java | 3 ++- src/main/java/menu/controller/MenuController.java | 1 + src/main/java/menu/view/OutputView.java | 4 ++++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 4414b82a8..c787dc9d9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2,7 +2,7 @@ **출력** - [x] 실행 문구 -- [ ] 이름 입력 안내 +- [x] 이름 입력 안내 - [ ] 못 먹는 음식 입력 안내 - [ ] 메뉴 추천 결과 - [ ] 추천 완료 문구 diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index 421d7e027..e69eaf7fc 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_MESSAGE("점심 메뉴 추천을 시작합니다."); + START_MESSAGE("점심 메뉴 추천을 시작합니다."), + COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"); private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 0107a9b1c..52da3a7d3 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -8,5 +8,6 @@ public class MenuController { public void start() { outputView.printStartMessage(); + outputView.printNameMessage(); } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 9407357ee..0a62292c4 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -9,6 +9,10 @@ public void printStartMessage() { printNewLine(); } + public void printNameMessage() { + System.out.println(OutputMessage.COACH_NAME); + } + private void printNewLine() { System.out.println(); } From 6cd6dee79cdab847d8bdd09d8fa63581a00949bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 01:07:17 +0900 Subject: [PATCH 04/35] =?UTF-8?q?feat(InputView):=20=EC=BD=94=EC=B9=98=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=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 +- .../java/menu/controller/MenuController.java | 3 +++ src/main/java/menu/view/InputView.java | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/main/java/menu/view/InputView.java diff --git a/docs/README.md b/docs/README.md index c787dc9d9..771846940 100644 --- a/docs/README.md +++ b/docs/README.md @@ -8,7 +8,7 @@ - [ ] 추천 완료 문구 **입력** -- [ ] 코치 이름 +- [x] 코치 이름 - [ ] 못 먹는 음식 **카테고리 추천** diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 52da3a7d3..b02174475 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,13 +1,16 @@ package menu.controller; +import menu.view.InputView; import menu.view.OutputView; public class MenuController { private final OutputView outputView = new OutputView(); + private final InputView inputView = new InputView(); public void start() { outputView.printStartMessage(); outputView.printNameMessage(); + 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()); + } +} From 07fef5f421a91fa62d8ab3370d277d77f90e1899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 01:14:19 +0900 Subject: [PATCH 05/35] =?UTF-8?q?feat(OutputView):=20=EB=AA=BB=20=EB=A8=B9?= =?UTF-8?q?=EB=8A=94=20=EC=9D=8C=EC=8B=9D=20=EC=9E=85=EB=A0=A5=20=EC=95=88?= =?UTF-8?q?=EB=82=B4=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/OutputMessage.java | 3 ++- src/main/java/menu/controller/MenuController.java | 5 ++++- src/main/java/menu/view/OutputView.java | 5 +++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index 771846940..8e52c6779 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,7 +3,7 @@ **출력** - [x] 실행 문구 - [x] 이름 입력 안내 -- [ ] 못 먹는 음식 입력 안내 +- [x] 못 먹는 음식 입력 안내 - [ ] 메뉴 추천 결과 - [ ] 추천 완료 문구 diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index e69eaf7fc..3670e1ad4 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_MESSAGE("점심 메뉴 추천을 시작합니다."), - COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"); + COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), + EXCLUDED_FOOD("%s(이)가 못 먹는 메뉴를 입력해 주세요.\n"); private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index b02174475..2b86dd2fb 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -3,6 +3,8 @@ import menu.view.InputView; import menu.view.OutputView; +import java.util.List; + public class MenuController { private final OutputView outputView = new OutputView(); @@ -11,6 +13,7 @@ public class MenuController { public void start() { outputView.printStartMessage(); outputView.printNameMessage(); - inputView.readNames(); + List coaches = inputView.readNames(); + coaches.forEach(outputView::printExcludedFood); } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 0a62292c4..d64224e90 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -13,6 +13,11 @@ public void printNameMessage() { System.out.println(OutputMessage.COACH_NAME); } + public void printExcludedFood(String name) { + System.out.printf(OutputMessage.EXCLUDED_FOOD.toString(), name); + + } + private void printNewLine() { System.out.println(); } From 2112d1f08d3a9f856beb2125f45655b3d13f7f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 01:48:08 +0900 Subject: [PATCH 06/35] =?UTF-8?q?feat(InputView):=20=EB=AA=BB=20=EB=A8=B9?= =?UTF-8?q?=EB=8A=94=20=EC=9D=8C=EC=8B=9D=20=EC=9E=85=EB=A0=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/controller/MenuController.java | 5 ++++- src/main/java/menu/view/InputView.java | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 8e52c6779..187894a99 100644 --- a/docs/README.md +++ b/docs/README.md @@ -9,7 +9,7 @@ **입력** - [x] 코치 이름 -- [ ] 못 먹는 음식 +- [x] 못 먹는 음식 **카테고리 추천** - [ ] 랜덤으로 카테고리를 뽑는다. diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 2b86dd2fb..3fb6bb356 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -14,6 +14,9 @@ public void start() { outputView.printStartMessage(); outputView.printNameMessage(); List coaches = inputView.readNames(); - coaches.forEach(outputView::printExcludedFood); + coaches.forEach(name -> { + outputView.printExcludedFood(name); + inputView.readExcludedFood(); + }); } } diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index dda57bdc6..85e40ca69 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -13,4 +13,10 @@ public List readNames() { return Stream.of(names.split(",")) .collect(Collectors.toList()); } + + public List readExcludedFood() { + String foods = Console.readLine(); + return Stream.of(foods.split(",")) + .collect(Collectors.toList()); + } } From 178222bbfa156a75b454c3f15b4e7936f66db871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 02:08:36 +0900 Subject: [PATCH 07/35] =?UTF-8?q?feat(Coaches):=20=EC=BD=94=EC=B9=98=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84,=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20?= =?UTF-8?q?=EC=9D=8C=EC=8B=9D=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/MenuController.java | 4 +++- src/main/java/menu/domain/Coach.java | 15 +++++++++++++++ src/main/java/menu/domain/Coaches.java | 13 +++++++++++++ src/main/java/menu/service/MemberService.java | 14 ++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/main/java/menu/domain/Coach.java create mode 100644 src/main/java/menu/domain/Coaches.java create mode 100644 src/main/java/menu/service/MemberService.java diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 3fb6bb356..29ee2b983 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,5 +1,6 @@ package menu.controller; +import menu.service.MemberService; import menu.view.InputView; import menu.view.OutputView; @@ -9,6 +10,7 @@ public class MenuController { private final OutputView outputView = new OutputView(); private final InputView inputView = new InputView(); + private final MemberService memberService = new MemberService(); public void start() { outputView.printStartMessage(); @@ -16,7 +18,7 @@ public void start() { List coaches = inputView.readNames(); coaches.forEach(name -> { outputView.printExcludedFood(name); - inputView.readExcludedFood(); + memberService.addCoach(name, inputView.readExcludedFood()); }); } } diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java new file mode 100644 index 000000000..8547943e8 --- /dev/null +++ b/src/main/java/menu/domain/Coach.java @@ -0,0 +1,15 @@ +package menu.domain; + +import java.util.ArrayList; +import java.util.List; + +public class Coach { + + private final String name; + private final List excludedFoods; + + public Coach(String name, List excludedFoods) { + this.name = name; + this.excludedFoods = new ArrayList<>(excludedFoods); + } +} diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java new file mode 100644 index 000000000..efbc148a3 --- /dev/null +++ b/src/main/java/menu/domain/Coaches.java @@ -0,0 +1,13 @@ +package menu.domain; + +import java.util.ArrayList; +import java.util.List; + +public class Coaches { + + private final List coaches = new ArrayList<>(); + + public void addCoach(String name, List excludedFoods) { + coaches.add(new Coach(name, excludedFoods)); + } +} diff --git a/src/main/java/menu/service/MemberService.java b/src/main/java/menu/service/MemberService.java new file mode 100644 index 000000000..0f82c0983 --- /dev/null +++ b/src/main/java/menu/service/MemberService.java @@ -0,0 +1,14 @@ +package menu.service; + +import menu.domain.Coaches; + +import java.util.List; + +public class MemberService { + + private final Coaches coaches = new Coaches(); + + public void addCoach(String name, List excludedFoods) { + coaches.addCoach(name, excludedFoods); + } +} From 5cac7517e58ce3707070b0c9b57485a425c946dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 02:41:11 +0900 Subject: [PATCH 08/35] =?UTF-8?q?feat(Category):=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20enum=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/constant/Category.java | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/menu/constant/Category.java diff --git a/src/main/java/menu/constant/Category.java b/src/main/java/menu/constant/Category.java new file mode 100644 index 000000000..190c021c8 --- /dev/null +++ b/src/main/java/menu/constant/Category.java @@ -0,0 +1,27 @@ +package menu.constant; + +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())); + } +} From ccbbbabb5a7e5a567a882e2b5e8a2197965cd695 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 02:45:18 +0900 Subject: [PATCH 09/35] =?UTF-8?q?feat(CategoryRecommender):=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=B6=94=EC=B2=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- .../java/menu/constant/ExceptionMessage.java | 18 +++++++++++ .../java/menu/controller/MenuController.java | 3 ++ .../java/menu/domain/CategoryRecommender.java | 30 +++++++++++++++++++ src/main/java/menu/service/MenuService.java | 12 ++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 src/main/java/menu/constant/ExceptionMessage.java create mode 100644 src/main/java/menu/domain/CategoryRecommender.java create mode 100644 src/main/java/menu/service/MenuService.java diff --git a/docs/README.md b/docs/README.md index 187894a99..be2f6e0ce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -12,7 +12,7 @@ - [x] 못 먹는 음식 **카테고리 추천** -- [ ] 랜덤으로 카테고리를 뽑는다. +- [x] 랜덤으로 카테고리를 뽑는다. - [ ] 3번 이상 먹은 카테고리일 경우 다시 뽑는다. **음식 추천** diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java new file mode 100644 index 000000000..e19ab3b39 --- /dev/null +++ b/src/main/java/menu/constant/ExceptionMessage.java @@ -0,0 +1,18 @@ +package menu.constant; + +public enum ExceptionMessage { + + INCORRECT_RECOMMEND("잘못된 추천입니다."); + + 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/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 29ee2b983..8c2c544e8 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.service.MemberService; +import menu.service.MenuService; import menu.view.InputView; import menu.view.OutputView; @@ -11,6 +12,7 @@ public class MenuController { private final OutputView outputView = new OutputView(); private final InputView inputView = new InputView(); private final MemberService memberService = new MemberService(); + private final MenuService menuService = new MenuService(); public void start() { outputView.printStartMessage(); @@ -20,5 +22,6 @@ public void start() { outputView.printExcludedFood(name); memberService.addCoach(name, inputView.readExcludedFood()); }); + menuService.recommendCategory(); } } diff --git a/src/main/java/menu/domain/CategoryRecommender.java b/src/main/java/menu/domain/CategoryRecommender.java new file mode 100644 index 000000000..8ba1da21b --- /dev/null +++ b/src/main/java/menu/domain/CategoryRecommender.java @@ -0,0 +1,30 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Category; + +import java.util.ArrayList; +import java.util.List; + +public class CategoryRecommender { + + private static final int MAX_RECOMMEND = 5; + + private final List categories; + + public CategoryRecommender() { + this.categories = recommendCategory(); + } + + private List recommendCategory() { + List categories = new ArrayList<>(); + for (int i = 0; i < MAX_RECOMMEND; i++) { + categories.add(Category.getRecommendFood(Randoms.pickNumberInRange(1, 5))); + } + return categories; + } + + public List getCategories() { + return categories; + } +} diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java new file mode 100644 index 000000000..d3f1a3902 --- /dev/null +++ b/src/main/java/menu/service/MenuService.java @@ -0,0 +1,12 @@ +package menu.service; + +import menu.domain.CategoryRecommender; + +public class MenuService { + + CategoryRecommender categoryRecommender = new CategoryRecommender(); + + public void recommendCategory() { + System.out.println(categoryRecommender.getCategories()); + } +} From 75ddf5eaf94fdfe69ed9aacc6936e684aae11f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 03:31:59 +0900 Subject: [PATCH 10/35] =?UTF-8?q?feat(CategoryRecommender):=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=202=EB=B2=88=20=EB=A8=B9=EC=9D=80=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20?= =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=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 +-- .../java/menu/domain/CategoryRecommender.java | 26 +++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index be2f6e0ce..35d348d25 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,12 +13,12 @@ **카테고리 추천** - [x] 랜덤으로 카테고리를 뽑는다. -- [ ] 3번 이상 먹은 카테고리일 경우 다시 뽑는다. +- [x] 3번 이상 먹은 카테고리일 경우 다시 뽑는다. **음식 추천** - [ ] 카테고리의 음식 중 하나를 뽑는다. - [ ] 코치가 못 먹는 음식일 경우 다시 뽑는다. -- [ ] 이미 먹은 음식일 경우 다시 뽑는다. +- [ ] 이미 먹은 음식일 경우 다천시 뽑는다. **오류 발생** - [ ] 코치의 이름이 2~4글자 이상인 경우 diff --git a/src/main/java/menu/domain/CategoryRecommender.java b/src/main/java/menu/domain/CategoryRecommender.java index 8ba1da21b..80812a8c6 100644 --- a/src/main/java/menu/domain/CategoryRecommender.java +++ b/src/main/java/menu/domain/CategoryRecommender.java @@ -3,27 +3,43 @@ import camp.nextstep.edu.missionutils.Randoms; import menu.constant.Category; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class CategoryRecommender { - private static final int MAX_RECOMMEND = 5; + private static final int RECOMMEND_NUMBER = 5; + private static final int MAX_RECOMMEND_COUNT = 2; private final List categories; + private final Map categoriesCount; public CategoryRecommender() { + this.categoriesCount = new EnumMap<>(Category.class); + Arrays.stream(Category.values()) + .forEach(category -> categoriesCount.put(category, 0)); this.categories = recommendCategory(); } private List recommendCategory() { List categories = new ArrayList<>(); - for (int i = 0; i < MAX_RECOMMEND; i++) { - categories.add(Category.getRecommendFood(Randoms.pickNumberInRange(1, 5))); + while (categories.size() < RECOMMEND_NUMBER) { + Category recommendCategory = Category.getRecommendFood(Randoms.pickNumberInRange(1, 5)); + if (isNotThreeTimes(recommendCategory)) { + categories.add(recommendCategory); + categoriesCount.put(recommendCategory, increaseCount(recommendCategory)); + } } return categories; } + private boolean isNotThreeTimes(Category recommendCategory) { + return categoriesCount.get(recommendCategory) < MAX_RECOMMEND_COUNT; + } + + private int increaseCount(Category category) { + return categoriesCount.get(category) + 1; + } + public List getCategories() { return categories; } From f533b873b605230bee3c0f025bb119748631ffc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 17:40:20 +0900 Subject: [PATCH 11/35] =?UTF-8?q?feat(Menu):=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=EC=97=90=20=ED=8F=AC=ED=95=A8=EB=90=9C=20=EC=9D=8C?= =?UTF-8?q?=EC=8B=9D=20=EB=B0=98=ED=99=98=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 --- src/main/java/menu/constant/Menu.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/menu/constant/Menu.java diff --git a/src/main/java/menu/constant/Menu.java b/src/main/java/menu/constant/Menu.java new file mode 100644 index 000000000..03e662955 --- /dev/null +++ b/src/main/java/menu/constant/Menu.java @@ -0,0 +1,27 @@ +package menu.constant; + +import java.util.Arrays; +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; + } + + public static List getFoodsByCategory(Category category) { + return Arrays.stream(Menu.values()) + .filter(value -> value.category == category) + .findAny() + .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INCORRECT_CATEGORY.toString())) + .foods; + } +} From b5287581ca03c6c91d56805c46552c5b8e396b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 17:42:51 +0900 Subject: [PATCH 12/35] =?UTF-8?q?feat(MenuRecommender):=20=EC=9D=8C?= =?UTF-8?q?=EC=8B=9D=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 --- docs/README.md | 2 +- .../java/menu/constant/ExceptionMessage.java | 3 ++- .../java/menu/controller/MenuController.java | 6 ++--- src/main/java/menu/domain/Coaches.java | 5 ++++ .../java/menu/domain/MenuRecommender.java | 27 +++++++++++++++++++ src/main/java/menu/service/MemberService.java | 14 ---------- src/main/java/menu/service/MenuService.java | 23 +++++++++++++--- 7 files changed, 57 insertions(+), 23 deletions(-) create mode 100644 src/main/java/menu/domain/MenuRecommender.java delete mode 100644 src/main/java/menu/service/MemberService.java diff --git a/docs/README.md b/docs/README.md index 35d348d25..5b3742b7b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,7 +16,7 @@ - [x] 3번 이상 먹은 카테고리일 경우 다시 뽑는다. **음식 추천** -- [ ] 카테고리의 음식 중 하나를 뽑는다. +- [x] 카테고리의 음식 중 하나를 뽑는다. - [ ] 코치가 못 먹는 음식일 경우 다시 뽑는다. - [ ] 이미 먹은 음식일 경우 다천시 뽑는다. diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java index e19ab3b39..987a00277 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_RECOMMEND("잘못된 추천입니다."); + INCORRECT_RECOMMEND("잘못된 추천입니다."), + INCORRECT_CATEGORY("존재하지 않는 카테고리입니다."); 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 8c2c544e8..7a4504f59 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.service.MemberService; import menu.service.MenuService; import menu.view.InputView; import menu.view.OutputView; @@ -11,7 +10,6 @@ public class MenuController { private final OutputView outputView = new OutputView(); private final InputView inputView = new InputView(); - private final MemberService memberService = new MemberService(); private final MenuService menuService = new MenuService(); public void start() { @@ -20,8 +18,8 @@ public void start() { List coaches = inputView.readNames(); coaches.forEach(name -> { outputView.printExcludedFood(name); - memberService.addCoach(name, inputView.readExcludedFood()); + menuService.addCoach(name, inputView.readExcludedFood()); }); - menuService.recommendCategory(); + menuService.recommendMenus(); } } diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java index efbc148a3..8a0e8a1ba 100644 --- a/src/main/java/menu/domain/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -1,6 +1,7 @@ package menu.domain; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class Coaches { @@ -10,4 +11,8 @@ public class Coaches { public void addCoach(String name, List excludedFoods) { coaches.add(new Coach(name, excludedFoods)); } + + public List getCoaches() { + return Collections.unmodifiableList(coaches); + } } diff --git a/src/main/java/menu/domain/MenuRecommender.java b/src/main/java/menu/domain/MenuRecommender.java new file mode 100644 index 000000000..7024efad1 --- /dev/null +++ b/src/main/java/menu/domain/MenuRecommender.java @@ -0,0 +1,27 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Category; +import menu.constant.Menu; + +import java.util.*; + +public class MenuRecommender { + + private static final int WINNING_NUMBER = 0; + + private final Map> recommendResult; + + public MenuRecommender() { + this.recommendResult = new HashMap<>(); + } + + public void recommendFoods(Coach coach, List categories) { + List foods = new ArrayList<>(); + categories.forEach( (category) -> { + String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); + foods.add(menu); + }); + recommendResult.put(coach, foods); + } +} diff --git a/src/main/java/menu/service/MemberService.java b/src/main/java/menu/service/MemberService.java deleted file mode 100644 index 0f82c0983..000000000 --- a/src/main/java/menu/service/MemberService.java +++ /dev/null @@ -1,14 +0,0 @@ -package menu.service; - -import menu.domain.Coaches; - -import java.util.List; - -public class MemberService { - - private final Coaches coaches = new Coaches(); - - public void addCoach(String name, List excludedFoods) { - coaches.addCoach(name, excludedFoods); - } -} diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index d3f1a3902..33ed6fe83 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -1,12 +1,29 @@ package menu.service; +import menu.constant.Category; import menu.domain.CategoryRecommender; +import menu.domain.Coaches; +import menu.domain.MenuRecommender; + +import java.util.List; public class MenuService { - CategoryRecommender categoryRecommender = new CategoryRecommender(); + private final Coaches coaches = new Coaches(); + private final CategoryRecommender categoryRecommender = new CategoryRecommender(); + private final MenuRecommender menuRecommender = new MenuRecommender(); + + public void addCoach(String name, List excludedFoods) { + coaches.addCoach(name, excludedFoods); + } + + public List getRecommendCategory() { + return categoryRecommender.getCategories(); + } + + public void recommendMenus() { + coaches.getCoaches() + .forEach(coach -> menuRecommender.recommendFoods(coach, getRecommendCategory())); - public void recommendCategory() { - System.out.println(categoryRecommender.getCategories()); } } From f989cfc7c665dcad949f4ff5ecdcb6c8a84afd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 18:15:34 +0900 Subject: [PATCH 13/35] =?UTF-8?q?feat(Coach):=20=EC=BD=94=EC=B9=98?= =?UTF-8?q?=EA=B0=80=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D?= =?UTF-8?q?=EC=9D=B8=EC=A7=80=20=ED=8C=90=EB=8B=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Coach.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 8547943e8..26032c18f 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -12,4 +12,8 @@ public Coach(String name, List excludedFoods) { this.name = name; this.excludedFoods = new ArrayList<>(excludedFoods); } + + public boolean isExcludedFood(String food) { + return excludedFoods.contains(food); + } } From 88bc29aad161f636fc0034318d1bec994598a56c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 18:17:33 +0900 Subject: [PATCH 14/35] =?UTF-8?q?feat(MenuRecommender):=20=EC=BD=94?= =?UTF-8?q?=EC=B9=98=EA=B0=80=20=EB=AA=BB=20=EB=A8=B9=EB=8A=94=20=EC=9D=8C?= =?UTF-8?q?=EC=8B=9D=EC=9D=BC=20=EA=B2=BD=EC=9A=B0=20=EB=8B=A4=EC=8B=9C=20?= =?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 | 2 +- src/main/java/menu/domain/MenuRecommender.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5b3742b7b..3b5074b94 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,7 +17,7 @@ **음식 추천** - [x] 카테고리의 음식 중 하나를 뽑는다. -- [ ] 코치가 못 먹는 음식일 경우 다시 뽑는다. +- [x] 코치가 못 먹는 음식일 경우 다시 뽑는다. - [ ] 이미 먹은 음식일 경우 다천시 뽑는다. **오류 발생** diff --git a/src/main/java/menu/domain/MenuRecommender.java b/src/main/java/menu/domain/MenuRecommender.java index 7024efad1..52a5fdc28 100644 --- a/src/main/java/menu/domain/MenuRecommender.java +++ b/src/main/java/menu/domain/MenuRecommender.java @@ -18,10 +18,15 @@ public MenuRecommender() { public void recommendFoods(Coach coach, List categories) { List foods = new ArrayList<>(); - categories.forEach( (category) -> { - String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); - foods.add(menu); - }); + categories.forEach((category) -> foods.add(getRandomFood(coach, category))); recommendResult.put(coach, foods); } + + private String getRandomFood(Coach coach, Category category) { + String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); + while(coach.isExcludedFood(menu)) { + menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); + } + return menu; + } } From 842c47ef86bfe62e18701802cb251c26272eaa1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 18:38:04 +0900 Subject: [PATCH 15/35] =?UTF-8?q?feat(MenuRecommender):=20=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=20=EB=A8=B9=EC=9D=80=20=EC=9D=8C=EC=8B=9D=EC=9D=BC=20?= =?UTF-8?q?=EA=B2=BD=EC=9A=B0=20=EB=8B=A4=EC=8B=9C=20=EC=B6=94=EC=B2=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- src/main/java/menu/domain/MenuRecommender.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 3b5074b94..9bee3a2ff 100644 --- a/docs/README.md +++ b/docs/README.md @@ -18,7 +18,7 @@ **음식 추천** - [x] 카테고리의 음식 중 하나를 뽑는다. - [x] 코치가 못 먹는 음식일 경우 다시 뽑는다. -- [ ] 이미 먹은 음식일 경우 다천시 뽑는다. +- [x] 이미 먹은 음식일 경우 다시 뽑는다. **오류 발생** - [ ] 코치의 이름이 2~4글자 이상인 경우 diff --git a/src/main/java/menu/domain/MenuRecommender.java b/src/main/java/menu/domain/MenuRecommender.java index 52a5fdc28..07bdec0e0 100644 --- a/src/main/java/menu/domain/MenuRecommender.java +++ b/src/main/java/menu/domain/MenuRecommender.java @@ -17,16 +17,21 @@ public MenuRecommender() { } public void recommendFoods(Coach coach, List categories) { + System.out.println(categories); List foods = new ArrayList<>(); - categories.forEach((category) -> foods.add(getRandomFood(coach, category))); + categories.forEach((category) -> foods.add(getRandomFood(coach, category, foods))); recommendResult.put(coach, foods); } - private String getRandomFood(Coach coach, Category category) { + private String getRandomFood(Coach coach, Category category, List foods) { String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); - while(coach.isExcludedFood(menu)) { + while (coach.isExcludedFood(menu) || isDuplicate(menu, foods)) { menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); } return menu; } + + private boolean isDuplicate(String menu, List foods) { + return foods.contains(menu); + } } From 5d91324dd4bf94df750da3b08405b90f7f6a6b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 21:18:59 +0900 Subject: [PATCH 16/35] =?UTF-8?q?fix(MenuRecommender):=20=EC=B6=94?= =?UTF-8?q?=EC=B2=9C=20=EA=B8=B0=EB=8A=A5=20=EB=B0=A9=EC=8B=9D=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/menu/constant/ResultElement.java | 19 ++++++++++ src/main/java/menu/domain/Coach.java | 36 +++++++++++++++++- src/main/java/menu/domain/Coaches.java | 8 ++++ .../java/menu/domain/MenuRecommender.java | 37 ------------------- src/main/java/menu/service/MenuService.java | 11 ++++-- 5 files changed, 69 insertions(+), 42 deletions(-) create mode 100644 src/main/java/menu/constant/ResultElement.java delete mode 100644 src/main/java/menu/domain/MenuRecommender.java diff --git a/src/main/java/menu/constant/ResultElement.java b/src/main/java/menu/constant/ResultElement.java new file mode 100644 index 000000000..a91db3031 --- /dev/null +++ b/src/main/java/menu/constant/ResultElement.java @@ -0,0 +1,19 @@ +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/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 26032c18f..9a1622eeb 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -1,19 +1,53 @@ package menu.domain; +import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Category; +import menu.constant.Menu; +import menu.constant.ResultElement; + import java.util.ArrayList; import java.util.List; +import java.util.StringJoiner; public class Coach { + private static final int WINNING_NUMBER = 0; + private final String name; private final List excludedFoods; + private final List recommendFoods; public Coach(String name, List excludedFoods) { this.name = name; this.excludedFoods = new ArrayList<>(excludedFoods); + this.recommendFoods = new ArrayList<>(); + } + + public void recommendFoods(Category category) { + recommendFoods.add(getRandomFood(category)); + } + + private String getRandomFood(Category category) { + String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); + while (isExcludedFood(menu) || isDuplicateRecommend(menu)) { + menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); + } + return menu; } - public boolean isExcludedFood(String food) { + private boolean isExcludedFood(String food) { return excludedFoods.contains(food); } + + private boolean isDuplicateRecommend(String food) { + return recommendFoods.contains(food); + } + + @Override + public String toString() { + StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); + stringJoiner.add(name); + recommendFoods.forEach(stringJoiner::add); + return stringJoiner.toString(); + } } diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java index 8a0e8a1ba..5858bbd8a 100644 --- a/src/main/java/menu/domain/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -6,6 +6,7 @@ public class Coaches { + private static final String NEW_LINE = "\n"; private final List coaches = new ArrayList<>(); public void addCoach(String name, List excludedFoods) { @@ -15,4 +16,11 @@ public void addCoach(String name, List excludedFoods) { public List getCoaches() { return Collections.unmodifiableList(coaches); } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + coaches.forEach(coach -> stringBuilder.append(coach.toString()).append(NEW_LINE)); + return stringBuilder.toString(); + } } diff --git a/src/main/java/menu/domain/MenuRecommender.java b/src/main/java/menu/domain/MenuRecommender.java deleted file mode 100644 index 07bdec0e0..000000000 --- a/src/main/java/menu/domain/MenuRecommender.java +++ /dev/null @@ -1,37 +0,0 @@ -package menu.domain; - -import camp.nextstep.edu.missionutils.Randoms; -import menu.constant.Category; -import menu.constant.Menu; - -import java.util.*; - -public class MenuRecommender { - - private static final int WINNING_NUMBER = 0; - - private final Map> recommendResult; - - public MenuRecommender() { - this.recommendResult = new HashMap<>(); - } - - public void recommendFoods(Coach coach, List categories) { - System.out.println(categories); - List foods = new ArrayList<>(); - categories.forEach((category) -> foods.add(getRandomFood(coach, category, foods))); - recommendResult.put(coach, foods); - } - - private String getRandomFood(Coach coach, Category category, List foods) { - String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); - while (coach.isExcludedFood(menu) || isDuplicate(menu, foods)) { - menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); - } - return menu; - } - - private boolean isDuplicate(String menu, List foods) { - return foods.contains(menu); - } -} diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index 33ed6fe83..6af18e615 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -3,7 +3,6 @@ import menu.constant.Category; import menu.domain.CategoryRecommender; import menu.domain.Coaches; -import menu.domain.MenuRecommender; import java.util.List; @@ -11,7 +10,6 @@ public class MenuService { private final Coaches coaches = new Coaches(); private final CategoryRecommender categoryRecommender = new CategoryRecommender(); - private final MenuRecommender menuRecommender = new MenuRecommender(); public void addCoach(String name, List excludedFoods) { coaches.addCoach(name, excludedFoods); @@ -22,8 +20,13 @@ public List getRecommendCategory() { } public void recommendMenus() { - coaches.getCoaches() - .forEach(coach -> menuRecommender.recommendFoods(coach, getRecommendCategory())); + List categories = getRecommendCategory(); + categories.forEach(this::recommend); + System.out.println(coaches); + } + private void recommend(Category category) { + coaches.getCoaches() + .forEach(coach -> coach.recommendFoods(category)); } } From 9bb59aa0b32b7e9c4477cc11b941502f8b1f0f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 22:41:41 +0900 Subject: [PATCH 17/35] =?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 --- docs/README.md | 2 ++ src/main/java/menu/constant/Category.java | 5 +++++ src/main/java/menu/controller/MenuController.java | 1 + src/main/java/menu/domain/CategoryRecommender.java | 12 ++++++++++++ src/main/java/menu/service/MenuService.java | 4 ++++ src/main/java/menu/view/OutputView.java | 5 +++++ 6 files changed, 29 insertions(+) diff --git a/docs/README.md b/docs/README.md index 9bee3a2ff..2c3ebc9c5 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,6 +4,8 @@ - [x] 실행 문구 - [x] 이름 입력 안내 - [x] 못 먹는 음식 입력 안내 +- [ ] 추천 요일 +- [x] 추천 카테고리 - [ ] 메뉴 추천 결과 - [ ] 추천 완료 문구 diff --git a/src/main/java/menu/constant/Category.java b/src/main/java/menu/constant/Category.java index 190c021c8..f01ad30a3 100644 --- a/src/main/java/menu/constant/Category.java +++ b/src/main/java/menu/constant/Category.java @@ -24,4 +24,9 @@ public static Category getRecommendFood(int randomNumber) { .findAny() .orElseThrow(() -> new IllegalArgumentException(ExceptionMessage.INCORRECT_RECOMMEND.toString())); } + + @Override + public String toString() { + return type; + } } diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 7a4504f59..ba9aba1bc 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -21,5 +21,6 @@ public void start() { menuService.addCoach(name, inputView.readExcludedFood()); }); menuService.recommendMenus(); + outputView.printCategory(menuService.getCategories()); } } diff --git a/src/main/java/menu/domain/CategoryRecommender.java b/src/main/java/menu/domain/CategoryRecommender.java index 80812a8c6..4c9e52263 100644 --- a/src/main/java/menu/domain/CategoryRecommender.java +++ b/src/main/java/menu/domain/CategoryRecommender.java @@ -2,6 +2,7 @@ import camp.nextstep.edu.missionutils.Randoms; import menu.constant.Category; +import menu.constant.ResultElement; import java.util.*; @@ -9,6 +10,7 @@ public class CategoryRecommender { private static final int RECOMMEND_NUMBER = 5; private static final int MAX_RECOMMEND_COUNT = 2; + private static final String TITLE = "카테고리"; private final List categories; private final Map categoriesCount; @@ -43,4 +45,14 @@ private int increaseCount(Category category) { public List getCategories() { return categories; } + + @Override + public String toString() { + StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); + stringJoiner.add(TITLE); + categories.forEach( + (category) ->stringJoiner.add(category.toString()) + ); + return stringJoiner.toString(); + } } diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index 6af18e615..03bcb4eb6 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -29,4 +29,8 @@ private void recommend(Category category) { coaches.getCoaches() .forEach(coach -> coach.recommendFoods(category)); } + + public CategoryRecommender getCategories() { + return categoryRecommender; + } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index d64224e90..6f6b9931c 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -1,6 +1,7 @@ package menu.view; import menu.constant.OutputMessage; +import menu.domain.CategoryRecommender; public class OutputView { @@ -18,6 +19,10 @@ public void printExcludedFood(String name) { } + public void printCategory(CategoryRecommender categories) { + System.out.println(categories); + } + private void printNewLine() { System.out.println(); } From a0fbc8d9586b2f14e6cfb40f08d42184726bf8fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 22:55:01 +0900 Subject: [PATCH 18/35] =?UTF-8?q?feat(OutputView):=20=EC=9A=94=EC=9D=BC=20?= =?UTF-8?q?=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/Days.java | 21 +++++++++++++++++++ .../java/menu/constant/OutputMessage.java | 3 ++- .../java/menu/controller/MenuController.java | 1 + .../java/menu/domain/CategoryRecommender.java | 2 +- src/main/java/menu/view/OutputView.java | 13 ++++++++++++ 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/main/java/menu/constant/Days.java diff --git a/docs/README.md b/docs/README.md index 2c3ebc9c5..ae3212fdf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -4,7 +4,7 @@ - [x] 실행 문구 - [x] 이름 입력 안내 - [x] 못 먹는 음식 입력 안내 -- [ ] 추천 요일 +- [x] 추천 요일 - [x] 추천 카테고리 - [ ] 메뉴 추천 결과 - [ ] 추천 완료 문구 diff --git a/src/main/java/menu/constant/Days.java b/src/main/java/menu/constant/Days.java new file mode 100644 index 000000000..fb4064ade --- /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; + } +} diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index 3670e1ad4..7e72197b3 100644 --- a/src/main/java/menu/constant/OutputMessage.java +++ b/src/main/java/menu/constant/OutputMessage.java @@ -4,7 +4,8 @@ public enum OutputMessage { START_MESSAGE("점심 메뉴 추천을 시작합니다."), COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), - EXCLUDED_FOOD("%s(이)가 못 먹는 메뉴를 입력해 주세요.\n"); + EXCLUDED_FOOD("%s(이)가 못 먹는 메뉴를 입력해 주세요.\n"), + DAYS_TITLE("구분"); private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index ba9aba1bc..1546c2df2 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -21,6 +21,7 @@ public void start() { menuService.addCoach(name, inputView.readExcludedFood()); }); menuService.recommendMenus(); + outputView.printDays(); outputView.printCategory(menuService.getCategories()); } } diff --git a/src/main/java/menu/domain/CategoryRecommender.java b/src/main/java/menu/domain/CategoryRecommender.java index 4c9e52263..842f7f138 100644 --- a/src/main/java/menu/domain/CategoryRecommender.java +++ b/src/main/java/menu/domain/CategoryRecommender.java @@ -51,7 +51,7 @@ public String toString() { StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); stringJoiner.add(TITLE); categories.forEach( - (category) ->stringJoiner.add(category.toString()) + (category) -> stringJoiner.add(category.toString()) ); return stringJoiner.toString(); } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 6f6b9931c..acdf25388 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -1,8 +1,13 @@ package menu.view; +import menu.constant.Days; import menu.constant.OutputMessage; +import menu.constant.ResultElement; import menu.domain.CategoryRecommender; +import java.util.Arrays; +import java.util.StringJoiner; + public class OutputView { public void printStartMessage() { @@ -19,6 +24,14 @@ public void printExcludedFood(String name) { } + public void printDays() { + StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); + stringJoiner.add(OutputMessage.DAYS_TITLE.toString()); + Arrays.stream(Days.values()) + .forEach((day) -> stringJoiner.add(day.toString())); + System.out.println(stringJoiner); + } + public void printCategory(CategoryRecommender categories) { System.out.println(categories); } From a010efbbd2fbf7f99da93228c73025691f64e241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 23:00:15 +0900 Subject: [PATCH 19/35] =?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 --- docs/README.md | 2 +- src/main/java/menu/constant/Days.java | 2 +- src/main/java/menu/constant/OutputMessage.java | 4 +++- src/main/java/menu/controller/MenuController.java | 3 +++ src/main/java/menu/view/OutputView.java | 8 ++++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index ae3212fdf..1ee6eb3f9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -7,7 +7,7 @@ - [x] 추천 요일 - [x] 추천 카테고리 - [ ] 메뉴 추천 결과 -- [ ] 추천 완료 문구 +- [x] 추천 완료 문구 **입력** - [x] 코치 이름 diff --git a/src/main/java/menu/constant/Days.java b/src/main/java/menu/constant/Days.java index fb4064ade..c6ce7ae5e 100644 --- a/src/main/java/menu/constant/Days.java +++ b/src/main/java/menu/constant/Days.java @@ -1,7 +1,7 @@ package menu.constant; public enum Days { - + MONDAY("월요일"), TUESDAY("화요일"), WEDNESDAY("수요일"), diff --git a/src/main/java/menu/constant/OutputMessage.java b/src/main/java/menu/constant/OutputMessage.java index 7e72197b3..4ac516948 100644 --- a/src/main/java/menu/constant/OutputMessage.java +++ b/src/main/java/menu/constant/OutputMessage.java @@ -5,7 +5,9 @@ public enum OutputMessage { START_MESSAGE("점심 메뉴 추천을 시작합니다."), COACH_NAME("코치의 이름을 입력해 주세요. (, 로 구분)"), EXCLUDED_FOOD("%s(이)가 못 먹는 메뉴를 입력해 주세요.\n"), - DAYS_TITLE("구분"); + DAYS_TITLE("구분"), + MENU_RESULT("메뉴 추천 결과입니다."), + COMPLETE("추천을 완료했습니다."); private final String message; diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 1546c2df2..3033332bf 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -21,7 +21,10 @@ public void start() { menuService.addCoach(name, inputView.readExcludedFood()); }); menuService.recommendMenus(); + + outputView.printMenuResultMessage(); outputView.printDays(); outputView.printCategory(menuService.getCategories()); + outputView.printComplete(); } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index acdf25388..f79e3639e 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -36,6 +36,14 @@ public void printCategory(CategoryRecommender categories) { System.out.println(categories); } + public void printMenuResultMessage() { + System.out.println(OutputMessage.MENU_RESULT); + } + + public void printComplete() { + System.out.println(OutputMessage.COMPLETE); + } + private void printNewLine() { System.out.println(); } From 65b5401bda45c3201de6451fc3174f0be215a36f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 23:06:24 +0900 Subject: [PATCH 20/35] =?UTF-8?q?feat(OutputView):=20=EB=A9=94=EB=89=B4=20?= =?UTF-8?q?=EC=B6=94=EC=B2=9C=20=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 +- .../java/menu/controller/MenuController.java | 8 +++--- src/main/java/menu/service/MenuService.java | 5 +++- src/main/java/menu/view/OutputView.java | 25 ++++++++++++++----- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/docs/README.md b/docs/README.md index 1ee6eb3f9..8dd60712d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,7 +6,7 @@ - [x] 못 먹는 음식 입력 안내 - [x] 추천 요일 - [x] 추천 카테고리 -- [ ] 메뉴 추천 결과 +- [x] 메뉴 추천 결과 - [x] 추천 완료 문구 **입력** diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 3033332bf..09fbdc955 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -16,15 +16,13 @@ public void start() { outputView.printStartMessage(); outputView.printNameMessage(); List coaches = inputView.readNames(); + outputView.printNewLine(); coaches.forEach(name -> { outputView.printExcludedFood(name); menuService.addCoach(name, inputView.readExcludedFood()); + outputView.printNewLine(); }); menuService.recommendMenus(); - - outputView.printMenuResultMessage(); - outputView.printDays(); - outputView.printCategory(menuService.getCategories()); - outputView.printComplete(); + outputView.printResult(menuService.getCategories(), menuService.getCoaches()); } } diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index 03bcb4eb6..04facd96e 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -22,7 +22,6 @@ public List getRecommendCategory() { public void recommendMenus() { List categories = getRecommendCategory(); categories.forEach(this::recommend); - System.out.println(coaches); } private void recommend(Category category) { @@ -33,4 +32,8 @@ private void recommend(Category category) { public CategoryRecommender getCategories() { return categoryRecommender; } + + public Coaches getCoaches() { + return coaches; + } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index f79e3639e..b467a8b21 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.CategoryRecommender; +import menu.domain.Coaches; import java.util.Arrays; import java.util.StringJoiner; @@ -24,7 +25,19 @@ public void printExcludedFood(String name) { } - public void printDays() { + public void printResult(CategoryRecommender categories, Coaches coaches) { + printMenuResultMessage(); + printDays(); + printCategory(categories); + printRecommendResult(coaches); + printComplete(); + } + + private void printMenuResultMessage() { + System.out.println(OutputMessage.MENU_RESULT); + } + + private void printDays() { StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); stringJoiner.add(OutputMessage.DAYS_TITLE.toString()); Arrays.stream(Days.values()) @@ -32,19 +45,19 @@ public void printDays() { System.out.println(stringJoiner); } - public void printCategory(CategoryRecommender categories) { + private void printCategory(CategoryRecommender categories) { System.out.println(categories); } - public void printMenuResultMessage() { - System.out.println(OutputMessage.MENU_RESULT); + private void printRecommendResult(Coaches coaches) { + System.out.println(coaches); } - public void printComplete() { + private void printComplete() { System.out.println(OutputMessage.COMPLETE); } - private void printNewLine() { + public void printNewLine() { System.out.println(); } } From 683a89f39b2b702552b8b2c99e8be8888d33334e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 23:10:17 +0900 Subject: [PATCH 21/35] =?UTF-8?q?refactor(MenuService):=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=AA=85=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/service/MenuService.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index 04facd96e..2c8380044 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -15,16 +15,17 @@ public void addCoach(String name, List excludedFoods) { coaches.addCoach(name, excludedFoods); } - public List getRecommendCategory() { - return categoryRecommender.getCategories(); - } public void recommendMenus() { List categories = getRecommendCategory(); - categories.forEach(this::recommend); + categories.forEach(this::recommendMenuForCoaches); + } + + private List getRecommendCategory() { + return categoryRecommender.getCategories(); } - private void recommend(Category category) { + private void recommendMenuForCoaches(Category category) { coaches.getCoaches() .forEach(coach -> coach.recommendFoods(category)); } From f8604052861bfba50e4c5cb03ab37ad966356899 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Thu, 24 Aug 2023 23:30:28 +0900 Subject: [PATCH 22/35] =?UTF-8?q?feat(Name):=20=EC=BD=94=EC=B9=98=EC=9D=98?= =?UTF-8?q?=20=EC=9D=B4=EB=A6=84=EC=9D=B4=202~4=EA=B8=80=EC=9E=90=20?= =?UTF-8?q?=EC=9D=B4=EC=83=81=EC=9D=B8=20=EA=B2=BD=EC=9A=B0=20=EC=98=88?= =?UTF-8?q?=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 | 3 +- .../java/menu/controller/MenuController.java | 5 ++-- src/main/java/menu/domain/Coach.java | 6 ++-- src/main/java/menu/domain/Coaches.java | 2 +- src/main/java/menu/domain/Name.java | 28 +++++++++++++++++++ src/main/java/menu/service/MenuService.java | 3 +- src/main/java/menu/view/InputView.java | 8 ++++-- 8 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 src/main/java/menu/domain/Name.java diff --git a/docs/README.md b/docs/README.md index 8dd60712d..83aed273a 100644 --- a/docs/README.md +++ b/docs/README.md @@ -23,5 +23,5 @@ - [x] 이미 먹은 음식일 경우 다시 뽑는다. **오류 발생** -- [ ] 코치의 이름이 2~4글자 이상인 경우 +- [x] 코치의 이름이 2~4글자 이상인 경우 - [ ] `,`로 나누어져 있지 않은 경우 \ No newline at end of file diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java index 987a00277..1f5820b5b 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_RECOMMEND("잘못된 추천입니다."), - INCORRECT_CATEGORY("존재하지 않는 카테고리입니다."); + INCORRECT_CATEGORY("존재하지 않는 카테고리입니다."), + INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."); 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 09fbdc955..f7ace18ca 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -1,5 +1,6 @@ package menu.controller; +import menu.domain.Name; import menu.service.MenuService; import menu.view.InputView; import menu.view.OutputView; @@ -15,10 +16,10 @@ public class MenuController { public void start() { outputView.printStartMessage(); outputView.printNameMessage(); - List coaches = inputView.readNames(); + List coaches = inputView.readNames(); outputView.printNewLine(); coaches.forEach(name -> { - outputView.printExcludedFood(name); + outputView.printExcludedFood(name.toString()); menuService.addCoach(name, inputView.readExcludedFood()); outputView.printNewLine(); }); diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 9a1622eeb..1124b6b1e 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -13,11 +13,11 @@ public class Coach { private static final int WINNING_NUMBER = 0; - private final String name; + private final Name name; private final List excludedFoods; private final List recommendFoods; - public Coach(String name, List excludedFoods) { + public Coach(Name name, List excludedFoods) { this.name = name; this.excludedFoods = new ArrayList<>(excludedFoods); this.recommendFoods = new ArrayList<>(); @@ -46,7 +46,7 @@ private boolean isDuplicateRecommend(String food) { @Override public String toString() { StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); - stringJoiner.add(name); + stringJoiner.add(name.toString()); recommendFoods.forEach(stringJoiner::add); return stringJoiner.toString(); } diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java index 5858bbd8a..505abb242 100644 --- a/src/main/java/menu/domain/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -9,7 +9,7 @@ public class Coaches { private static final String NEW_LINE = "\n"; private final List coaches = new ArrayList<>(); - public void addCoach(String name, List excludedFoods) { + public void addCoach(Name name, List excludedFoods) { coaches.add(new Coach(name, excludedFoods)); } diff --git a/src/main/java/menu/domain/Name.java b/src/main/java/menu/domain/Name.java new file mode 100644 index 000000000..7fa36c040 --- /dev/null +++ b/src/main/java/menu/domain/Name.java @@ -0,0 +1,28 @@ +package menu.domain; + +import menu.constant.ExceptionMessage; + +public class Name { + + private static final int MIN_NAME_LENGTH = 2; + private static final int MAX_NAME_LENGTH = 4; + + private final String name; + + public Name(String name) { + validateName(name); + this.name = name; + } + + private void validateName(String name) { + if (!(MIN_NAME_LENGTH <= name.length() && name.length() <= MAX_NAME_LENGTH)) { + ExceptionMessage exceptionMessage = ExceptionMessage.INCORRECT_NAME_RANGE; + throw new IllegalArgumentException(exceptionMessage.toString()); + } + } + + @Override + public String toString() { + return name; + } +} diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index 2c8380044..728974d10 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -3,6 +3,7 @@ import menu.constant.Category; import menu.domain.CategoryRecommender; import menu.domain.Coaches; +import menu.domain.Name; import java.util.List; @@ -11,7 +12,7 @@ public class MenuService { private final Coaches coaches = new Coaches(); private final CategoryRecommender categoryRecommender = new CategoryRecommender(); - public void addCoach(String name, List excludedFoods) { + public void addCoach(Name name, List excludedFoods) { coaches.addCoach(name, excludedFoods); } diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 85e40ca69..536ec9bed 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -1,17 +1,21 @@ package menu.view; import camp.nextstep.edu.missionutils.Console; +import menu.domain.Name; +import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class InputView { - public List readNames() { + public List readNames() { String names = Console.readLine(); - return Stream.of(names.split(",")) + return Arrays.stream(names.split(",")) + .map(Name::new) .collect(Collectors.toList()); + } public List readExcludedFood() { From dc99f4244d9242027e45774be4abfc65ac64a67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 01:21:50 +0900 Subject: [PATCH 23/35] =?UTF-8?q?feat(InputValidator):=20`,`=EB=A1=9C=20?= =?UTF-8?q?=EB=82=98=EB=88=84=EC=96=B4=EC=A0=B8=20=EC=9E=88=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=80=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=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 | 3 ++- .../java/menu/validator/InputValidator.java | 17 +++++++++++++++++ src/main/java/menu/view/InputView.java | 5 +++++ 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/main/java/menu/validator/InputValidator.java diff --git a/docs/README.md b/docs/README.md index 83aed273a..0bb12129d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,4 +24,4 @@ **오류 발생** - [x] 코치의 이름이 2~4글자 이상인 경우 -- [ ] `,`로 나누어져 있지 않은 경우 \ No newline at end of file +- [x] `,`로 나누어져 있지 않은 경우 \ No newline at end of file diff --git a/src/main/java/menu/constant/ExceptionMessage.java b/src/main/java/menu/constant/ExceptionMessage.java index 1f5820b5b..0b8923040 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_RECOMMEND("잘못된 추천입니다."), INCORRECT_CATEGORY("존재하지 않는 카테고리입니다."), - INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."); + INCORRECT_NAME_RANGE("코치의 이름은 2~4자까지 입력할 수 있습니다."), + INCORRECT_DELIMITER("','로 구분해 입력하여 주십시오."); private static final String PREFIX = "[ERROR] "; private final String message; diff --git a/src/main/java/menu/validator/InputValidator.java b/src/main/java/menu/validator/InputValidator.java new file mode 100644 index 000000000..5e27a89ca --- /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 = "(\\S|,)+(\\S)"; + + 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 536ec9bed..27191b777 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.validator.InputValidator; import java.util.Arrays; import java.util.List; @@ -10,8 +11,11 @@ public class InputView { + InputValidator inputValidator = new InputValidator(); + public List readNames() { String names = Console.readLine(); + inputValidator.validateDelimiter(names); return Arrays.stream(names.split(",")) .map(Name::new) .collect(Collectors.toList()); @@ -20,6 +24,7 @@ public List readNames() { public List readExcludedFood() { String foods = Console.readLine(); + inputValidator.validateDelimiter(foods); return Stream.of(foods.split(",")) .collect(Collectors.toList()); } From d06f5363aea7fd5dac6cd7f34bf5fb672e7ec37b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 01:38:14 +0900 Subject: [PATCH 24/35] =?UTF-8?q?feat(InputValidator):=20=EC=A0=95?= =?UTF-8?q?=EA=B7=9C=EC=8B=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/validator/InputValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/menu/validator/InputValidator.java b/src/main/java/menu/validator/InputValidator.java index 5e27a89ca..5fa7aee07 100644 --- a/src/main/java/menu/validator/InputValidator.java +++ b/src/main/java/menu/validator/InputValidator.java @@ -6,7 +6,7 @@ public class InputValidator { - private static final String DELIMITER_REGEXP = "(\\S|,)+(\\S)"; + private static final String DELIMITER_REGEXP = "(\\S|,)+(\\S)?"; public void validateDelimiter(String input) { if (!Pattern.matches(DELIMITER_REGEXP, input)) { From 7f4c52aafd23aeff3a4fc4b907492656a1912df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 01:39:20 +0900 Subject: [PATCH 25/35] =?UTF-8?q?feat(InputView):=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=20=EC=8B=9C=20=EB=B0=9C=EC=83=9D=20=EC=A7=80?= =?UTF-8?q?=EC=A0=90=EB=B6=80=ED=84=B0=20=EC=9E=AC=EC=8B=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/menu/controller/MenuController.java | 2 -- src/main/java/menu/view/InputView.java | 36 +++++++++++++------ 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index f7ace18ca..08db7926a 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -15,9 +15,7 @@ public class MenuController { public void start() { outputView.printStartMessage(); - outputView.printNameMessage(); List coaches = inputView.readNames(); - outputView.printNewLine(); coaches.forEach(name -> { outputView.printExcludedFood(name.toString()); menuService.addCoach(name, inputView.readExcludedFood()); diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 27191b777..8d0ba0ea6 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -6,26 +6,42 @@ import java.util.Arrays; import java.util.List; +import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; public class InputView { InputValidator inputValidator = new InputValidator(); + OutputView outputView = new OutputView(); public List readNames() { - String names = Console.readLine(); - inputValidator.validateDelimiter(names); - return Arrays.stream(names.split(",")) - .map(Name::new) - .collect(Collectors.toList()); - + return attemptedInput(() -> { + outputView.printNameMessage(); + String names = Console.readLine(); + outputView.printNewLine(); + inputValidator.validateDelimiter(names); + return Arrays.stream(names.split(",")) + .map(Name::new) + .collect(Collectors.toList()); + }); } public List readExcludedFood() { - String foods = Console.readLine(); - inputValidator.validateDelimiter(foods); - return Stream.of(foods.split(",")) - .collect(Collectors.toList()); + return attemptedInput(() -> { + String foods = Console.readLine(); + inputValidator.validateDelimiter(foods); + return Stream.of(foods.split(",")) + .collect(Collectors.toList()); + }); + } + + private T attemptedInput(Supplier supplier) { + try { + return supplier.get(); + } catch (IllegalArgumentException exception) { + System.out.println(exception.getMessage()); + return supplier.get(); + } } } From a21fd7f2c43aee3766e5d400e751a046f41e23e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 01:42:21 +0900 Subject: [PATCH 26/35] =?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 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 08db7926a..47fa01819 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -15,13 +15,17 @@ public class MenuController { public void start() { outputView.printStartMessage(); + addCoachAndExcludedFoods(); + menuService.recommendMenus(); + outputView.printResult(menuService.getCategories(), menuService.getCoaches()); + } + + private void addCoachAndExcludedFoods() { List coaches = inputView.readNames(); coaches.forEach(name -> { outputView.printExcludedFood(name.toString()); menuService.addCoach(name, inputView.readExcludedFood()); outputView.printNewLine(); }); - menuService.recommendMenus(); - outputView.printResult(menuService.getCategories(), menuService.getCoaches()); } } From 18286a796c93ce2e127a44d14bcc36c0a86cfd12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 01:58:21 +0900 Subject: [PATCH 27/35] =?UTF-8?q?feat(Categories):=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...{CategoryRecommender.java => Categories.java} | 6 +++--- src/main/java/menu/service/MenuService.java | 16 ++++++---------- src/main/java/menu/view/OutputView.java | 6 +++--- 3 files changed, 12 insertions(+), 16 deletions(-) rename src/main/java/menu/domain/{CategoryRecommender.java => Categories.java} (95%) diff --git a/src/main/java/menu/domain/CategoryRecommender.java b/src/main/java/menu/domain/Categories.java similarity index 95% rename from src/main/java/menu/domain/CategoryRecommender.java rename to src/main/java/menu/domain/Categories.java index 842f7f138..7e10322e0 100644 --- a/src/main/java/menu/domain/CategoryRecommender.java +++ b/src/main/java/menu/domain/Categories.java @@ -6,7 +6,7 @@ import java.util.*; -public class CategoryRecommender { +public class Categories { private static final int RECOMMEND_NUMBER = 5; private static final int MAX_RECOMMEND_COUNT = 2; @@ -15,7 +15,7 @@ public class CategoryRecommender { private final List categories; private final Map categoriesCount; - public CategoryRecommender() { + public Categories() { this.categoriesCount = new EnumMap<>(Category.class); Arrays.stream(Category.values()) .forEach(category -> categoriesCount.put(category, 0)); @@ -31,7 +31,7 @@ private List recommendCategory() { categoriesCount.put(recommendCategory, increaseCount(recommendCategory)); } } - return categories; + return List.copyOf(categories); } private boolean isNotThreeTimes(Category recommendCategory) { diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index 728974d10..d9b88f8b3 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -1,7 +1,7 @@ package menu.service; import menu.constant.Category; -import menu.domain.CategoryRecommender; +import menu.domain.Categories; import menu.domain.Coaches; import menu.domain.Name; @@ -10,7 +10,7 @@ public class MenuService { private final Coaches coaches = new Coaches(); - private final CategoryRecommender categoryRecommender = new CategoryRecommender(); + private final Categories categories = new Categories(); public void addCoach(Name name, List excludedFoods) { coaches.addCoach(name, excludedFoods); @@ -18,12 +18,8 @@ public void addCoach(Name name, List excludedFoods) { public void recommendMenus() { - List categories = getRecommendCategory(); - categories.forEach(this::recommendMenuForCoaches); - } - - private List getRecommendCategory() { - return categoryRecommender.getCategories(); + categories.getCategories() + .forEach(this::recommendMenuForCoaches); } private void recommendMenuForCoaches(Category category) { @@ -31,8 +27,8 @@ private void recommendMenuForCoaches(Category category) { .forEach(coach -> coach.recommendFoods(category)); } - public CategoryRecommender getCategories() { - return categoryRecommender; + public Categories getCategories() { + return categories; } public Coaches getCoaches() { diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index b467a8b21..21f86caa4 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -3,7 +3,7 @@ import menu.constant.Days; import menu.constant.OutputMessage; import menu.constant.ResultElement; -import menu.domain.CategoryRecommender; +import menu.domain.Categories; import menu.domain.Coaches; import java.util.Arrays; @@ -25,7 +25,7 @@ public void printExcludedFood(String name) { } - public void printResult(CategoryRecommender categories, Coaches coaches) { + public void printResult(Categories categories, Coaches coaches) { printMenuResultMessage(); printDays(); printCategory(categories); @@ -45,7 +45,7 @@ private void printDays() { System.out.println(stringJoiner); } - private void printCategory(CategoryRecommender categories) { + private void printCategory(Categories categories) { System.out.println(categories); } From 309ef2ca691a6f784dd29be5250c20e44e3fce45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 02:10:34 +0900 Subject: [PATCH 28/35] =?UTF-8?q?feat(Coaches):=20getter=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Coaches.java | 7 ++++--- src/main/java/menu/service/MenuService.java | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/menu/domain/Coaches.java b/src/main/java/menu/domain/Coaches.java index 505abb242..4f4603f19 100644 --- a/src/main/java/menu/domain/Coaches.java +++ b/src/main/java/menu/domain/Coaches.java @@ -1,7 +1,8 @@ package menu.domain; +import menu.constant.Category; + import java.util.ArrayList; -import java.util.Collections; import java.util.List; public class Coaches { @@ -13,8 +14,8 @@ public void addCoach(Name name, List excludedFoods) { coaches.add(new Coach(name, excludedFoods)); } - public List getCoaches() { - return Collections.unmodifiableList(coaches); + public void recommendMenu(Category category) { + coaches.forEach(coach -> coach.recommendFoods(category)); } @Override diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java index d9b88f8b3..25779aa9b 100644 --- a/src/main/java/menu/service/MenuService.java +++ b/src/main/java/menu/service/MenuService.java @@ -19,12 +19,11 @@ public void addCoach(Name name, List excludedFoods) { public void recommendMenus() { categories.getCategories() - .forEach(this::recommendMenuForCoaches); + .forEach(this::recommendMenu); } - private void recommendMenuForCoaches(Category category) { - coaches.getCoaches() - .forEach(coach -> coach.recommendFoods(category)); + private void recommendMenu(Category category) { + coaches.recommendMenu(category); } public Categories getCategories() { From bb34e0b3e19d144f07cf5ef714cc18156e2624c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 02:11:17 +0900 Subject: [PATCH 29/35] =?UTF-8?q?refactor(InputView):=20=EC=97=90=EB=9F=AC?= =?UTF-8?q?=20=EC=B6=9C=EB=A0=A5=20=EB=B0=A9=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 | 2 +- src/main/java/menu/view/InputView.java | 2 +- src/main/java/menu/view/OutputView.java | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/menu/controller/MenuController.java b/src/main/java/menu/controller/MenuController.java index 47fa01819..debe7aa51 100644 --- a/src/main/java/menu/controller/MenuController.java +++ b/src/main/java/menu/controller/MenuController.java @@ -23,7 +23,7 @@ public void start() { private void addCoachAndExcludedFoods() { List coaches = inputView.readNames(); coaches.forEach(name -> { - outputView.printExcludedFood(name.toString()); + outputView.printExcludedFood(name); menuService.addCoach(name, inputView.readExcludedFood()); outputView.printNewLine(); }); diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 8d0ba0ea6..00683a82a 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -40,7 +40,7 @@ private T attemptedInput(Supplier supplier) { try { return supplier.get(); } catch (IllegalArgumentException exception) { - System.out.println(exception.getMessage()); + outputView.printExceptionMessage(exception.getMessage()); return supplier.get(); } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 21f86caa4..af3448944 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -5,6 +5,7 @@ import menu.constant.ResultElement; import menu.domain.Categories; import menu.domain.Coaches; +import menu.domain.Name; import java.util.Arrays; import java.util.StringJoiner; @@ -20,7 +21,7 @@ public void printNameMessage() { System.out.println(OutputMessage.COACH_NAME); } - public void printExcludedFood(String name) { + public void printExcludedFood(Name name) { System.out.printf(OutputMessage.EXCLUDED_FOOD.toString(), name); } @@ -60,4 +61,8 @@ private void printComplete() { public void printNewLine() { System.out.println(); } + + public void printExceptionMessage(String exceptionMessage) { + System.out.println(exceptionMessage); + } } From ed9399a4a8ebca7f4692d69cc1658c231fe43562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 02:20:12 +0900 Subject: [PATCH 30/35] =?UTF-8?q?test(InputValidator):=20`,`=EB=A1=9C=20?= =?UTF-8?q?=EB=82=98=EB=88=84=EC=96=B4=EC=A0=B8=20=EC=9E=88=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EC=9D=80=20=EA=B2=BD=EC=9A=B0=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=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/InputValidatorTest.java | 28 ++++++++++++++++++++++ 1 file changed, 28 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..13fa81f3d --- /dev/null +++ b/src/test/java/menu/InputValidatorTest.java @@ -0,0 +1,28 @@ +package menu; + +import menu.validator.InputValidator; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class InputValidatorTest { + + InputValidator inputValidator = new InputValidator(); + String ERROR_MESSAGE = "[ERROR]"; + + @Test + void validateSpace() { + String input = "토미, 제임스, 포코"; + assertThatThrownBy(() -> inputValidator.validateDelimiter(input)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @Test + void validateDelimiter() { + String input = "토미| 제임스, 포코"; + assertThatThrownBy(() -> inputValidator.validateDelimiter(input)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } +} From ff7b3565894a9b1c8c39e2f6a90cc97d9ceded5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 02:37:01 +0900 Subject: [PATCH 31/35] =?UTF-8?q?test(categories):=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20=EC=B6=94=EC=B2=9C=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoriesTest.java | 23 +++++++++++++++++++++++ 1 file changed, 23 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..406dbeb92 --- /dev/null +++ b/src/test/java/menu/CategoriesTest.java @@ -0,0 +1,23 @@ +package menu; + +import menu.domain.Categories; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CategoriesTest { + + @Test + void recommendCategories() { + Categories categories = new Categories(); + + assertThat(categories.getCategories().size()).isEqualTo(5); + } + + @Test + void CategoriesToString() { + Categories categories = new Categories(); + + assertThat(categories.toString()).contains("[ 카테고리 |"); + } +} From 935447de96c12f7c5b903412ea70b84c232717d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 02:41:36 +0900 Subject: [PATCH 32/35] =?UTF-8?q?test(Category):=20=EC=B9=B4=ED=85=8C?= =?UTF-8?q?=EA=B3=A0=EB=A6=AC=20=EC=9D=91=EB=8B=B5=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoryTest.java | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/test/java/menu/CategoryTest.java diff --git a/src/test/java/menu/CategoryTest.java b/src/test/java/menu/CategoryTest.java new file mode 100644 index 000000000..8645eca2e --- /dev/null +++ b/src/test/java/menu/CategoryTest.java @@ -0,0 +1,44 @@ +package menu; + +import menu.constant.Category; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class CategoryTest { + + @Test + void getJapanese() { + Category category = Category.getRecommendFood(1); + + assertThat(category).isEqualTo(Category.JAPANESE); + } + + @Test + void getKorean() { + Category category = Category.getRecommendFood(2); + + assertThat(category).isEqualTo(Category.KOREAN); + } + + @Test + void getChinese() { + Category category = Category.getRecommendFood(3); + + assertThat(category).isEqualTo(Category.CHINESE); + } + + @Test + void getAsian() { + Category category = Category.getRecommendFood(4); + + assertThat(category).isEqualTo(Category.ASIAN); + } + + @Test + void getWestern() { + Category category = Category.getRecommendFood(5); + + assertThat(category).isEqualTo(Category.WESTERN); + } +} From c1f2a9958ecd6c802932ceeec54c37e00eb03ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 02:50:42 +0900 Subject: [PATCH 33/35] =?UTF-8?q?test(Name):=20=EC=9D=B4=EB=A6=84=20?= =?UTF-8?q?=EA=B8=B8=EC=9D=B4=20=EC=98=88=EC=99=B8=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/menu/CategoriesTest.java | 2 +- src/test/java/menu/NameTest.java | 27 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/test/java/menu/NameTest.java diff --git a/src/test/java/menu/CategoriesTest.java b/src/test/java/menu/CategoriesTest.java index 406dbeb92..01657520a 100644 --- a/src/test/java/menu/CategoriesTest.java +++ b/src/test/java/menu/CategoriesTest.java @@ -15,7 +15,7 @@ void recommendCategories() { } @Test - void CategoriesToString() { + void categoriesToString() { Categories categories = new Categories(); assertThat(categories.toString()).contains("[ 카테고리 |"); diff --git a/src/test/java/menu/NameTest.java b/src/test/java/menu/NameTest.java new file mode 100644 index 000000000..2bfb19872 --- /dev/null +++ b/src/test/java/menu/NameTest.java @@ -0,0 +1,27 @@ +package menu; + +import menu.domain.Name; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class NameTest { + + String ERROR_MESSAGE = "[ERROR]"; + + @Test + void validateMinLength() { + String input = "빵"; + assertThatThrownBy(() -> new Name(input)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } + + @Test + void validateMaxLength() { + String input = "토미제임스포코"; + assertThatThrownBy(() -> new Name(input)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining(ERROR_MESSAGE); + } +} From 499da34cde71f1a0596c394b6ec9d50ed7316bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Fri, 25 Aug 2023 02:59:14 +0900 Subject: [PATCH 34/35] =?UTF-8?q?fix(InputValidator):=20=EB=B9=88=20?= =?UTF-8?q?=EA=B0=92=20=EC=9E=85=EB=A0=A5=EC=8B=9C=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EB=B0=9C=EC=83=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/validator/InputValidator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/menu/validator/InputValidator.java b/src/main/java/menu/validator/InputValidator.java index 5fa7aee07..9067979dd 100644 --- a/src/main/java/menu/validator/InputValidator.java +++ b/src/main/java/menu/validator/InputValidator.java @@ -6,7 +6,7 @@ public class InputValidator { - private static final String DELIMITER_REGEXP = "(\\S|,)+(\\S)?"; + private static final String DELIMITER_REGEXP = "(\\S|)+(,\\S)?"; public void validateDelimiter(String input) { if (!Pattern.matches(DELIMITER_REGEXP, input)) { From 84426a05a1b3e155b61d5d2017bb13635f6505ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=97=B0=EC=A7=84?= Date: Sat, 26 Aug 2023 17:55:47 +0900 Subject: [PATCH 35/35] =?UTF-8?q?refactor(RecommendMenu):=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=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Coach.java | 33 +++------------- src/main/java/menu/domain/ExcludedMenu.java | 17 +++++++++ src/main/java/menu/domain/RecommendMenu.java | 40 ++++++++++++++++++++ 3 files changed, 63 insertions(+), 27 deletions(-) create mode 100644 src/main/java/menu/domain/ExcludedMenu.java 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 1124b6b1e..914f8b7df 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -1,53 +1,32 @@ package menu.domain; -import camp.nextstep.edu.missionutils.Randoms; import menu.constant.Category; -import menu.constant.Menu; import menu.constant.ResultElement; -import java.util.ArrayList; import java.util.List; import java.util.StringJoiner; public class Coach { - private static final int WINNING_NUMBER = 0; - private final Name name; - private final List excludedFoods; - private final List recommendFoods; + private final ExcludedMenu excludedMenu; + private final RecommendMenu recommendMenu; public Coach(Name name, List excludedFoods) { this.name = name; - this.excludedFoods = new ArrayList<>(excludedFoods); - this.recommendFoods = new ArrayList<>(); + this.excludedMenu = new ExcludedMenu(excludedFoods); + this.recommendMenu = new RecommendMenu(); } public void recommendFoods(Category category) { - recommendFoods.add(getRandomFood(category)); - } - - private String getRandomFood(Category category) { - String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); - while (isExcludedFood(menu) || isDuplicateRecommend(menu)) { - menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); - } - return menu; - } - - private boolean isExcludedFood(String food) { - return excludedFoods.contains(food); - } - - private boolean isDuplicateRecommend(String food) { - return recommendFoods.contains(food); + recommendMenu.recommendFoods(category, excludedMenu); } @Override public String toString() { StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString(), ResultElement.START.toString(), ResultElement.END.toString()); stringJoiner.add(name.toString()); - recommendFoods.forEach(stringJoiner::add); + stringJoiner.add(recommendMenu.toString()); return stringJoiner.toString(); } } diff --git a/src/main/java/menu/domain/ExcludedMenu.java b/src/main/java/menu/domain/ExcludedMenu.java new file mode 100644 index 000000000..2c3403205 --- /dev/null +++ b/src/main/java/menu/domain/ExcludedMenu.java @@ -0,0 +1,17 @@ +package menu.domain; + +import java.util.List; + +public class ExcludedMenu { + + private final List excludedMenus; + + + public ExcludedMenu(List excludedMenus) { + this.excludedMenus = excludedMenus; + } + + public boolean isExcludedMenu(String recommendMenu) { + return excludedMenus.contains(recommendMenu); + } +} diff --git a/src/main/java/menu/domain/RecommendMenu.java b/src/main/java/menu/domain/RecommendMenu.java new file mode 100644 index 000000000..cc02b1ae2 --- /dev/null +++ b/src/main/java/menu/domain/RecommendMenu.java @@ -0,0 +1,40 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; +import menu.constant.Category; +import menu.constant.Menu; +import menu.constant.ResultElement; + +import java.util.ArrayList; +import java.util.List; +import java.util.StringJoiner; + +public class RecommendMenu { + + private static final int WINNING_NUMBER = 0; + + private final List menus = new ArrayList<>(); + + public void recommendFoods(Category category, ExcludedMenu excludedMenu) { + menus.add(getRandomFood(category, excludedMenu)); + } + + private String getRandomFood(Category category, ExcludedMenu excludedMenu) { + String menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); + while (isDuplicateRecommend(menu) || excludedMenu.isExcludedMenu(menu)) { + menu = Randoms.shuffle(Menu.getFoodsByCategory(category)).get(WINNING_NUMBER); + } + return menu; + } + + private boolean isDuplicateRecommend(String food) { + return menus.contains(food); + } + + @Override + public String toString() { + StringJoiner stringJoiner = new StringJoiner(ResultElement.DELIMITER.toString()); + menus.forEach(stringJoiner::add); + return stringJoiner.toString(); + } +}