Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiemo0708 #3

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
26 changes: 26 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## 기능 요구 사항

- [ ] 한 주의 메뉴를 추천 박는 서비스이다.

- [ ] 메뉴를 입력 받을 코치를 2~5명 입력받는다.

- [ ] 0~2개의 못먹는 메뉴를 입력 받는다.

- [ ] 한주에 같은 카테고리에서 2번 까지만 메뉴를 추천한다.

- [ ] 각 코치에게 중복되지 않는 메뉴를 추천한다.


- 추천 가능 카테고리
- 일식: 규동, 우동, 미소시루, 스시, 가츠동, 오니기리, 하이라이스, 라멘, 오코노미야끼
한식: 김밥, 김치찌개, 쌈밥, 된장찌개, 비빔밥, 칼국수, 불고기, 떡볶이, 제육볶음
중식: 깐풍기, 볶음면, 동파육, 짜장면, 짬뽕, 마파두부, 탕수육, 토마토 달걀볶음, 고추잡채
아시안: 팟타이, 카오 팟, 나시고렝, 파인애플 볶음밥, 쌀국수, 똠얌꿍, 반미, 월남쌈, 분짜
양식: 라자냐, 그라탱, 뇨끼, 끼슈, 프렌치 토스트, 바게트, 스파게티, 피자, 파니니

- [ ] 추천할 카테고리 랜덤 값이 1 = 일식, 2 = 한식, 3 = 중식, 4= 아시안, 5= 양식을 반환
- [ ] 카테고리 메뉴를 셔플후 첫번째 값을 사용

- 예외 처리
- [ ] 코치가 2~5명의 범위를 벗어 날때
- [ ] 못먹는 메뉴가 0~2개를 벗어 날때
5 changes: 5 additions & 0 deletions src/main/java/menu/Application.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
45 changes: 45 additions & 0 deletions src/main/java/menu/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -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<MenuCategory> category) {
OutputView.printCategory(category);
}


private NonPreferredMenu askNonPreferred(List<String> coachNames) {
return new NonPreferredMenu(InputView.askNonPreferred(coachNames));
}

private Coach askCoachName() {
while (true) {
try {
return new Coach(InputView.askCoachName());
} catch (IllegalArgumentException e) {
OutputView.printError(e);
}
}


}

}
54 changes: 54 additions & 0 deletions src/main/java/menu/domain/ChooseCategory.java
Original file line number Diff line number Diff line change
@@ -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<Integer, MenuCategory> map = new HashMap<>();
private final List<MenuCategory> 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<Integer, MenuCategory> 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<MenuCategory> choices, MenuCategory value) {
return (int) choices.stream()
.filter(choice -> choice.equals(value))
.count();
}

public List<MenuCategory> getCategory() {
return this.choicesCategory;
}
}
15 changes: 15 additions & 0 deletions src/main/java/menu/domain/Coach.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package menu.domain;

import java.util.List;

public class Coach {
private final List<String> coachNames;

public Coach(List<String> coachNames) {
this.coachNames = coachNames;
}

public List<String> getCoachNames() {
return this.coachNames;
}
}
54 changes: 54 additions & 0 deletions src/main/java/menu/domain/Menu.java
Original file line number Diff line number Diff line change
@@ -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<String> JAPANESE =
new ArrayList<>(Arrays.asList("규동", "우동", "미소시루",
"스시", "가츠동","오니기리", "하이라이스", "라멘", "오꼬노미야끼"));
private static final List<String> KOREAN =
new ArrayList<>(Arrays.asList("김밥", "김치찌개", "쌈밥", "된장찌개", "비빔밥", "칼국수", "불고기",
"떡볶이","제육볶음"));

private static final List<String> CHINESE =
new ArrayList<>(Arrays.asList("깐풍기", "볶음면", "동파육", "짜장면", "짬뽕", "마파두부", "탕수육",
"토마토 ","달걀볶음","고추잡채"));

private static final List<String> ASIAN =
new ArrayList<>(Arrays.asList("팟타이", "카오 팟", "나시고렝", "파인애플 볶음밥", "똠얌꿍", "반미", "월남쌈",
"분짜"));

private static final List<String> WESTERN =
new ArrayList<>(Arrays.asList("라자냐", "그라탱", "뇨끼", "끼슈", "프렌치 토스트", "바게트", "스파게티",
"피자","파니니"));


public void Recommend(List<MenuCategory> category, List<String> 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();
}
}
18 changes: 18 additions & 0 deletions src/main/java/menu/domain/MenuCategory.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
14 changes: 14 additions & 0 deletions src/main/java/menu/domain/NonPreferredMenu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package menu.domain;

import java.util.List;

public class NonPreferredMenu {
private final List<List<String>> nonPreferredMenus;
public NonPreferredMenu(List<List<String>> nonPreferredMenus) {
this.nonPreferredMenus = nonPreferredMenus;
}

public List<List<String>> getCoachNames() {
return nonPreferredMenus;
}
}
15 changes: 15 additions & 0 deletions src/main/java/menu/global/Error.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
36 changes: 36 additions & 0 deletions src/main/java/menu/view/InputView.java
Original file line number Diff line number Diff line change
@@ -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<String> askCoachName() {
System.out.printf(INPUT_NAME_MESSAGE);
List<String> coachName = Arrays.asList(Console.readLine().split(","));
validate(coachName);
return coachName;
}
public static List<List<String>> askNonPreferred(List<String> coachNames) {
List<List<String>> 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<String> coachName) {
if(coachName.size()<MIN_COACH||coachName.size()>MAX_COACH){
throw new IllegalArgumentException(NAME_RANGE_OUT.getMessage());
}
}
}
36 changes: 36 additions & 0 deletions src/main/java/menu/view/OutputView.java
Original file line number Diff line number Diff line change
@@ -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<MenuCategory> 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));

}
}