From ecdc7a3b37ac77d1aa393cc47850182435120584 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 07:21:45 +0900 Subject: [PATCH 01/12] =?UTF-8?q?docs:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=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 | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29bb..17b2406d8 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,26 @@ +## 기능 요구 사항 + +- [ ] 한 주의 메뉴를 추천 박는 서비스이다. + +- [ ] 메뉴를 입력 받을 코치를 2~5명 입력받는다. + +- [ ] 0~2개의 못먹는 메뉴를 입력 받는다. + +- [ ] 한주에 같은 카테고리에서 2번 까지만 메뉴를 추천한다. + +- [ ] 각 코치에게 중복되지 않는 메뉴를 추천한다. + + +- 추천 가능 카테고리 + - 일식: 규동, 우동, 미소시루, 스시, 가츠동, 오니기리, 하이라이스, 라멘, 오코노미야끼 + 한식: 김밥, 김치찌개, 쌈밥, 된장찌개, 비빔밥, 칼국수, 불고기, 떡볶이, 제육볶음 + 중식: 깐풍기, 볶음면, 동파육, 짜장면, 짬뽕, 마파두부, 탕수육, 토마토 달걀볶음, 고추잡채 + 아시안: 팟타이, 카오 팟, 나시고렝, 파인애플 볶음밥, 쌀국수, 똠얌꿍, 반미, 월남쌈, 분짜 + 양식: 라자냐, 그라탱, 뇨끼, 끼슈, 프렌치 토스트, 바게트, 스파게티, 피자, 파니니 + + - [ ] 추천할 카테고리 랜덤 값이 1 = 일식, 2 = 한식, 3 = 중식, 4= 아시안, 5= 양식을 반환 + - [ ] 카테고리 메뉴를 셔플후 첫번째 값을 사용 + +- 예외 처리 +- [ ] 코치가 2~5명의 범위를 벗어 날때 +- [ ] 못먹는 메뉴가 0~2개를 벗어 날때 From 792f366bed7c90717721ab66cf3dcb1c08f0b1f6 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 07:25:49 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20=EC=96=B4=ED=94=8C=EB=A6=AC?= =?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=85=98=EA=B3=BC=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Application.java | 4 ++++ src/main/java/menu/controller/Controller.java | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/main/java/menu/controller/Controller.java diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6340b6f33..6a9574957 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -1,7 +1,11 @@ package menu; +import menu.controller.Controller; + public class Application { public static void main(String[] args) { // TODO: 프로그램 구현 + Controller controller = new Controller(); + controller.run(); } } diff --git a/src/main/java/menu/controller/Controller.java b/src/main/java/menu/controller/Controller.java new file mode 100644 index 000000000..e6bc4523a --- /dev/null +++ b/src/main/java/menu/controller/Controller.java @@ -0,0 +1,8 @@ +package menu.controller; + +public class Controller { + + public void run() { + + } +} From 5f3bf1620eccc20bfe4375d2dab5adce2eb227cd Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 08:19:05 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20=EB=A9=94=EB=89=B4=EC=99=80?= =?UTF-8?q?=EB=A9=94=EB=89=B4=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Menu.java | 5 +++++ src/main/java/menu/domain/MenuCategory.java | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 src/main/java/menu/domain/Menu.java create mode 100644 src/main/java/menu/domain/MenuCategory.java diff --git a/src/main/java/menu/domain/Menu.java b/src/main/java/menu/domain/Menu.java new file mode 100644 index 000000000..bdb62f24e --- /dev/null +++ b/src/main/java/menu/domain/Menu.java @@ -0,0 +1,5 @@ +package menu.domain; + +public class Menu { + +} diff --git a/src/main/java/menu/domain/MenuCategory.java b/src/main/java/menu/domain/MenuCategory.java new file mode 100644 index 000000000..a66adaa5b --- /dev/null +++ b/src/main/java/menu/domain/MenuCategory.java @@ -0,0 +1,9 @@ +package menu.domain; + +public enum MenuCategory { + JAPANESE, + KOREAN, + CHINESE, + ASIAN, + WESTERN; +} From e845906bed02941779443dee31f1bd6d8d4e2f16 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 08:34:25 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=EC=9D=98=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=EC=9D=84=20=EC=9E=85=EB=A0=A5=EB=B0=9B?= =?UTF-8?q?=EB=8A=94=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/Controller.java | 11 ++++++++++ src/main/java/menu/domain/Coach.java | 12 ++++++++++ src/main/java/menu/view/InputView.java | 22 +++++++++++++++++++ src/main/java/menu/view/OutputView.java | 11 ++++++++++ 4 files changed, 56 insertions(+) create mode 100644 src/main/java/menu/domain/Coach.java create mode 100644 src/main/java/menu/view/InputView.java create mode 100644 src/main/java/menu/view/OutputView.java diff --git a/src/main/java/menu/controller/Controller.java b/src/main/java/menu/controller/Controller.java index e6bc4523a..dcbecd011 100644 --- a/src/main/java/menu/controller/Controller.java +++ b/src/main/java/menu/controller/Controller.java @@ -1,8 +1,19 @@ package menu.controller; +import menu.domain.Coach; +import menu.view.InputView; +import menu.view.OutputView; + public class Controller { public void run() { + OutputView.welcomeMessage(); + askCoachName(); + } + + private void askCoachName() { + new Coach(InputView.askCoachName()); } + } diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java new file mode 100644 index 000000000..9bbd73bd1 --- /dev/null +++ b/src/main/java/menu/domain/Coach.java @@ -0,0 +1,12 @@ +package menu.domain; + +import java.util.List; + +public class Coach { + private final List coachNames; + + public Coach(List coachNames) { + this.coachNames = coachNames; + } + +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java new file mode 100644 index 000000000..631985c71 --- /dev/null +++ b/src/main/java/menu/view/InputView.java @@ -0,0 +1,22 @@ +package menu.view; + +import camp.nextstep.edu.missionutils.Console; + +import java.util.Arrays; +import java.util.List; + +public class InputView { +private static final String INPUT_NAME_MESSAGE = "%n코치의 이름을 입력해 주세요. (, 로 구분)%n"; +private static final String INPUT_MENU_MESSAGE = "%n%s (이)가 못 먹는 메뉴를 입력해 주세요."; +private static final int MIN_COACH=2; +private static final int MAX_COACH=5; + + public static List askCoachName() { + System.out.printf(INPUT_NAME_MESSAGE); + List coachName = Arrays.asList(Console.readLine().split(",")); + + return coachName; + } + + +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java new file mode 100644 index 000000000..e866ffbb9 --- /dev/null +++ b/src/main/java/menu/view/OutputView.java @@ -0,0 +1,11 @@ +package menu.view; + +public class OutputView { + private static final String WELCOME_MESSAGE = "점심 메뉴 추천을 시작합니다."; + private static final String RECOMMEND_RESULT_MESSAGE = "메뉴 추천 결과입니다."; + private static final String RECOMMEND_COMPLETE_MESSAGE = "추천을 완료했습니다."; + + public static void welcomeMessage(){ + System.out.println(WELCOME_MESSAGE); + } +} From 7d0bdc340bbc50b891b955b9d0903d9e8523b44e Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 08:51:36 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EC=BD=94=EC=B9=98=20=EC=88=98=EA=B0=80=20=EB=B2=94?= =?UTF-8?q?=EC=9C=84=EB=A5=BC=20=EB=84=98=EC=96=B4=EA=B0=94=EC=9D=84?= =?UTF-8?q?=EB=95=8C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/Controller.java | 11 +++++++++-- src/main/java/menu/global/Error.java | 15 +++++++++++++++ src/main/java/menu/view/InputView.java | 10 ++++++++-- src/main/java/menu/view/OutputView.java | 4 +++- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 src/main/java/menu/global/Error.java diff --git a/src/main/java/menu/controller/Controller.java b/src/main/java/menu/controller/Controller.java index dcbecd011..e72f3c4c0 100644 --- a/src/main/java/menu/controller/Controller.java +++ b/src/main/java/menu/controller/Controller.java @@ -11,8 +11,15 @@ public void run() { askCoachName(); } - private void askCoachName() { - new Coach(InputView.askCoachName()); + private Coach askCoachName() { + while (true) { + try { + return new Coach(InputView.askCoachName()); + } catch (IllegalArgumentException e) { + OutputView.printError(e); + } + } + } diff --git a/src/main/java/menu/global/Error.java b/src/main/java/menu/global/Error.java new file mode 100644 index 000000000..7bcf21aa0 --- /dev/null +++ b/src/main/java/menu/global/Error.java @@ -0,0 +1,15 @@ +package menu.global; + +public enum Error { + NAME_RANGE_OUT("코치는 최소 2명 이상 5명 이하로 입력해야 합니다."); + private static final String ERROR = "[ERROR] "; + private final String message; + + Error(String message) { + this.message = ERROR+message; + } + + public String getMessage() { + return message; + } +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 631985c71..32cc0378d 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -5,6 +5,8 @@ import java.util.Arrays; import java.util.List; +import static menu.global.Error.NAME_RANGE_OUT; + public class InputView { private static final String INPUT_NAME_MESSAGE = "%n코치의 이름을 입력해 주세요. (, 로 구분)%n"; private static final String INPUT_MENU_MESSAGE = "%n%s (이)가 못 먹는 메뉴를 입력해 주세요."; @@ -14,9 +16,13 @@ public class InputView { public static List askCoachName() { System.out.printf(INPUT_NAME_MESSAGE); List coachName = Arrays.asList(Console.readLine().split(",")); - + validate(coachName); return coachName; } - + private static void validate(List coachName) { + if(coachName.size()MAX_COACH){ + throw new IllegalArgumentException(NAME_RANGE_OUT.getMessage()); + } + } } diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index e866ffbb9..a88416657 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -4,7 +4,9 @@ public class OutputView { private static final String WELCOME_MESSAGE = "점심 메뉴 추천을 시작합니다."; private static final String RECOMMEND_RESULT_MESSAGE = "메뉴 추천 결과입니다."; private static final String RECOMMEND_COMPLETE_MESSAGE = "추천을 완료했습니다."; - + public static void printError(Exception e) { + System.out.println(e.getMessage()); + } public static void welcomeMessage(){ System.out.println(WELCOME_MESSAGE); } From 9b71501f471f349575649e3face7f650d2accf23 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 09:32:36 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20=EC=BD=94=EC=B9=98=EA=B0=80=20?= =?UTF-8?q?=EB=AA=BB=EB=A8=B9=EB=8A=94=20=EC=9D=8C=EC=8B=9D=EC=9D=84=20?= =?UTF-8?q?=EB=B0=9B=EC=95=84=EC=84=9C=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/Controller.java | 10 +++++++++- src/main/java/menu/domain/Coach.java | 3 +++ src/main/java/menu/domain/NonPreferredMenu.java | 14 ++++++++++++++ src/main/java/menu/view/InputView.java | 12 ++++++++++-- src/main/java/menu/view/OutputView.java | 4 ++++ 5 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/main/java/menu/domain/NonPreferredMenu.java diff --git a/src/main/java/menu/controller/Controller.java b/src/main/java/menu/controller/Controller.java index e72f3c4c0..e46e28899 100644 --- a/src/main/java/menu/controller/Controller.java +++ b/src/main/java/menu/controller/Controller.java @@ -1,14 +1,22 @@ package menu.controller; import menu.domain.Coach; +import menu.domain.NonPreferredMenu; import menu.view.InputView; import menu.view.OutputView; +import java.util.List; + public class Controller { public void run() { OutputView.welcomeMessage(); - askCoachName(); + Coach coach = askCoachName(); + NonPreferredMenu nonPreferredMenu = askNonPreferred(coach.getCoachNames()); + } + + private NonPreferredMenu askNonPreferred(List coachNames) { + return new NonPreferredMenu(InputView.askNonPreferred(coachNames)); } private Coach askCoachName() { diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java index 9bbd73bd1..4e832de57 100644 --- a/src/main/java/menu/domain/Coach.java +++ b/src/main/java/menu/domain/Coach.java @@ -9,4 +9,7 @@ public Coach(List coachNames) { this.coachNames = coachNames; } + public List getCoachNames() { + return this.coachNames; + } } diff --git a/src/main/java/menu/domain/NonPreferredMenu.java b/src/main/java/menu/domain/NonPreferredMenu.java new file mode 100644 index 000000000..dca1b6059 --- /dev/null +++ b/src/main/java/menu/domain/NonPreferredMenu.java @@ -0,0 +1,14 @@ +package menu.domain; + +import java.util.List; + +public class NonPreferredMenu { + private final List> nonPreferredMenus; + public NonPreferredMenu(List> nonPreferredMenus) { + this.nonPreferredMenus = nonPreferredMenus; + } + + public List> getCoachNames() { + return nonPreferredMenus; + } +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 32cc0378d..595c04a14 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 java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -9,7 +10,7 @@ public class InputView { private static final String INPUT_NAME_MESSAGE = "%n코치의 이름을 입력해 주세요. (, 로 구분)%n"; -private static final String INPUT_MENU_MESSAGE = "%n%s (이)가 못 먹는 메뉴를 입력해 주세요."; +private static final String INPUT_MENU_MESSAGE = "%n%s (이)가 못 먹는 메뉴를 입력해 주세요.%n"; private static final int MIN_COACH=2; private static final int MAX_COACH=5; @@ -19,7 +20,14 @@ public static List askCoachName() { validate(coachName); return coachName; } - + public static List> askNonPreferred(List coachNames) { + List> nonPreferredMenus = new ArrayList<>(); + for(String names : coachNames){ + System.out.printf(INPUT_MENU_MESSAGE,names); + nonPreferredMenus.add( Arrays.asList(Console.readLine().split(","))); + } + return nonPreferredMenus; + } private static void validate(List coachName) { if(coachName.size()MAX_COACH){ throw new IllegalArgumentException(NAME_RANGE_OUT.getMessage()); diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index a88416657..d6496cfd5 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -1,5 +1,7 @@ package menu.view; +import java.util.List; + public class OutputView { private static final String WELCOME_MESSAGE = "점심 메뉴 추천을 시작합니다."; private static final String RECOMMEND_RESULT_MESSAGE = "메뉴 추천 결과입니다."; @@ -10,4 +12,6 @@ public static void printError(Exception e) { public static void welcomeMessage(){ System.out.println(WELCOME_MESSAGE); } + + } From 36881155223c38bc73176c5e9f1aea9afbf27963 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 09:52:25 +0900 Subject: [PATCH 07/12] =?UTF-8?q?feat:=20=EB=A9=94=EB=89=B4=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/Menu.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/menu/domain/Menu.java b/src/main/java/menu/domain/Menu.java index bdb62f24e..087b41483 100644 --- a/src/main/java/menu/domain/Menu.java +++ b/src/main/java/menu/domain/Menu.java @@ -1,5 +1,30 @@ package menu.domain; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + public class Menu { + private static final List JAPANESE = + new ArrayList<>(Arrays.asList("규동", "우동", "미소시루", + "스시", "가츠동","오니기리", "하이라이스", "라멘", "오꼬노미야끼")); + private static final List KOREAN = + new ArrayList<>(Arrays.asList("김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기", + "떡볶이","제육볶음")); + + private static final List CHINESE = + new ArrayList<>(Arrays.asList("깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육", + "토마토 ","달걀볶음","고추잡채")); + + private static final List ASIAN = + new ArrayList<>(Arrays.asList("팟타이", "카오 팟", "나시고렝", "파인애플 볶음밥", "똠얌꿍", "반미", "월남쌈", + "분짜")); + + private static final List WESTERN = + new ArrayList<>(Arrays.asList("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", + "피자","파니니")); + + + } From a0c4a164036dc28c44eceafa78df455315d4a72f Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 10:22:50 +0900 Subject: [PATCH 08/12] =?UTF-8?q?feat:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EB=A7=A4=EC=B9=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/Controller.java | 5 +++++ src/main/java/menu/domain/ChooseCategory.java | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/main/java/menu/domain/ChooseCategory.java diff --git a/src/main/java/menu/controller/Controller.java b/src/main/java/menu/controller/Controller.java index e46e28899..9ab5e5b97 100644 --- a/src/main/java/menu/controller/Controller.java +++ b/src/main/java/menu/controller/Controller.java @@ -1,5 +1,6 @@ package menu.controller; +import menu.domain.ChooseCategory; import menu.domain.Coach; import menu.domain.NonPreferredMenu; import menu.view.InputView; @@ -13,8 +14,12 @@ public void run() { OutputView.welcomeMessage(); Coach coach = askCoachName(); NonPreferredMenu nonPreferredMenu = askNonPreferred(coach.getCoachNames()); + ChooseCategory chooseCategory = new ChooseCategory(); + chooseCategory.choose(); } + + private NonPreferredMenu askNonPreferred(List coachNames) { return new NonPreferredMenu(InputView.askNonPreferred(coachNames)); } diff --git a/src/main/java/menu/domain/ChooseCategory.java b/src/main/java/menu/domain/ChooseCategory.java new file mode 100644 index 000000000..b1933ff16 --- /dev/null +++ b/src/main/java/menu/domain/ChooseCategory.java @@ -0,0 +1,20 @@ +package menu.domain; + +import java.util.EnumMap; +import java.util.Map; + +import static menu.domain.MenuCategory.*; + +public class ChooseCategory { + final Map map = new EnumMap<>(MenuCategory.class); + public ChooseCategory(){ + map.put(JAPANESE, 1); + map.put(KOREAN, 2); + map.put(CHINESE, 3 ); + map.put(ASIAN, 4); + map.put(WESTERN, 5); + } + public void choose() { + + } +} From b8bc01565ac394cf3a8a9ffdf9e64f460ce4dace Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 10:25:53 +0900 Subject: [PATCH 09/12] =?UTF-8?q?fix:=20=EB=A7=A4=ED=95=91=EC=9D=84=20enum?= =?UTF-8?q?Map=20=EC=97=90=EC=84=9C=20HashMap=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/domain/ChooseCategory.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/java/menu/domain/ChooseCategory.java b/src/main/java/menu/domain/ChooseCategory.java index b1933ff16..1a90df2e2 100644 --- a/src/main/java/menu/domain/ChooseCategory.java +++ b/src/main/java/menu/domain/ChooseCategory.java @@ -1,18 +1,19 @@ package menu.domain; import java.util.EnumMap; +import java.util.HashMap; import java.util.Map; import static menu.domain.MenuCategory.*; public class ChooseCategory { - final Map map = new EnumMap<>(MenuCategory.class); + final Map map = new HashMap<>(); public ChooseCategory(){ - map.put(JAPANESE, 1); - map.put(KOREAN, 2); - map.put(CHINESE, 3 ); - map.put(ASIAN, 4); - map.put(WESTERN, 5); + map.put(1, JAPANESE); + map.put(2, KOREAN); + map.put(3, CHINESE ); + map.put(4, ASIAN); + map.put(5, WESTERN); } public void choose() { From a2fa0e9766ca3938446b6511c3f4240fd2c4a302 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 10:58:25 +0900 Subject: [PATCH 10/12] =?UTF-8?q?feat:=20=EC=9A=94=EC=9D=BC=EB=B3=84=20?= =?UTF-8?q?=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=84=A0=EC=A0=95=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/Application.java | 1 + src/main/java/menu/domain/ChooseCategory.java | 41 ++++++++++++++++--- src/main/java/menu/view/OutputView.java | 4 +- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6a9574957..c4e2c8df2 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -6,6 +6,7 @@ public class Application { public static void main(String[] args) { // TODO: 프로그램 구현 Controller controller = new Controller(); + controller.run(); } } diff --git a/src/main/java/menu/domain/ChooseCategory.java b/src/main/java/menu/domain/ChooseCategory.java index 1a90df2e2..b7f6ea378 100644 --- a/src/main/java/menu/domain/ChooseCategory.java +++ b/src/main/java/menu/domain/ChooseCategory.java @@ -1,21 +1,50 @@ package menu.domain; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.Map; +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.*; +import java.util.stream.IntStream; import static menu.domain.MenuCategory.*; public class ChooseCategory { + private static final int MAX_ALLOW_DUPLICATION = 2; + private static final int MAX_ATTEMPTS = 3; final Map map = new HashMap<>(); - public ChooseCategory(){ + private final List choicesCategory = new ArrayList<>(); + + public ChooseCategory() { map.put(1, JAPANESE); map.put(2, KOREAN); - map.put(3, CHINESE ); + map.put(3, CHINESE); map.put(4, ASIAN); map.put(5, WESTERN); } + public void choose() { + IntStream.range(0, 5) + .mapToObj(i -> generateUniqueValue(map)) + .forEach(choicesCategory::add); + + } + + private MenuCategory generateUniqueValue(Map map) { + MenuCategory value = null; + for (int attempt = 0; attempt < MAX_ATTEMPTS; attempt++) { + int randomKey = Randoms.pickNumberInRange(1, 5); // 실제로는 여기에서 랜덤 값 추출 + + value = map.get(randomKey); + if (value != null && countOccurrences(choicesCategory, value) < MAX_ALLOW_DUPLICATION) { + return value; + } + } + + return generateUniqueValue(map); + } + private int countOccurrences(List choices, MenuCategory value) { + return (int) choices.stream() + .filter(choice -> choice.equals(value)) + .count(); } -} +} \ No newline at end of file diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index d6496cfd5..222e9514c 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -13,5 +13,7 @@ public static void welcomeMessage(){ System.out.println(WELCOME_MESSAGE); } - + public static void recommendMenu(){ + System.out.println(RECOMMEND_RESULT_MESSAGE); + } } From 407c5613f49fe565b006da34b6d72aacbced7de3 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 11:18:43 +0900 Subject: [PATCH 11/12] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=9C=20=EC=B9=B4?= =?UTF-8?q?=ED=85=8C=EA=B3=A0=EB=A6=AC=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/Controller.java | 5 +++++ src/main/java/menu/domain/ChooseCategory.java | 4 ++++ src/main/java/menu/view/InputView.java | 2 +- src/main/java/menu/view/OutputView.java | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/menu/controller/Controller.java b/src/main/java/menu/controller/Controller.java index 9ab5e5b97..71fdec311 100644 --- a/src/main/java/menu/controller/Controller.java +++ b/src/main/java/menu/controller/Controller.java @@ -2,6 +2,7 @@ import menu.domain.ChooseCategory; import menu.domain.Coach; +import menu.domain.MenuCategory; import menu.domain.NonPreferredMenu; import menu.view.InputView; import menu.view.OutputView; @@ -16,8 +17,12 @@ public void run() { NonPreferredMenu nonPreferredMenu = askNonPreferred(coach.getCoachNames()); ChooseCategory chooseCategory = new ChooseCategory(); chooseCategory.choose(); + printCategory(chooseCategory.getCategory()); } + private void printCategory(List category) { + OutputView.printCategory(category); + } private NonPreferredMenu askNonPreferred(List coachNames) { diff --git a/src/main/java/menu/domain/ChooseCategory.java b/src/main/java/menu/domain/ChooseCategory.java index b7f6ea378..667db1555 100644 --- a/src/main/java/menu/domain/ChooseCategory.java +++ b/src/main/java/menu/domain/ChooseCategory.java @@ -47,4 +47,8 @@ private int countOccurrences(List choices, MenuCategory value) { .filter(choice -> choice.equals(value)) .count(); } + + public List getCategory() { + return this.choicesCategory; + } } \ No newline at end of file diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java index 595c04a14..ba9bc656e 100644 --- a/src/main/java/menu/view/InputView.java +++ b/src/main/java/menu/view/InputView.java @@ -10,7 +10,7 @@ public class InputView { private static final String INPUT_NAME_MESSAGE = "%n코치의 이름을 입력해 주세요. (, 로 구분)%n"; -private static final String INPUT_MENU_MESSAGE = "%n%s (이)가 못 먹는 메뉴를 입력해 주세요.%n"; +private static final String INPUT_MENU_MESSAGE = "%s (이)가 못 먹는 메뉴를 입력해 주세요.%n"; private static final int MIN_COACH=2; private static final int MAX_COACH=5; diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java index 222e9514c..812064d60 100644 --- a/src/main/java/menu/view/OutputView.java +++ b/src/main/java/menu/view/OutputView.java @@ -1,11 +1,20 @@ package menu.view; +import menu.domain.MenuCategory; + import java.util.List; public class OutputView { private static final String WELCOME_MESSAGE = "점심 메뉴 추천을 시작합니다."; private static final String RECOMMEND_RESULT_MESSAGE = "메뉴 추천 결과입니다."; private static final String RECOMMEND_COMPLETE_MESSAGE = "추천을 완료했습니다."; + private static final String SORTATION = "[ 구분 | 월요일 | 화요일 | 수요일 | 목요일 | 금요일 ]"; + private static final String CATEGORY = "[ 카테고리 | %s | %s | %s | %s | %s ]"; + private static final int ZERO = 0; + private static final int ONE = 1; + private static final int TWO = 2; + private static final int THREE = 3; + private static final int FOUR = 4; public static void printError(Exception e) { System.out.println(e.getMessage()); } @@ -16,4 +25,12 @@ public static void welcomeMessage(){ public static void recommendMenu(){ System.out.println(RECOMMEND_RESULT_MESSAGE); } + + public static void printCategory(List category) { + recommendMenu(); + System.out.println(SORTATION); + System.out.printf(CATEGORY,category.get(ZERO),category.get(ONE), + category.get(TWO),category.get(THREE),category.get(FOUR)); + + } } From 31d41ea960318f8040f9b1707a997e7015020cc5 Mon Sep 17 00:00:00 2001 From: jinhyeon Date: Tue, 5 Dec 2023 11:57:36 +0900 Subject: [PATCH 12/12] =?UTF-8?q?feat:=20=EC=B6=94=EC=B2=9C=20=EB=A9=94?= =?UTF-8?q?=EB=89=B4=20=EC=83=9D=EC=84=B1=20=EC=9E=91=EC=84=B1=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/menu/controller/Controller.java | 9 +++--- src/main/java/menu/domain/Menu.java | 28 +++++++++++++++++-- src/main/java/menu/domain/MenuCategory.java | 19 +++++++++---- 3 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/main/java/menu/controller/Controller.java b/src/main/java/menu/controller/Controller.java index 71fdec311..6d296726e 100644 --- a/src/main/java/menu/controller/Controller.java +++ b/src/main/java/menu/controller/Controller.java @@ -1,9 +1,6 @@ package menu.controller; -import menu.domain.ChooseCategory; -import menu.domain.Coach; -import menu.domain.MenuCategory; -import menu.domain.NonPreferredMenu; +import menu.domain.*; import menu.view.InputView; import menu.view.OutputView; @@ -18,8 +15,12 @@ public void run() { ChooseCategory chooseCategory = new ChooseCategory(); chooseCategory.choose(); printCategory(chooseCategory.getCategory()); + Menu menu = new Menu(); + menu.Recommend(chooseCategory.getCategory(),coach.getCoachNames()); } + + private void printCategory(List category) { OutputView.printCategory(category); } diff --git a/src/main/java/menu/domain/Menu.java b/src/main/java/menu/domain/Menu.java index 087b41483..e015a6b48 100644 --- a/src/main/java/menu/domain/Menu.java +++ b/src/main/java/menu/domain/Menu.java @@ -1,5 +1,7 @@ package menu.domain; +import camp.nextstep.edu.missionutils.Randoms; + import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -25,6 +27,28 @@ public class Menu { "피자","파니니")); - - + public void Recommend(List category, List coachNames) { + for(MenuCategory categoryName : category){ + categoryCheck(categoryName); + } + } + + private String categoryCheck(MenuCategory categoryName) { + if(categoryName.equals(MenuCategory.JAPANESE)){ + return Randoms.shuffle(JAPANESE).get(0); + } + if(categoryName.equals(MenuCategory.KOREAN)){ + return Randoms.shuffle(KOREAN).get(0); + } + if(categoryName.equals(MenuCategory.CHINESE)){ + return Randoms.shuffle(CHINESE).get(0); + } + if(categoryName.equals(MenuCategory.ASIAN)){ + return Randoms.shuffle(ASIAN).get(0); + } + if(categoryName.equals(MenuCategory.WESTERN)){ + return Randoms.shuffle(WESTERN).get(0); + } + throw new IllegalArgumentException(); + } } diff --git a/src/main/java/menu/domain/MenuCategory.java b/src/main/java/menu/domain/MenuCategory.java index a66adaa5b..09e823e3b 100644 --- a/src/main/java/menu/domain/MenuCategory.java +++ b/src/main/java/menu/domain/MenuCategory.java @@ -1,9 +1,18 @@ package menu.domain; public enum MenuCategory { - JAPANESE, - KOREAN, - CHINESE, - ASIAN, - WESTERN; + JAPANESE("JAPANESE"), + KOREAN("KOREAN"), + CHINESE("CHINESE"), + ASIAN("ASIAN"), + WESTERN("WESTERN"); + + private final String category; + + MenuCategory(String category) { + this.category = category; + } + public String getCategory() { + return this.category; + } }