diff --git a/src/main/java/menu/Application.java b/src/main/java/menu/Application.java index 6340b6f33..612d63472 100644 --- a/src/main/java/menu/Application.java +++ b/src/main/java/menu/Application.java @@ -1,7 +1,13 @@ package menu; +import menu.controller.PersonController; +import menu.service.MenuService; + public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + MenuService saveMenuService = new MenuService(); + + PersonController personController = new PersonController(saveMenuService); + personController.run(); } } diff --git a/src/main/java/menu/controller/PersonController.java b/src/main/java/menu/controller/PersonController.java new file mode 100644 index 000000000..e760f0a88 --- /dev/null +++ b/src/main/java/menu/controller/PersonController.java @@ -0,0 +1,70 @@ +package menu.controller; + +import menu.model.Menu; +import menu.model.Menus; +import menu.model.People; +import menu.service.MenuService; +import menu.view.InputView; +import menu.view.OutputView; + +import java.util.ArrayList; +import java.util.List; + +public class PersonController { + private final MenuService menuService; + + + public PersonController(MenuService saveMenuService) { + this.menuService = saveMenuService; + } + + public void run() { +// 한식 : 비빔밥, 김밥, ... + Menus menus = saveMenu(); +// 감독 이름 : 신홍규, 김민수, ... + People people = getCoachNames(); + + makeCategory(menus, people); + } + + public Menus saveMenu() { + List menusInput = new ArrayList<>(); + Menus menus = menuService.saveMenu(menusInput); +// OutputView.printMenu(menus); + return menus; + } + + public People getCoachNames() { + String coachNames = InputView.getCoachNames(); + String[] manyCoachNames = coachNames.split(","); + + List cantFoods = InputView.getCantFood(manyCoachNames); + People people = menuService.saveCantFoods(manyCoachNames, cantFoods); +// OutputView.printPeople(people); + return people; + } + + public void makeCategory(Menus menus, People people) { + while (true) { +// 5일 식사 카테고리(한식, 일식 ...) + List category = menuService.makeCategory(); + boolean checkRepeat = menuService.checkCategory(category); + if(checkRepeat) { +// true : 검증 통과 + People peopleForAnswer = menuService.makeMenu(menus, category, people); + boolean checkHateMenu = menuService.checkHateMenu(peopleForAnswer, people); + boolean checkMenuRepeat = menuService.checkMenuRepeat(peopleForAnswer); +// OutputView.printPeople(peopleForAnswer); + + if(checkHateMenu && checkMenuRepeat) { + OutputView.result(peopleForAnswer, category); + break; + } + + } + break; + } + + + } +} diff --git a/src/main/java/menu/model/Menu.java b/src/main/java/menu/model/Menu.java new file mode 100644 index 000000000..f35b46a50 --- /dev/null +++ b/src/main/java/menu/model/Menu.java @@ -0,0 +1,19 @@ +package menu.model; + +public class Menu { + private final String menuCountry; + private final String[] menuNames; + + public Menu(String menuCountry, String[] menuNames) { + this.menuCountry = menuCountry; + this.menuNames = menuNames; + } + + public String getMenuCountry() { + return menuCountry; + } + + public String[] getMenuNames() { + return menuNames; + } +} diff --git a/src/main/java/menu/model/Menus.java b/src/main/java/menu/model/Menus.java new file mode 100644 index 000000000..81f9f4463 --- /dev/null +++ b/src/main/java/menu/model/Menus.java @@ -0,0 +1,29 @@ +package menu.model; + +import java.util.List; + +public class Menus { + + private final List menus; + + public Menus(List menus) { + this.menus = menus; + } + + public void saveMenu(Menu menu) { + menus.add(menu); + } + + public List getMenus() { + return menus; + } + + public Menu getSameMenu(String menuName) { + for (Menu menu : menus) { + if (menu.getMenuCountry().equals(menuName)) { + return menu; + } + } + return null; + } +} diff --git a/src/main/java/menu/model/People.java b/src/main/java/menu/model/People.java new file mode 100644 index 000000000..4bdad30b9 --- /dev/null +++ b/src/main/java/menu/model/People.java @@ -0,0 +1,20 @@ +package menu.model; + +import java.util.List; +import java.util.Map; + +public class People { + private final List people; + + public People(List people) { + this.people = people; + } + + public void savePerson(Person person) { + people.add(person); + } + + public List getPeople() { + return people; + } +} diff --git a/src/main/java/menu/model/Person.java b/src/main/java/menu/model/Person.java new file mode 100644 index 000000000..4be414424 --- /dev/null +++ b/src/main/java/menu/model/Person.java @@ -0,0 +1,20 @@ +package menu.model; + +public class Person { + String name; + String[] cantMenu; + + public Person(String name, String[] cantMenu) { + this.name = name; + this.cantMenu = cantMenu; + } + + public String getPersonName() { + return name; + } + + public String[] getCantFoods() { + return cantMenu; + } + +} diff --git a/src/main/java/menu/service/MenuService.java b/src/main/java/menu/service/MenuService.java new file mode 100644 index 000000000..1feb2ae06 --- /dev/null +++ b/src/main/java/menu/service/MenuService.java @@ -0,0 +1,174 @@ +package menu.service; + +import camp.nextstep.edu.missionutils.Randoms; +import menu.model.Menu; +import menu.model.Menus; +import menu.model.People; +import menu.model.Person; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + + +public class MenuService { + + public Menus saveMenu(List menusInput) { + String[] menuCountries = {"일식", "한식", "중식", "아시안", "양식"}; + String[][] menuNames = { + {"규동", "우동", "미소시루", "스시", "가츠동", "오니기리", "하이라이스", "라멘", "오코노미야끼"}, + {"김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기", "떡볶이", "제육볶음"}, + {"깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육", "토마토 달걀볶음", "고추잡채"}, + {"팟타이", "카오 팟", "나시고렝", "파인애플 볶음밥", "쌀국수", "똠얌꿍", "반미", "월남쌈", "분짜"}, + {"라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티", "피자", "파니니"} + }; + Menus menus = new Menus(menusInput); + + for (int i = 0; i < 5; i++) { + String menuCountry = menuCountries[i]; + Menu menu = new Menu(menuCountry, menuNames[i]); + menus.saveMenu(menu); + } + return menus; + } + + public List makeCategory02() { + List candidate = Arrays.asList("일식", "한식", "중식", "아시안", "양식"); + List category = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + String firstCategory = Randoms.shuffle(candidate).get(0); + category.add(firstCategory); + } + return category; + } + + public List makeCategory() { + List candidate = Arrays.asList("일식", "한식", "중식", "아시안", "양식"); + + candidate.add(0,""); + + List category = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + String firstCategory = candidate.get(Randoms.pickNumberInRange(1,5)); + category.add(firstCategory); + } + return category; + } + + public boolean checkCategory(List category) { + for(String name : category) { + } + for (String categoryItem : category) { + if (Collections.frequency(category, categoryItem) >= 3) { + return false; + } + } + return true; + } + + public People saveCantFoods(String[] coachNames, List cantFoods) { + List person = new ArrayList<>(); + + People people = new People(person); + + for(int i=0; i category, People people) { +// menus : 각 나라에 대한 음식 저장 +// category : 5일간의 식사 카테고리 +// people : 감독 이름과 싫어하는 음식 저장 + + List peopleForAnswer = new ArrayList<>(); + + for (Person person : people.getPeople()) { + String coachName = person.getPersonName(); + String[] eatFoods = new String[5]; + Person personForAnswer = chooseEatMenu(menus, category, person); +// 사람 이름 : 메뉴 5개 목록을 반환받음 + peopleForAnswer.add(personForAnswer); + } + People temp = new People(peopleForAnswer); + + + return temp; + + } + + private Person chooseEatMenu(Menus menus, List category, Person person) { +// 전체 메뉴 저장된 menus +// 5일 카테고리인 category +// 감독 이름과 싫어하는 음식 저장된 person +// 반환을 위해 객체 생성 + List eatFoods = new ArrayList<>(); + String name = person.getPersonName(); + for (String categoryMenu : category) { + Menu sameMenu = menus.getSameMenu(categoryMenu); + String[] sameMenus = sameMenu.getMenuNames(); +// 그 요일에 맞는 요리 목록 가져옴 + String menu = Randoms.shuffle(Arrays.asList(sameMenus)).get(0); + eatFoods.add(menu); + } + + return new Person(name, eatFoods.toArray(new String[0])); + + } + + public boolean checkHateMenu(People peopleForAnswer, People people) { +// people에서 싫어하는 음식 꺼내서 ForAnswer와 대조하기 +// 선택한 음식 5개 중에서 싫어하는 음식 확인 + for (int i = 0; i < people.getPeople().size(); i++) { + return checkFood(peopleForAnswer.getPeople().get(i), people.getPeople().get(i)); + } + return false; + } + + private boolean checkFood(Person person, Person person1) { + String[] candidateFoods = person.getCantFoods(); + String[] cantFoods = person1.getCantFoods(); + for (String candidateFood : candidateFoods) { + for (String cantFood : cantFoods) { + if (candidateFood.equals(cantFood)) { + return false; + } + } + } + return true; + } + + private boolean checkHateFood(Person person, Person person1) { + String[] eatFoods = person.getCantFoods(); + String[] cantFoods = person1.getCantFoods(); + for (String eatFood : eatFoods) { + for (String cantFood : cantFoods) { + if (eatFood.equals(cantFood)) { + return false; + } + } + } + return true; + } + + public boolean checkMenuRepeat(People peopleForAnswer) { + + + for (Person person : peopleForAnswer.getPeople()) { + + List eatFoods = new ArrayList<>(); + + + String[] eatFood = person.getCantFoods(); + for (String s : eatFood) { + if (eatFoods.contains(s)) { + return false; + } + eatFoods.add(s); + } + } + return true; + } +} diff --git a/src/main/java/menu/view/InputView.java b/src/main/java/menu/view/InputView.java new file mode 100644 index 000000000..cf1299768 --- /dev/null +++ b/src/main/java/menu/view/InputView.java @@ -0,0 +1,27 @@ +package menu.view; + +import java.io.Console; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +public class InputView { + public static String getCoachNames() { + System.out.println("점심 메뉴 추천을 시작합니다.\n" + + "코치의 이름을 입력해 주세요. (, 로 구분)"); + Scanner scanner = new Scanner(System.in); + String coachNames = scanner.nextLine(); + return coachNames; + } + + public static List getCantFood(String[] coachNames) { + List cantFoods = new ArrayList<>(); + for (String coachName : coachNames) { + System.out.println(coachName + "(이)가 못 먹는 메뉴를 입력해 주세요."); + Scanner scanner = new Scanner(System.in); + String cantFood = scanner.nextLine(); + cantFoods.add(cantFood.split(",")); + } + return cantFoods; + } +} diff --git a/src/main/java/menu/view/OutputView.java b/src/main/java/menu/view/OutputView.java new file mode 100644 index 000000000..98a501ff8 --- /dev/null +++ b/src/main/java/menu/view/OutputView.java @@ -0,0 +1,49 @@ +package menu.view; + +import menu.model.Menus; +import menu.model.People; +import menu.model.Person; + +import java.util.List; + +public class OutputView { + public static void printMenu(Menus menus) { + for (int i = 0; i < menus.getMenus().size(); i++) { + System.out.println(menus.getMenus().get(i).getMenuCountry()); + for (int j = 0; j < menus.getMenus().get(i).getMenuNames().length; j++) { + System.out.print(menus.getMenus().get(i).getMenuNames()[j]+" "); + } + System.out.println(); + } + } + + public static void printPeople(People people) { + for (int i = 0; i < people.getPeople().size(); i++) { + System.out.println(people.getPeople().get(i).getPersonName()); + for (int j = 0; j < people.getPeople().get(i).getCantFoods().length; j++) { + System.out.print(people.getPeople().get(i).getCantFoods()[j]+" "); + } + System.out.println(); + } + } + + public static void result(People people, List category) { + System.out.println("메뉴 추천 결과입니다.\n" + "[ 구분 | 월요일 | 화요일 | 수요일 | 목요일 | 금요일 ]"); +// [ 카테고리 | 한식 | 한식 | 일식 | 중식 | 아시안 ] + System.out.print("[ 카테고리 "); + for(String name : category) { + System.out.print(" | " + name); + } + System.out.print(" ]"); + System.out.println(); + + for (Person person : people.getPeople()) { + System.out.print(person.getPersonName()); + for (int i = 0; i < category.size(); i++) { + System.out.print(" | " + person.getCantFoods()[i]); + } + System.out.println(); + } + System.out.println("추천을 완료했습니다."); + } +}