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개를 벗어 날때 diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6340b6f33..c4e2c8df2 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -1,7 +1,12 @@ 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..6d296726e --- /dev/null +++ b/src/main/java/menu/controller/Controller.java @@ -0,0 +1,45 @@ +package menu.controller; + +import menu.domain.*; +import menu.view.InputView; +import menu.view.OutputView; + +import java.util.List; + +public class Controller { + + public void run() { + OutputView.welcomeMessage(); + Coach coach = askCoachName(); + NonPreferredMenu nonPreferredMenu = askNonPreferred(coach.getCoachNames()); + 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); + } + + + private NonPreferredMenu askNonPreferred(List coachNames) { + return new NonPreferredMenu(InputView.askNonPreferred(coachNames)); + } + + private Coach askCoachName() { + while (true) { + try { + return new Coach(InputView.askCoachName()); + } catch (IllegalArgumentException e) { + OutputView.printError(e); + } + } + + + } + +} diff --git a/src/main/java/menu/domain/ChooseCategory.java b/src/main/java/menu/domain/ChooseCategory.java new file mode 100644 index 000000000..667db1555 --- /dev/null +++ b/src/main/java/menu/domain/ChooseCategory.java @@ -0,0 +1,54 @@ +package menu.domain; + +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<>(); + private final List choicesCategory = new ArrayList<>(); + + public ChooseCategory() { + map.put(1, JAPANESE); + map.put(2, KOREAN); + 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(); + } + + public List getCategory() { + return this.choicesCategory; + } +} \ No newline at end of file diff --git a/src/main/java/menu/domain/Coach.java b/src/main/java/menu/domain/Coach.java new file mode 100644 index 000000000..4e832de57 --- /dev/null +++ b/src/main/java/menu/domain/Coach.java @@ -0,0 +1,15 @@ +package menu.domain; + +import java.util.List; + +public class Coach { + private final List coachNames; + + public Coach(List coachNames) { + this.coachNames = coachNames; + } + + public List getCoachNames() { + return this.coachNames; + } +} diff --git a/src/main/java/menu/domain/Menu.java b/src/main/java/menu/domain/Menu.java new file mode 100644 index 000000000..e015a6b48 --- /dev/null +++ b/src/main/java/menu/domain/Menu.java @@ -0,0 +1,54 @@ +package menu.domain; + +import camp.nextstep.edu.missionutils.Randoms; + +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("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", + "피자","파니니")); + + + 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 new file mode 100644 index 000000000..09e823e3b --- /dev/null +++ b/src/main/java/menu/domain/MenuCategory.java @@ -0,0 +1,18 @@ +package menu.domain; + +public enum MenuCategory { + 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; + } +} 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/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 new file mode 100644 index 000000000..ba9bc656e --- /dev/null +++ b/src/main/java/menu/view/InputView.java @@ -0,0 +1,36 @@ +package menu.view; + +import camp.nextstep.edu.missionutils.Console; + +import java.util.ArrayList; +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 = "%s (이)가 못 먹는 메뉴를 입력해 주세요.%n"; +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(",")); + 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 new file mode 100644 index 000000000..812064d60 --- /dev/null +++ b/src/main/java/menu/view/OutputView.java @@ -0,0 +1,36 @@ +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()); + } + public static void welcomeMessage(){ + System.out.println(WELCOME_MESSAGE); + } + + 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)); + + } +}