code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,74 @@
+package christmas.domain;
+
+import christmas.domain.event.Event;
+import christmas.domain.event.Giveaway;
+import christmas.domain.menu.Category;
+import christmas.domain.menu.Menu;
+import christmas.dto.MenuCount;
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.util.AbstractMap.SimpleEntry;
+import java.util.Arrays;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class Order {
+ private final Menus menus;
+ private final Date date;
+
+ public Order(Date date, Menus menus) {
+ validateCategory(menus);
+ this.date = date;
+ this.menus = menus;
+ }
+
+ public int getDate() {
+ return date.getDate();
+ }
+
+ public Map<Menu, Integer> getOrderMenu() {
+ return menus.getMenus();
+ }
+
+ private void validateCategory(Menus menus) {
+ if (menus.isAllInCategory(Category.BEVERAGE)) {
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ public int totalAmount() {
+ return menus.totalAmount();
+ }
+
+ public Optional<MenuCount> giveGiveaway() {
+ Giveaway giveaway = (Giveaway) Event.GIVEAWAY.policy();
+ return giveaway.giveGiveaway(date, menus);
+ }
+
+ public Map<Event, Integer> benefitDetails() {
+ return Arrays.stream(Event.values())
+ .map(event -> new SimpleEntry<>(event, event.benefitAmount(date, menus)))
+ .filter(entry -> entry.getValue() < 0)
+ .collect(Collectors.toMap(Entry::getKey, Entry::getValue, (x, y) -> y, LinkedHashMap::new));
+ }
+
+ public int totalBenefit() {
+ return Arrays.stream(Event.values())
+ .mapToInt(event -> event.benefitAmount(date, menus))
+ .sum();
+ }
+
+ public int totalDiscount() {
+ return Arrays.stream(Event.values())
+ .filter(event -> event != Event.GIVEAWAY)
+ .mapToInt(event -> event.benefitAmount(date, menus))
+ .sum();
+ }
+
+ public int finalAmount() {
+ return totalAmount() + totalDiscount();
+ }
+} | Java | ์์์ ๋ง์ํด์ฃผ์ ๋ฐฉ๋ฒ๋๋ก ์ผ๊ธ ์ปฌ๋ ์
์ ๋ง๋ค์๋ค๋ฉด ๊ทธ๋ ๊ฒ ์ฒ๋ฆฌํ ์๋ ์์๊ฒ ๋ค์! ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,33 @@
+package christmas.domain.event;
+
+import christmas.domain.Date;
+import christmas.domain.Menus;
+import christmas.domain.menu.Menu;
+import christmas.dto.MenuCount;
+import java.util.Optional;
+
+public class Giveaway implements EventPolicy {
+ private static final int MIN_TOTAL_AMOUNT = 120_000; //shadowing
+ private static final Menu giveaway = Menu.CHAMPAGNE;
+ private static final int numGiveaway = 1;
+
+ @Override
+ public boolean canBeApplied(Date date, Menus menus) {
+ return menus.totalAmount() >= MIN_TOTAL_AMOUNT;
+ }
+
+ @Override
+ public int amount(Date date, Menus menus) {
+ if (canBeApplied(date, menus)) {
+ return -1 * numGiveaway * giveaway.price();
+ }
+ return NONE;
+ }
+
+ public Optional<MenuCount> giveGiveaway(Date date, Menus menus) {
+ if (canBeApplied(date, menus)) {
+ return Optional.of(new MenuCount(giveaway.description(), numGiveaway));
+ }
+ return Optional.empty();
+ }
+} | Java | ์ ๊ฐ ์ธํฐํ์ด์ค ๊ตฌํ์ ์ต์์น ์์์ ๋จ๊ฒจ๋์๋ ์ฃผ์์
๋๋ค. ์ธํฐํ์ด์ค์ ๊ตฌํ์ฒด๊ฐ ๊ฐ์ ์ด๋ฆ์ ๋ณ์๋ฅผ ์ฌ์ฉํ๋ฉด ๊ตฌํ์ฒด์ ๋ณ์๊ฐ์ผ๋ก shadowing ๋๋ค๋ ๊ฑธ ํ์ํ์ต๋๋ค. |
@@ -0,0 +1,112 @@
+package christmas.controller;
+
+import christmas.domain.Badge;
+import christmas.domain.Date;
+import christmas.domain.Menus;
+import christmas.domain.Order;
+import christmas.domain.event.Event;
+import christmas.dto.DiscountAmount;
+import christmas.dto.MenuCount;
+import christmas.exception.PromotionException;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.List;
+import java.util.Map;
+
+public class PromotionController {
+ private final InputView inputView = new InputView();
+ private final OutputView outputView = new OutputView();
+ private Order order;
+
+ public void run() {
+ this.order = createOrder();
+ showPlan();
+ showBadge();
+ }
+
+ private Order createOrder() {
+ Date date = askVisitDate();
+ while (true) {
+ try {
+ Menus menus = askMenus();
+ return new Order(date, menus);
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Date askVisitDate() {
+ while (true) {
+ try {
+ return new Date(inputView.readVisitDate());
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Menus askMenus() {
+ while (true) {
+ try {
+ List<String> input = inputView.readMenus();
+ Menus menus = new Menus();
+ input.stream()
+ .map(menu -> Parser.parseMenu(menu, "-"))
+ .forEach(menuCount -> menus.add(menuCount.menu(), menuCount.count()));
+ return menus;
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private void showPlan() {
+ outputView.printPlanHeader(order.getDate());
+ showOrder();
+ showTotalAmount();
+ showGiveaway();
+ showBenefitDetails();
+ showTotalBenefit();
+ showFinalAmount();
+ }
+
+ private void showTotalAmount() {
+ outputView.printTotalAmount(order.totalAmount());
+ }
+
+ private void showOrder() {
+ List<MenuCount> menuCounts = order.getOrderMenu().entrySet()
+ .stream()
+ .map(MenuCount::apply)
+ .toList();
+ outputView.printOrder(menuCounts);
+ }
+
+ private void showGiveaway() {
+ outputView.printGiveaway(order.giveGiveaway());
+ }
+
+ private void showBenefitDetails() {
+ Map<Event, Integer> details = order.benefitDetails();
+
+ List<DiscountAmount> discountAmounts = details.entrySet().stream()
+ .map(DiscountAmount::apply)
+ .toList();
+ outputView.printBenefitDetails(discountAmounts);
+ }
+
+ private void showTotalBenefit() {
+ int totalBenefit = order.totalBenefit();
+ outputView.printTotalBenefit(totalBenefit);
+ }
+
+ private void showFinalAmount() {
+ outputView.printFinalAmount(order.finalAmount());
+ }
+
+ private void showBadge() {
+ Badge badge = Badge.fromBenefit(order.totalBenefit());
+ outputView.printBadge(badge.displayName());
+ }
+} | Java | ๋ค๋ฅธ ๋ถ๋ค ๋ณด๋ค๋ณด๋ try-catch์ ๋ํด ํจ์ ์ ๋ค๋ฆญ+ExceptionHandler๋ก ๋ง์ด ์์ฉํ์๋๋ผ๊ตฌ์! ์์ธ ์ฒ๋ฆฌ ํ ๋ค์ ์คํํ๋ ๋ถ๋ถ๋ ๋ถ๋ฆฌ ๊ฐ๋ฅํด ๋ณด์
๋๋ค! |
@@ -0,0 +1,112 @@
+package christmas.controller;
+
+import christmas.domain.Badge;
+import christmas.domain.Date;
+import christmas.domain.Menus;
+import christmas.domain.Order;
+import christmas.domain.event.Event;
+import christmas.dto.DiscountAmount;
+import christmas.dto.MenuCount;
+import christmas.exception.PromotionException;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.List;
+import java.util.Map;
+
+public class PromotionController {
+ private final InputView inputView = new InputView();
+ private final OutputView outputView = new OutputView();
+ private Order order;
+
+ public void run() {
+ this.order = createOrder();
+ showPlan();
+ showBadge();
+ }
+
+ private Order createOrder() {
+ Date date = askVisitDate();
+ while (true) {
+ try {
+ Menus menus = askMenus();
+ return new Order(date, menus);
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Date askVisitDate() {
+ while (true) {
+ try {
+ return new Date(inputView.readVisitDate());
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Menus askMenus() {
+ while (true) {
+ try {
+ List<String> input = inputView.readMenus();
+ Menus menus = new Menus();
+ input.stream()
+ .map(menu -> Parser.parseMenu(menu, "-"))
+ .forEach(menuCount -> menus.add(menuCount.menu(), menuCount.count()));
+ return menus;
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private void showPlan() {
+ outputView.printPlanHeader(order.getDate());
+ showOrder();
+ showTotalAmount();
+ showGiveaway();
+ showBenefitDetails();
+ showTotalBenefit();
+ showFinalAmount();
+ }
+
+ private void showTotalAmount() {
+ outputView.printTotalAmount(order.totalAmount());
+ }
+
+ private void showOrder() {
+ List<MenuCount> menuCounts = order.getOrderMenu().entrySet()
+ .stream()
+ .map(MenuCount::apply)
+ .toList();
+ outputView.printOrder(menuCounts);
+ }
+
+ private void showGiveaway() {
+ outputView.printGiveaway(order.giveGiveaway());
+ }
+
+ private void showBenefitDetails() {
+ Map<Event, Integer> details = order.benefitDetails();
+
+ List<DiscountAmount> discountAmounts = details.entrySet().stream()
+ .map(DiscountAmount::apply)
+ .toList();
+ outputView.printBenefitDetails(discountAmounts);
+ }
+
+ private void showTotalBenefit() {
+ int totalBenefit = order.totalBenefit();
+ outputView.printTotalBenefit(totalBenefit);
+ }
+
+ private void showFinalAmount() {
+ outputView.printFinalAmount(order.finalAmount());
+ }
+
+ private void showBadge() {
+ Badge badge = Badge.fromBenefit(order.totalBenefit());
+ outputView.printBadge(badge.displayName());
+ }
+} | Java | try ๋ด๋ถ์๋ ์๋ฌ๊ฐ ๋ ๊ฐ๋ฅ์ฑ์ด ์๋ ๋ฌธ๊ตฌ์ ๋ํด์ ์ง์ค์ ์ผ๋ก ๊ด๋ฆฌํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. Menu menu = parseMenu() ๋ผ๋ ๊ตฌ๋ฌธ์ ๋ํด์๋ง ์๋ฌ ์ฒ๋ฆฌ๋ฅผ ํ๊ณ , ํต๊ณผ ํ add๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ด๋จ๊น์? |
@@ -0,0 +1,85 @@
+package christmas.domain;
+
+import christmas.domain.menu.Category;
+import christmas.domain.menu.Menu;
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class Menus {
+ public static final int MIN_MENU_COUNT = 1;
+ public static final int MAX_ORDER_COUNT = 20;
+ private final Map<Menu, Integer> menus = new EnumMap<>(Menu.class);
+
+ public Map<Menu, Integer> getMenus() {
+ return menus;
+ }
+
+ public void add(String menu, int count) {
+ validate(menu, count);
+ menus.put(Menu.fromDescription(menu), count);
+ }
+
+ private void validate(String menu, int count) {
+ validateMenuExists(menu);
+ validateMenuNotDuplicated(menu);
+ validateCount(count);
+ validateTotalCount(count);
+ }
+
+ public boolean isAllInCategory(Category category) {
+ return menus.keySet().stream()
+ .map(Menu::category)
+ .allMatch(c -> c.equals(category));
+ }
+
+ public int countByCategory(Category category) {
+ return menus.keySet().stream()
+ .filter(key -> category.equals(key.category()))
+ .mapToInt(menus::get)
+ .sum();
+ }
+
+ public int totalCount() {
+ return menus.values().stream()
+ .mapToInt(Integer::intValue)
+ .sum();
+ }
+
+ public int totalAmount() {
+ return menus.entrySet().stream()
+ .mapToInt(this::itemPrice)
+ .sum();
+ }
+
+ private int itemPrice(Entry<Menu, Integer> item) {
+ return item.getKey().price() * item.getValue();
+ }
+
+ private void validateMenuExists(String menu) {
+ if (Menu.exists(menu)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+
+ private void validateCount(int count) {
+ if (count < MIN_MENU_COUNT) {
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateMenuNotDuplicated(String menu) {
+ if (menus.containsKey(Menu.fromDescription(menu))) {
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+ }
+
+ private void validateTotalCount(int count) {
+ if (totalCount() + count > MAX_ORDER_COUNT) {
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+ }
+} | Java | ๊ฒ์ฆ ๋ก์ง๊ณผ, totalAmount()๋ฑ์ ๋น์ง๋์ค ๋ก์ง์ ๊ด๋ จ์ฑ์ด ๋ฎ์๋ณด์
๋๋ค! ์ด๋ถ๋ถ๋ Parser์ฒ๋ผ validator๋ก ๋ถ๋ฆฌ ๊ฐ๋ฅํด๋ณด์ฌ์ ! |
@@ -0,0 +1,74 @@
+package christmas.view;
+
+import christmas.dto.DiscountAmount;
+import christmas.dto.MenuCount;
+import christmas.exception.PromotionException;
+import java.util.List;
+import java.util.Optional;
+
+public class OutputView {
+
+ public void printPlanHeader(int date) {
+ System.out.printf("12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!\n", date);
+ }
+
+ public void printOrder(List<MenuCount> order) {
+ System.out.println("\n<์ฃผ๋ฌธ ๋ฉ๋ด>");
+ order.forEach(this::printMenuCount);
+ }
+
+ public void printTotalAmount(int amount) {
+ System.out.println("\n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>");
+ printAmount(amount);
+ }
+
+ public void printGiveaway(Optional<MenuCount> giveaway) {
+ System.out.println("\n<์ฆ์ ๋ฉ๋ด>");
+ if (giveaway.isPresent()) {
+ printMenuCount(giveaway.get());
+ return;
+ }
+ printNone();
+ }
+
+ public void printBenefitDetails(List<DiscountAmount> discountAmounts) {
+ System.out.println("\n<ํํ ๋ด์ญ>");
+ if (discountAmounts.isEmpty()) {
+ printNone();
+ return;
+ }
+ discountAmounts.forEach(da -> System.out.printf("%s: %,d์\n", da.name(), da.amount()));
+ }
+
+ public void printTotalBenefit(int totalBenefit) {
+ System.out.println("\n<์ดํํ ๊ธ์ก>");
+ printAmount(totalBenefit);
+ }
+
+ public void printFinalAmount(int finalAMount) {
+ System.out.println("\n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>");
+ printAmount(finalAMount);
+ }
+
+ public void printBadge(String displayName) {
+ System.out.println("\n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+ System.out.println(displayName);
+ }
+
+ public void printErrorMessage(PromotionException e) {
+ System.out.println(e.getMessage());
+ }
+
+
+ private void printNone() {
+ System.out.println("์์");
+ }
+
+ private void printMenuCount(MenuCount menuCount) {
+ System.out.printf("%s %d๊ฐ\n", menuCount.menu(), menuCount.count());
+ }
+
+ private void printAmount(int amount) {
+ System.out.printf("%,d์\n", amount);
+ }
+} | Java | ๊ฐ ์ถ๋ ฅ๋ฌธ์ static final ์์๋ก ์ฒ๋ฆฌํ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,112 @@
+package christmas.controller;
+
+import christmas.domain.Badge;
+import christmas.domain.Date;
+import christmas.domain.Menus;
+import christmas.domain.Order;
+import christmas.domain.event.Event;
+import christmas.dto.DiscountAmount;
+import christmas.dto.MenuCount;
+import christmas.exception.PromotionException;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.List;
+import java.util.Map;
+
+public class PromotionController {
+ private final InputView inputView = new InputView();
+ private final OutputView outputView = new OutputView();
+ private Order order;
+
+ public void run() {
+ this.order = createOrder();
+ showPlan();
+ showBadge();
+ }
+
+ private Order createOrder() {
+ Date date = askVisitDate();
+ while (true) {
+ try {
+ Menus menus = askMenus();
+ return new Order(date, menus);
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Date askVisitDate() {
+ while (true) {
+ try {
+ return new Date(inputView.readVisitDate());
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Menus askMenus() {
+ while (true) {
+ try {
+ List<String> input = inputView.readMenus();
+ Menus menus = new Menus();
+ input.stream()
+ .map(menu -> Parser.parseMenu(menu, "-"))
+ .forEach(menuCount -> menus.add(menuCount.menu(), menuCount.count()));
+ return menus;
+ } catch (PromotionException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private void showPlan() {
+ outputView.printPlanHeader(order.getDate());
+ showOrder();
+ showTotalAmount();
+ showGiveaway();
+ showBenefitDetails();
+ showTotalBenefit();
+ showFinalAmount();
+ }
+
+ private void showTotalAmount() {
+ outputView.printTotalAmount(order.totalAmount());
+ }
+
+ private void showOrder() {
+ List<MenuCount> menuCounts = order.getOrderMenu().entrySet()
+ .stream()
+ .map(MenuCount::apply)
+ .toList();
+ outputView.printOrder(menuCounts);
+ }
+
+ private void showGiveaway() {
+ outputView.printGiveaway(order.giveGiveaway());
+ }
+
+ private void showBenefitDetails() {
+ Map<Event, Integer> details = order.benefitDetails();
+
+ List<DiscountAmount> discountAmounts = details.entrySet().stream()
+ .map(DiscountAmount::apply)
+ .toList();
+ outputView.printBenefitDetails(discountAmounts);
+ }
+
+ private void showTotalBenefit() {
+ int totalBenefit = order.totalBenefit();
+ outputView.printTotalBenefit(totalBenefit);
+ }
+
+ private void showFinalAmount() {
+ outputView.printFinalAmount(order.finalAmount());
+ }
+
+ private void showBadge() {
+ Badge badge = Badge.fromBenefit(order.totalBenefit());
+ outputView.printBadge(badge.displayName());
+ }
+} | Java | Menus ๋ฅผ add ํ๋ฉด์๋ ๊ฒ์ฆํ๋ ๊ณผ์ ์ด ์๊ณ ์๋ชป๋ ๊ฒ์ฆ ๊ฒฐ๊ณผ ์๋ชป๋ ์ฃผ๋ฌธ์ผ ๊ฒฝ์ฐ ๋ค์ ๋ฐ์์ผํด์ ์ด๋ ๊ฒ ๊ตฌํํ์ต๋๋ค. |
@@ -0,0 +1,59 @@
+package christmas.domain.menu;
+
+import static christmas.domain.menu.Category.APPETIZER;
+import static christmas.domain.menu.Category.BEVERAGE;
+import static christmas.domain.menu.Category.DESSERT;
+import static christmas.domain.menu.Category.MAIN;
+
+import java.util.Arrays;
+
+public enum Menu {
+ MUSHROOM_SOUP(APPETIZER, "์์ก์ด์ํ", 6_000),
+ TAPAS(APPETIZER, "ํํ์ค", 5_500),
+ CAESAR_SALAD(APPETIZER, "์์ ์๋ฌ๋", 8_000),
+
+ T_BONE_STEAK(MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
+ BARBECUE_RIBS(MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000),
+ SEAFOOD_PASTA(MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000),
+ CHRISTMAS_PASTA(MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000),
+
+ CHOCOLATE_CAKE(DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000),
+ ICE_CREAM(DESSERT, "์์ด์คํฌ๋ฆผ", 5_000),
+
+ ZERO_COLA(BEVERAGE, "์ ๋ก์ฝ๋ผ", 3_000),
+ RED_WINE(BEVERAGE, "๋ ๋์์ธ", 60_000),
+ CHAMPAGNE(BEVERAGE, "์ดํ์ธ", 25_000);
+
+ private final Category category;
+ private final String description;
+ private final int price;
+
+ Menu(Category category, String description, int price) {
+ this.category = category;
+ this.description = description;
+ this.price = price;
+ }
+
+ public static boolean exists(String description) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(m -> description.equals(m.description()));
+ }
+
+ public static Menu fromDescription(String description) {
+ return Arrays.stream(Menu.values())
+ .filter(m -> description.equals(m.description))
+ .findAny().get();
+ }
+
+ public Category category() {
+ return category;
+ }
+
+ public String description() {
+ return description;
+ }
+
+ public int price() {
+ return price;
+ }
+} | Java | ๋ฆฌ๋ทฐ์ด๋์ ์ฝ๋๋ฅผ ๋ณด๋ ๋ง์ํ์ ๋ฐฉ๋ฒ์ด ํจ์จ์ ์ด๋ค์! ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,42 @@
+package christmas.view;
+
+import static christmas.controller.Parser.parseDate;
+import static christmas.controller.Parser.parseMenus;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.util.List;
+
+public class InputView {
+ private static final String DATE_PATTERN = "[\\d]{1,2}";
+ private static final String MENUS_PATTERN = "(([๊ฐ-ํฃ]+)-([\\d]{1,2}),)*([๊ฐ-ํฃ]+)-([\\d]{1,2})";
+
+ public int readVisitDate() {
+ System.out.println("12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)");
+ String date = Console.readLine();
+ validateDateInput(date);
+ return parseDate(date);
+ }
+
+ private void validateDateInput(String input) {
+ if (input.matches(DATE_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_DATE_MESSAGE);
+ }
+
+ public List<String> readMenus() {
+ System.out.println("์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)");
+ String menus = Console.readLine().trim();
+ validateMenuInput(menus);
+ return parseMenus(menus, ",");
+ }
+
+ private void validateMenuInput(String menus) {
+ if (menus.matches(MENUS_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+} | Java | ์ ๊ท์์ ํ๊ธ๋ ๋๋๊ตฐ์! ๋ฐฐ์๊ฐ์! |
@@ -0,0 +1,18 @@
+package christmas.domain.event;
+
+import christmas.domain.Date;
+import christmas.domain.Menus;
+
+public interface EventPolicy {
+ int MIN_TOTAL_AMOUNT = 10_000;
+ int NONE = 0;
+
+
+ default boolean isApplicableMenus(Menus menus) {
+ return menus.totalAmount() >= MIN_TOTAL_AMOUNT;
+ }
+
+ boolean canBeApplied(Date date, Menus menus);
+
+ int amount(Date date, Menus menus);
+} | Java | ๋ค๋ฅธ ๊ตฌํ์ฒด๋ค ์ฝ๋ ๋ณด๋๊น, amount ๋ฉ์๋ ๋ด๋ถ์์ canBeApplied ๋ฉ์๋๊ฐ ํธ์ถ๋๊ฒ ๋๋๋ฐ ์ด๋ฅผ default ๋ฉ์๋๋, ๊ตฌ์ฒดํด๋์ค์ ์ธํฐํ์ด์ค ์ฌ์ด์ ์ถ์ ํด๋์ค๋ฅผ ์ถ๊ฐํ์ฌ ๊ฐ์ ํ๋ค๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! ํ์ฌ๋ ์ค์๊ฐ ๋ฐ์ํด๋ ๋ง์ ๋ฐฉ๋ฒ์ด ์๊ธฐ ๋๋ฌธ์ด์ฃ ! |
@@ -0,0 +1,53 @@
+package christmas.domain.event;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import christmas.domain.Date;
+import christmas.domain.Menus;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+class DDayDiscountTest {
+ EventPolicy dDayDiscount = new DDayDiscount();
+
+ @DisplayName("10000์ ๋ฏธ๋ง์ธ ๊ฒฝ์ฐ ํ ์ธ ์ ์ฉ๋์ง ์๋๋ค.")
+ @Test
+ void notApplicableOrder() {
+ Menus menus = new Menus();
+ menus.add(("ํํ์ค"), 1);
+
+ assertThat(dDayDiscount.canBeApplied(new Date(25), menus))
+ .isEqualTo(false);
+ assertThat(dDayDiscount.amount(new Date(25), menus))
+ .isEqualTo(0);
+ }
+
+ @DisplayName("ํ ์ธ ๊ธฐ๊ฐ์ด ์๋๋ฉด ์ ์ฉ๋์ง ์๋๋ค.")
+ @ParameterizedTest
+ @CsvSource({"25,true", "26,false"})
+ void notApplicableDate(int dateSource, boolean expected) {
+ assertThat(dDayDiscount.canBeApplied(new Date(dateSource), createMenus()))
+ .isEqualTo(expected);
+ }
+
+ @DisplayName("ํ ์ธ ๊ธ์ก ํ
์คํธ")
+ @ParameterizedTest
+ @CsvSource({"1,-1000", "25,-3400"})
+ void amount(int dateSource, int expectedAmount) {
+ assertThat(dDayDiscount.amount(new Date(dateSource), createMenus()))
+ .isEqualTo(expectedAmount);
+ }
+
+ Menus createMenus() {
+ Menus menus = new Menus();
+ menus.add(("ํํ์ค"), 2);
+ menus.add(("์์ ์๋ฌ๋"), 1);
+ menus.add(("ํด์ฐ๋ฌผํ์คํ"), 2);
+ menus.add(("์ด์ฝ์ผ์ดํฌ"), 1);
+ menus.add(("์ ๋ก์ฝ๋ผ"), 1);
+ menus.add(("์ดํ์ธ"), 1);
+ return menus;
+ }
+} | Java | ๋ชจ๋ ํ
์คํธ ์ฝ๋์์ ์ด ๋ฉ์๋๊ฐ ์กด์ฌํ๋ ๊ฐ์ต๋๋ค. ์ด๋ฅผ ์ถ์ํํด์ ํ
์คํธ์ฝ๋๋ฅผ ์์ฑํ๋ฉด, ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,42 @@
+package christmas.view;
+
+import static christmas.controller.Parser.parseDate;
+import static christmas.controller.Parser.parseMenus;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.util.List;
+
+public class InputView {
+ private static final String DATE_PATTERN = "[\\d]{1,2}";
+ private static final String MENUS_PATTERN = "(([๊ฐ-ํฃ]+)-([\\d]{1,2}),)*([๊ฐ-ํฃ]+)-([\\d]{1,2})";
+
+ public int readVisitDate() {
+ System.out.println("12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)");
+ String date = Console.readLine();
+ validateDateInput(date);
+ return parseDate(date);
+ }
+
+ private void validateDateInput(String input) {
+ if (input.matches(DATE_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_DATE_MESSAGE);
+ }
+
+ public List<String> readMenus() {
+ System.out.println("์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)");
+ String menus = Console.readLine().trim();
+ validateMenuInput(menus);
+ return parseMenus(menus, ",");
+ }
+
+ private void validateMenuInput(String menus) {
+ if (menus.matches(MENUS_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+} | Java | ์ข์ ์ ๊ท์ ํ๋ ๋ฐฐ์๊ฐ๋๋ค!
๊ทผ๋ฐ ์ด๋ ๊ฒ ํ๋ฉด " ๋ฉ๋ด - 2 " ์ด๋ ๊ฒ ๋ฉ๋ด์ด๋ฆ์ด๋ ์ซ์ ์ฌ์ด๋ ์๋ค์ ๊ณต๋ฐฑ์ด ์์ด๋ invalidํ๊ฒ ํ๋ณํ๊ณ ๋ค์ ์
๋ ฅ์ ์๊ตฌํ๋์? |
@@ -0,0 +1,42 @@
+package christmas.view;
+
+import static christmas.controller.Parser.parseDate;
+import static christmas.controller.Parser.parseMenus;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.util.List;
+
+public class InputView {
+ private static final String DATE_PATTERN = "[\\d]{1,2}";
+ private static final String MENUS_PATTERN = "(([๊ฐ-ํฃ]+)-([\\d]{1,2}),)*([๊ฐ-ํฃ]+)-([\\d]{1,2})";
+
+ public int readVisitDate() {
+ System.out.println("12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)");
+ String date = Console.readLine();
+ validateDateInput(date);
+ return parseDate(date);
+ }
+
+ private void validateDateInput(String input) {
+ if (input.matches(DATE_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_DATE_MESSAGE);
+ }
+
+ public List<String> readMenus() {
+ System.out.println("์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)");
+ String menus = Console.readLine().trim();
+ validateMenuInput(menus);
+ return parseMenus(menus, ",");
+ }
+
+ private void validateMenuInput(String menus) {
+ if (menus.matches(MENUS_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+} | Java | ๋งจ์๊ณผ ๋งจ๋ค ๊ธ์๋ ๊ณต๋ฐฑ์ด์์ด๋ ๋์ง๋ง ๋ฉ๋ด์ - ์นด์ดํธ ์ฌ์ด์๋ ๊ณต๋ฐฑ์ ํ์ฉํ์ง์์ต๋๋ค.
๋งจ์๋ค ๊ณต๋ฐฑ์ ์ฃผ์ด์ง ์์์ ๊ณต๋ฐฑ์ด ์๊ธธ๋ ํ์ฉํ์ด์ |
@@ -0,0 +1,302 @@
+# ๐ ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
+
+์ฐํ
์ฝ ์๋น์ ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
์ ์ํ '์ด๋ฒคํธ ํ๋๋' ํ๋ก์ ํธ์
๋๋ค.
+
+๊ณ ๊ฐ์ด ์๋น์ ๋ฐฉ๋ฌธํ ๋ ์ง์ ๋ฉ๋ด๋ฅผ ๋ฏธ๋ฆฌ ์ ํํ๋ฉด ์ฃผ๋ฌธ ๋ฉ๋ด, ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก, ์ฆ์ ๋ฉ๋ด, ํํ ๋ด์ญ, ์ดํํ ๊ธ์ก, ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก, 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ๋ด์ฉ์ ๋ณด์ฌ์ค๋๋ค.
+
+## ๐ ์ฐจ๋ก
+[1. ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ](#-๊ธฐ๋ฅ-์๊ตฌ์ฌํญ)
+
+[2. ๊ธฐ๋ฅ ๋ชฉ๋ก](#-๊ธฐ๋ฅ-๋ชฉ๋ก)
+
+[3. ์ฃผ์ ํด๋์ค์ ๋ฉ์๋](#-์ฃผ์-ํด๋์ค์-๋ฉ์๋)
+
+
+## ๐ ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ
+### ๋ฐฉ๋ฌธํ ๋ ์ง ์ ํ
+ - 1์ด์ 31์ดํ์ ์ซ์๋ง ์
๋ ฅ ๊ฐ๋ฅํ๋ค.
+ - 1 ์ด์ 31 ์ดํ์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ, "[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์." ์ถ๋ ฅํ๋ค.
+
+### ๋ฉ๋ด
+- ๋ฉ๋ด์ ์ข
๋ฅ๋ ์ํผํ์ด์ , ๋ฉ์ธ, ๋์ ํธ, ์๋ฃ๊ฐ ์๋ค.
+- ์ํผํ์ด์
+ - ์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+- ๋ฉ์ธ
+ - ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+- ๋์ ํธ
+ - ์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+- ์๋ฃ
+ - ์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+
+### ๋ฉ๋ด ์ ํ
+ - ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์
๋ ฅํ๋ค. (e.g. "ํํ์ค-1,ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-2")
+ - ๋ฉ๋ด ํ์์ด ์์์ ๋ค๋ฅธ ๊ฒฝ์ฐ, "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅ
+ - ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅํ๋ ๊ฒฝ์ฐ, "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๋ค.
+ - ๋ฉ๋ด์ ๊ฐ์๊ฐ 1 ์ด์์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๋ค.
+ - ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ(e.g. ์์ ์๋ฌ๋-1,์์ ์๋ฌ๋-1), "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๋ค.
+
+### ํํ ํ๋ ์๋ด
+ - ์ฃผ๋ฌธ ๋ฉ๋ด ์๋ด
+ - ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์ถ๋ ฅํ๋ค.
+ ```
+ <์ฃผ๋ฌธ ๋ฉ๋ด>
+ ํํ์ค 1๊ฐ
+ ํด์ฐ๋ฌผํ์คํ 2๊ฐ
+ ๋ ๋์์ธ 2๊ฐ
+ ```
+
+ - ์ด์ฃผ๋ฌธ ๊ธ์ก ์๋ด
+ - ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+ ```
+ <ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>
+ 195,500์
+ ```
+
+ - ์ฆ์ ๋ฉ๋ด ์๋ด
+ - ์ฆ์ ์ฌํญ์ด ์๋ ๊ฒฝ์ฐ "์์" ์ถ๋ ฅํ๋ค.
+ - ์ฆ์ ์๋ ๊ฒฝ์ฐ ์ฆ์ ํ๊ณผ ์ฆ์ ๊ฐ์๋ฅผ ์ถ๋ ฅํ๋ค.
+ ```
+ <์ฆ์ ๋ฉ๋ด>
+ ์ดํ์ธ 1๊ฐ
+ ```
+
+ - ํํ ๋ด์ญ ์๋ด
+ - ์ฌ๋ฌ๊ฐ์ ํํ์ด ์ ์ฉ๋ ์ ์๋ค.
+ - ์ ์ฉ๋ ์ด๋ฒคํธ ๋ด์ญ๋ง ์ถ๋ ฅํ๋ค.
+ - ์ ์ฉ๋ ์ด๋ฒคํธ๊ฐ ํ๋๋ ์๋ค๋ฉด ํํ ๋ด์ญ "์์"์ ์ถ๋ ฅํ๋ค.
+ ```
+ ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -3,400์
+ ํน๋ณ ํ ์ธ: -1,000์
+ ์ฆ์ ์ด๋ฒคํธ: -25,000์
+ ```
+
+ - ์ดํํ ๊ธ์ก ์๋ด
+ - ์ด ํํ ๊ธ์ก์ ํ ์ธ ๊ธ์ก์ ํฉ๊ณ์ ์ฆ์ ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ ํฉํ ๊ธ์ก์ด๋ค.
+ ```
+ <์ดํํ ๊ธ์ก>
+ -29,400์
+ ```
+
+ - ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์๋ด
+ - ์์ ๊ฒฐ์ ๊ธ์ก์ ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํ ์ธ ๊ธ์ก์ ์ ํ ๊ธ์ก์ด๋ค.
+ ```
+ <ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>
+ 199,900์
+ ```
+
+ - 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์๋ด
+ - ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๋ฐ์ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํ๋ค.
+ ```
+ <12์ ์ด๋ฒคํธ ๋ฐฐ์ง>
+ ์ฐํ
+ ```
+
+
+### ์ฃผ๋ฌธ
+- ์๋ฃ๋ง ์ฃผ๋ฌธ ์, ์ฃผ๋ฌธํ ์ ์๋ค.
+- ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ 20๊ฐ ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์๋ค.
+ - (e.g. ์์ ์๋ฌ๋-1, ํฐ๋ณธ์คํ
์ดํฌ-1, ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1, ์ ๋ก์ฝ๋ผ-3, ์์ด์คํฌ๋ฆผ-1์ ์ด๊ฐ์๋ 7๊ฐ)
+
+### ์ด๋ฒคํธ
+- ํ ์ธ
+ - ๋๋ฐ์ด ํ ์ธ
+ - ์ ์ฉ ๊ธฐ๊ฐ : 2023.12.1 ~ 2023.12.25
+ - ํ ์ธ ๋์ : ์ด ์ฃผ๋ฌธ ๊ธ์ก
+ - ํ ์ธ ๊ธ์ก : ๋ ์ง๋ณ ํ ์ธ ๊ธ์ก
+ - 1,000์์ผ๋ก ์์, ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+ - (e.g. ์์์ผ์ธ 12์ 1์ผ์ 1,000์, 25์ผ์ 3,400์ ํ ์ธ)
+ - ํ์ผ ํ ์ธ
+ - ์ ์ฉ ๊ธฐ๊ฐ : 2023.12.1 ~ 2023.12.31 ๋ด ๋งค์ฃผ ์ผ์์ผ ~ ๋ชฉ์์ผ
+ - ํ ์ธ ๋์ : ๋์ ํธ ๋ฉ๋ด ๊ธ์ก
+ - ํ ์ธ ๊ธ์ก : ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+ - (e.g. ๋์ ํธ ๋ ๊ฐ ์ฃผ๋ฌธ ์ 4,046์ ํ ์ธ)
+ - ์ฃผ๋ง ํ ์ธ
+ - ์ ์ฉ ๊ธฐ๊ฐ : 2023.12.1 ~ 2023.12.31 ๋ด ๋งค์ฃผ ๊ธ์์ผ, ํ ์์ผ
+ - ํ ์ธ ๋์ : ๋ฉ์ธ ๋ฉ๋ด
+ - ํ ์ธ ๊ธ์ก : ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+ - ํน๋ณ ํ ์ธ
+ - ์ ์ฉ ๊ธฐ๊ฐ : 2023.12.1 ~ 2023.12.31 ๋ด ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์๋ ๋ ๋ค
+ - ํ ์ธ ๋์ : ์ด ์ฃผ๋ฌธ ๊ธ์ก
+ - ํ ์ธ ๊ธ์ก : 1,000์ ํ ์ธ
+- ์ฆ์
+ - ์ ์ฉ ๊ธฐ๊ฐ : 2023.12.1 ~ 2023.12.31
+ - ์ฆ์ ์กฐ๊ฑด : ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์
+ - ์ฆ์ ํ : ์ดํ์ธ 1๊ฐ
+- ํ ์ธ๊ณผ ์ฆ์ ์ ์ค๋ณต๋ ์ ์๋ค.
+- ๋ชจ๋ ์ด๋ฒคํธ๋ ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์์ผ๋ ์ ์ฉ ๊ฐ๋ฅํ๋ค.
+
+### ์ด๋ฒคํธ ๋ฐฐ์ง
+- ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๋ฐฐ์ง๊ฐ ๋ค๋ฅด๋ค.
+ - ๋ณ : ์ดํํ ๊ธ์ก์ด ์ค์ฒ์ ์ด์
+ - ํธ๋ฆฌ : ์ดํํ ๊ธ์ก์ด 1๋ง์ ์ด์
+ - ์ฐํ : ์ดํํ ๊ธ์ก์ด 2๋ง์ ์ด์
+
+## ๐ ๊ธฐ๋ฅ ๋ชฉ๋ก
+
+### ๋ฐฉ๋ฌธ ๋ ์ง
+- [x] 1~31 ์ค ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์ ํํ ์ ์๋ค.
+ - [x] ์์ธ ์ฒ๋ฆฌ
+ - [x] 1~31์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ "[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๊ณ ๋ค์ ์
๋ ฅ๋ฐ๋๋ค.
+- [x] ์ ํํ ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ๋ฌด์จ ์์ผ์ธ์ง ํ๋ณํ๋ค.
+- [x] ์ ํํ ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ํน์ ๋ ๋ก๋ถํฐ ๋ช๋ฒ์งธ ๋ ์ง์ธ์ง ํ๋ณํ๋ค.
+- [x] ์ ํํ ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ํน์ ๋ ์ง๋ค ์ค ํ๋์ธ์ง ํ๋ณํ๋ค.
+- [x] ์ ํํ ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ํน์ ๊ธฐ๊ฐ์ ํฌํจ๋๋ ์ง ํ๋ณํ๋ค.
+
+### ๋ฉ๋ด ์ ํ
+- [x] ๊ณ ๊ฐ์ ๋ฉ๋ด์ ์กด์ฌํ๋ ๋ฉ๋ด๋ฅผ ์ฃผ๋ฌธํ ์ ์๋ค.
+ - [x] ์ฃผ๋ฌธํ ์ํ์ด ๋ฉ๋ด์ ์กด์ฌํ๋์ง ํ๋จํ๋ค.
+- [x] ์์ธ ์ฒ๋ฆฌ
+ - [x] ๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์
๋ ฅํ๋ ๊ฒฝ์ฐ, "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๊ณ ๋ค์ ์
๋ ฅ๋ฐ๋๋ค.
+ - [x] ์ค๋ณต ๋ฉ๋ด๋ฅผ ์
๋ ฅํ ๊ฒฝ์ฐ(e.g. ์์ ์๋ฌ๋-1,์์ ์๋ฌ๋-1), "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๊ณ ๋ค์ ์
๋ ฅ๋ฐ๋๋ค.
+ - [x] ์ฃผ๋ฌธ ๊ฐ์๊ฐ 1๋ณด๋ค ์์ ๊ฒฝ์ฐ "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๊ณ ๋ค์ ์
๋ ฅ๋ฐ๋๋ค.
+- [x] ์ ํํ ๋ฉ๋ด์ ์ด ๊ฐ์๋ฅผ ๊ตฌํ๋ค.
+- [x] ์ ํํ ๋ฉ๋ด๋ค์ด ๋ชจ๋ ํน์ ์นดํ
๊ณ ๋ฆฌ์ ํด๋นํ๋์ง ๊ตฌํ๋ค.
+- [x] ์ ํํ ๋ฉ๋ด๋ค ์ค ํน์ ์นดํ
๊ณ ๋ฆฌ์ ํด๋นํ๋ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ๊ตฌํ๋ค.
+- [x] ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ๊ตฌํ๋ค.
+
+### ์ฃผ๋ฌธ
+- [x] ์์ธ ์ฒ๋ฆฌ
+ - [x] ์๋ฃ๋ง ์ฃผ๋ฌธ ์ "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๊ณ ๋ค์ ์
๋ ฅ๋ฐ๋๋ค.
+ - [x] ์ฃผ๋ฌธ ๋ฉ๋ด๊ฐ 20๊ฐ "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅํ๊ณ ๋ค์ ์
๋ ฅ๋ฐ๋๋ค.
+- [x] ์ ์ฉ๋ ์ฆ์ ํ์ ๊ตฌํ๋ค.
+- [x] ์ด ํํ ๊ธ์ก์ ๊ตฌํ๋ค.
+- [x] ์ด ํ ์ธ ๊ธ์ก์ ๊ตฌํ๋ค.
+
+### ์ด๋ฒคํธ ์ ์ฉ
+- [x] 10000์ ์ด์์ด๋ฉด ์ด๋ฒคํธ๋ฅผ ์ ์ฉํ๋ค.
+- [x] ์ ์ฉ๋๋ ๋๋ฐ์ด ํ ์ธ ๊ธ์ก์ ๊ตฌํ๋ค.
+- [x] ์ ์ฉ๋๋ ํ์ผ ํ ์ธ ๊ธ์ก์ ๊ตฌํ๋ค.
+- [x] ์ ์ฉ๋๋ ์ฃผ๋ง ํ ์ธ์ ๊ตฌํ๋ค.
+- [x] ์ ์ฉ๋๋ ํน๋ณ ํ ์ธ ๊ธ์ก์ ๊ตฌํ๋ค.
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์์ด๋ฉด ์ฆ์ ํ์ ์ฆ์ ํ๋ค.
+- [x] ์ฆ์ ํ ์ ์ฉ ๊ธ์ก์ ๊ตฌํ๋ค.
+
+### ์ด๋ฒคํธ ๋ฐฐ์ง
+- [x] ์ด ํํ ๊ธ์ก์ ๋ฐ๋ฅธ ๋ฐฐ์ง๋ฅผ ๊ตฌํ๋ค.
+
+### ์
๋ ฅ
+- [x] ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์
๋ ฅ๋ฐ๋๋ค.
+ - [x] ์์ธ ์ฒ๋ฆฌ
+ - [x] ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅํ๊ณ ๋ค์ ์
๋ ฅ๋ฐ๋๋ค.
+- [x] ๋ฉ๋ด๋ฅผ ์
๋ ฅ๋ฐ๋๋ค.
+ - [x] ์์ธ ์ฒ๋ฆฌ
+ - [x] ๋ฉ๋ด์ ๊ฐ์๋ 1 ์ด์์ ์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅ
+ - [x] ๋ฉ๋ด ํ์์ด ์์์ ๋ค๋ฅธ ๊ฒฝ์ฐ, "[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."๋ผ๋ ์๋ฌ ๋ฉ์์ง ์ถ๋ ฅ
+
+### ์ถ๋ ฅ
+- [x] ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅํ๋ค.
+- [x] ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- [x] ์ฆ์ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [x] ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํ๋ค.
+- [x] ํํ ๋ด์ญ์ ์ถ๋ ฅํ๋ค.
+ - [x] ์์ผ๋ฉด "์์"์ ์ถ๋ ฅํ๋ค.
+- [x] ์ดํํ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- [x] 12์ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํ๋ค.
+ - [x] ์์ผ๋ฉด ์์์ ์ถ๋ ฅํ๋ค.
+
+
+## ๐ ์ฃผ์ ํด๋์ค์ ๋ฉ์๋
+<table>
+ <thead>
+ <tr>
+ <th>ํด๋์ค</th></th>
+ <th>์๊ฐ</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td rowspan=2>Date</td>
+ <td>๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์ถ์ํํ ํด๋์ค<br> 1 ~ 31 ์ฌ์ด์ ์ ์๋ง ๊ฐ์ง ์ ์๋ ์๋ฃ๊ตฌ์กฐ </td>
+ </tr>
+ <tr>
+ <td>dayFromDate(int) : ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ํ๋ผ๋ฏธํฐ์ ๋ ์ง๋ก๋ถํฐ ๋ช๋ฒ์งธ ๋ ์ธ์ง ๋ฐํ<br>
+ dayOfWeek(): ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ๋ฌด์จ ์์ผ์ธ์ง ๋ฐํ<br>
+ isIncluded(List<Integer>): ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ํ๋ผ๋ฏธํฐ๋ก ๋ค์ด์จ ๋ ์ง๋ค ์ค ํ๋์ธ์ง ๋ฐํ<br>
+ isInRange(int,int): ๋ฐฉ๋ฌธ๋ ์ง๊ฐ ํ๋ผ๋ฏธํฐ๋ก ๋ค์ด์จ ์ฒซ๋ฒ์งธ ๋ ์ง์ ๋๋ฒ์งธ ๋ ์ง ์ฌ์ด์ ๋ ์ธ์ง ๋ฐํ </td>
+ </tr>
+ <tr>
+ <td rowspan=2>Menus</td>
+ <td>์ ํํ ๋ฉ๋ด๋ค์ ์ถ์ํํ ํด๋์ค<br>๋ฉ๋ดํ์ ๋ฉ๋ด๋ค์ ์ต๋ 20๊ฐ๊น์ง ๋ด์ ์ ์๋ ์๋ฃ๊ตฌ์กฐ</td>
+ </tr>
+ <tr>
+ <td>isAllInCategory(Category): ์ ํํ ๋ฉ๋ด๋ค์ด ๋ชจ๋ ํ๋ผ๋ฏธํฐ๋ก ๋ค์ด์จ ์นดํ
๊ณ ๋ฆฌ์ ๋ฉ๋ด์ธ์ง ๋ฐํ<br>
+ countByCategory(Category): ์ ํํ ๋ฉ๋ด๋ค ์ค ํ๋ผ๋ฏธํฐ๋ก ๋ค์ด์จ ์นดํ
๊ณ ๋ฆฌ์ ํด๋นํ๋ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ๋ฐํ<br>
+ totalCount(): ์ ํํ ๋ฉ๋ด๋ค์ ์ด๊ฐ์๋ฅผ ๋ฐํ<br>
+ totalAmount(): ์ ํํ ๋ฉ๋ด๋ค์ ์ด๊ธ์ก์ ๋ฐํ <br></td>
+ </tr>
+ <tr>
+ <td rowspan=2>Order</td>
+ <td>์ฃผ๋ฌธ์ ์ถ์ํํ ํด๋์ค<br>์๋ฃ๋ง ์ฃผ๋ฌธํ๊ฑฐ๋ 20๊ฐ ๋๋ ์ฃผ๋ฌธ์ ํ์ฉํ์ง ์๋ ์๋ฃ๊ตฌ์กฐ</td>
+ </tr>
+ <tr>
+ <td>benefitDetails(): ์ ํํ ๋ ์ง์ ์ ํํ ๋ฉ๋ด๋ค์ ์ฃผ๋ฌธํ๋ฉด ๋ฐ๊ฒ๋๋ ํดํ ๋ด์ญ ๋ฐํ<br>
+ totalBenefit(): ์ ์ฉ๋๋ ๋ชจ๋ ํํ์ ํฉํ ๊ธ์ก์ ๋ฐํ<br>
+ totalDiscount(): ์ ์ฉ๋๋ ๋ชจ๋ ํ ์ธ์ ํฉํ ๊ธ์ก์ ๋ฐํ<br>
+ finalAmount(): ํ ์ธ ์ ์ฉ ํ ์ค์ ๊ฒฐ์ ํ ๊ธ์ก์ ๋ฐํ<br></td>
+ </tr>
+ </tbody>
+</table>
+
+
+<table>
+ <thead>
+ <tr>
+ <th>๊ตฌ๋ถ</th>
+ <th>ํด๋์ค</th>
+ <th>์๊ฐ</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td rowspan=2>์ธํฐํ์ด์ค</td>
+ <td rowspan=2>EventPolicy</td>
+ <td>์ฆ์ /ํ ์ธ ์ด๋ฒคํธ๋ฅผ ์ถ์ํํ ์ธํฐํ์ด์ค</td>
+ </tr>
+ <tr>
+ <td>isApplicableMenus(Menus): ์ ํํ ๋ฉ๋ด๋ค์ด 10000์ ์ด์์ธ์ง ๋ฐํ<br>
+ canBeApplied(Date, Menus): ์ด๋ฒคํธ ์กฐ๊ฑด์ ๋ง์กฑํ๋ ๋ ์ง/๋ฉ๋ด์ธ์ง ๋ฐํํ๋ ์ถ์๋ฉ์๋<br> amount(Date, Menus): ์ด๋ฒคํธ ์ ์ฉ ๊ธ์ก์ ๋ฐํํ๋ ์ถ์๋ฉ์๋</td>
+ </tr>
+ <tr>
+ <td rowspan=10>๊ตฌํ์ฒด</td>
+ <td rowspan=2>DDayDiscount</td>
+ <td>๋๋ฐ์ด ํ ์ธ์ ์ถ์ํํ ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td>canBeApplied(Date, Menus): ์ ํํ ๋ฉ๋ด๋ค์ด 10000์ ์ด์์ด๋ฉด์ ๋ฐฉ๋ฌธ์ผ์ด 1~25 ์ฌ์ด ์ธ์ง ๋ฐํ<br>
+ amount(Date, Menus): ๋ ์ง์ ๋ฐ๋ผ ์ ์ฉ ๊ฐ๋ฅํ ๋๋ฐ์ด ํ ์ธ ๊ธ์ก ๋ฐํ</td>
+ </tr>
+ <tr>
+ <td rowspan=2>WeekdayDiscount</td>
+ <td>ํ์ผ ํ ์ธ์ ์ถ์ํํ ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td>canBeApplied(Date, Menus): ์ ํํ ๋ฉ๋ด๋ค์ด 10000์ ์ด์์ด๋ฉด์ ๋ฐฉ๋ฌธ์ผ์ด ํ์ผ์ธ์ง ๋ฐํ<br>
+ amount(Date, Menus): ๋์ ํธ ๊ฐ์๋ก ์ ์ฉ ๊ฐ๋ฅํ ํ์ผ ํ ์ธ ๊ธ์ก ๋ฐํ</td>
+ </tr>
+ <tr>
+ <td rowspan=2>WeekendDiscount</td>
+ <td>์ฃผ๋ง ํ ์ธ์ ์ถ์ํํ ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td>canBeApplied(Date, Menus): ์ ํํ ๋ฉ๋ด๋ค์ด 10000์ ์ด์์ด๋ฉด์ ๋ฐฉ๋ฌธ์ผ์ด ์ฃผ๋ง์ธ์ง ๋ฐํ<br>
+ amount(Date, Menus): ๋ฉ์ธ ๋ฉ๋ด๊ฐ์๋ก ์ ์ฉ ๊ฐ๋ฅํ ์ฃผ๋ง ํ ์ธ ๊ธ์ก ๋ฐํ</td>
+ </tr>
+ <tr>
+ <td rowspan=2>SpecialDiscount</td>
+ <td>ํน๋ณ ํ ์ธ์ ์ถ์ํํ ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td>canBeApplied(Date, Menus): ์ ํํ ๋ฉ๋ด๋ค์ด 10000์ ์ด์์ด๋ฉด์ ๋ฐฉ๋ฌธ์ผ์ด ๋ณ๋ฌ๋ฆฐ ๋ ์ธ์ง ๋ฐํ<br>
+ amount(Date, Menus): ์ ์ฉ ๊ฐ๋ฅํ ํน๋ณ ํ ์ธ ๊ธ์ก ๋ฐํ</td>
+ </tr> <tr>
+ <td rowspan=2>Giveaway</td>
+ <td>์ฆ์ ์ด๋ฒคํธ๋ฅผ ์ถ์ํํ ํด๋์ค</td>
+ </tr>
+ <tr>
+ <td>canBeApplied(Date, Menus): ์ ํํ ๋ฉ๋ด๋ค์ด 120000์ ์ด์์ธ์ง ๋ฐํ<br>
+ amount(Date, Menus): ์ ์ฉ๊ฐ๋ฅํ ์ฆ์ ํ ๊ธ์ก์ ๋ฐํ<br>
+ giveGiveaway(Date, Menus): ์ ์ฉ๊ฐ๋ฅํ ์ฆ์ ํ๊ณผ ์ฆ์ ํ ๊ธ์ก์ ๋ฐํ</td>
+ </tr>
+ </tbody>
+</table> | Unknown | ๊ธฐ๋ฅ์ด ์ธ์ธํ๊ณ ์ฃผ์ ํด๋์ค ์ ๋ฆฌ๋์ด ์์ด์ ์ดํดํ๊ธฐ ํธํ์ต๋๋ค.
ํ๋ก์ ํธ ๊ตฌ์กฐ๊ฐ ์ด๋ป๊ฒ ์ด๋ฃจ์ด์ ธ์๋์ง๋ ์์ฑํด์ฃผ์๋ฉด ๋ ์ดํดํ๊ธฐ ์ข์๊ฒ ๊ฐ๋ค์! ๐ |
@@ -0,0 +1,42 @@
+package christmas.view;
+
+import static christmas.controller.Parser.parseDate;
+import static christmas.controller.Parser.parseMenus;
+
+import camp.nextstep.edu.missionutils.Console;
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.util.List;
+
+public class InputView {
+ private static final String DATE_PATTERN = "[\\d]{1,2}";
+ private static final String MENUS_PATTERN = "(([๊ฐ-ํฃ]+)-([\\d]{1,2}),)*([๊ฐ-ํฃ]+)-([\\d]{1,2})";
+
+ public int readVisitDate() {
+ System.out.println("12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)");
+ String date = Console.readLine();
+ validateDateInput(date);
+ return parseDate(date);
+ }
+
+ private void validateDateInput(String input) {
+ if (input.matches(DATE_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_DATE_MESSAGE);
+ }
+
+ public List<String> readMenus() {
+ System.out.println("์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)");
+ String menus = Console.readLine().trim();
+ validateMenuInput(menus);
+ return parseMenus(menus, ",");
+ }
+
+ private void validateMenuInput(String menus) {
+ if (menus.matches(MENUS_PATTERN)) {
+ return;
+ }
+ throw new PromotionException(ErrorMessage.INVALID_ORDER_MESSAGE);
+ }
+} | Java | ๋น๋ก ํ๋ฒ๋ง ์ฐ์ผ ๋ฌธ์ฅ์ด์ฌ๋ ๋ฆฌํํ ๋ง์ด ํธํ๊ณ ๊ฐ๋
์ฑ์ ์ํด ์์๋ก ๋ถ๋ฆฌํ๋ ๊ฒ์ด ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค!
```suggestion
private final static String ASK_ORDER_MESSAGE = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
System.out.println(ASK_ORDER_MESSAGE);
``` |
@@ -1,7 +1,19 @@
package christmas;
+import christmas.back.application.service.ClientService;
+import christmas.back.application.service.MenuOrderService;
+import christmas.front.controller.IOController;
+import christmas.back.controller.PlannerController;
+import christmas.front.view.InputView;
+import christmas.front.view.OutputView;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ var clientService = new ClientService();
+ var menuOrderService = new MenuOrderService();
+ var ioController = new IOController(new InputView(),new OutputView());
+ PlannerController plannerController = new PlannerController(ioController,clientService,menuOrderService);
+ plannerController.startPlanner();
+ plannerController.showOrderResult();
}
} | Java | var๋ฅผ ์ด์ฉํ์ ํน๋ณํ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,102 @@
+package christmas.front.controller;
+
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.order.MenuOrders;
+import christmas.front.view.InputView;
+import christmas.front.view.OutputView;
+import java.util.List;
+import java.util.Map;
+
+public class IOController {
+ private final InputView inputView;
+ public final OutputView outputView;
+
+ public IOController(InputView inputView ,OutputView outputView) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ }
+
+ public Integer getVisitDay() {
+ String givenDate = inputView.readDate();
+ try {
+ InputValidate.numberCheck(givenDate);
+ Integer result = Integer.parseInt(givenDate);
+ InputValidate.dateRangeCheck(result);
+ return result;
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e.getMessage());
+ return getVisitDay();
+ }
+ }
+
+ public MenuOrders readMenuAndAmount() {
+ String order = inputView.readMenuAndAmount();
+ try {
+ MenuOrders orders = new MenuOrders(InputValidate.orderCheck(order));
+ showEventApplyMessaged(orders);
+ return orders;
+ } catch (IllegalArgumentException e) {
+ outputView.printError(e.getMessage());
+ return readMenuAndAmount();
+ }
+ }
+
+ private void showEventApplyMessaged(MenuOrders orders) {
+ if(orders.canNotGetEvent()) {
+ outputView.showEventDenyMessage();
+ outputView.showDelimeterLineInPlanner();
+ }
+ }
+
+ public void showEventDayIntroMessage(Integer visitDay) {
+ outputView.showEventDayIntroMessage(visitDay);
+ }
+
+ public void showOrderCompleteMessage(MenuOrders orders) {
+ outputView.showOrderCompleteMessage(orders);
+ }
+
+ public void showBeforeDisCountMessage(Integer beforeDiscount) {
+ outputView.showBeforeDisCountMessage(beforeDiscount);
+ }
+
+ public void showExtraItemEventMessage(String showExtra) {
+ outputView.showExtraItemEventMessage(showExtra);
+ }
+ public void showEventItemsHeaderMessage(){
+ outputView.showEventItemsHeaderMessage();
+ }
+ public void showTotalDiscountMessage(Integer totalAmount) {
+ outputView.showTotalDiscountMessage(totalAmount);
+ }
+
+ public void showAfterDiscount(Integer money) {
+ outputView.showAfterDiscount(money);
+ }
+
+ public void showEventBadge(String badge) {
+ outputView.showEventBadge(badge);
+ }
+
+ public void showLine() {
+ outputView.showDelimeterLineInPlanner();
+ }
+
+ public void showBenefit(List<Map<EventType,Integer>> benefit) {
+ if(benefit.isEmpty()) {
+ showNoBenefit();
+ return;
+ }
+ benefit.forEach(this::showSingleBenefit);
+ }
+ private void showSingleBenefit(Map<EventType,Integer> benefit){
+ Map.Entry<EventType, Integer> entry = benefit.entrySet().iterator().next();
+ EventType benefitType = entry.getKey();
+ Integer benefitAmount = entry.getValue();
+ outputView.showBenefitByType(benefitType,benefitAmount);
+ }
+
+ public void showNoBenefit() {
+ outputView.showNoEventResult();
+ }
+} | Java | InputValidate.orderCheck(order) ์ด ๋ถ๋ถ์ MenuOrders์ ๋ด๋ถ ์์ฑ์๋ก ์ฎ๊ธฐ๋ ๊ฑด ์ด๋ป๊ฒ ์๊ฐํ์๋์?
์ฃผ๋ฌธ ๋ฉ๋ด๊ฐ ๋ชจ๋ ์๋ฃ์ธ์ง, ์ด ์ฃผ๋ฌธ ๊ฐ์๊ฐ 20๊ฐ๋ฅผ ์ด๊ณผํ๋์ง ๊ฒ์ฆํ๋ ์ฑ
์์ MenuOrders๊ฐ ๋งก๋๊ฒ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,21 @@
+package christmas.back.domain.event.config;
+
+import christmas.back.domain.event.gift.GiftEvent;
+import christmas.back.domain.event.discount.DdayEvent;
+import christmas.back.domain.event.discount.SpecialEvent;
+import christmas.back.domain.event.discount.WeekEvent;
+import christmas.back.domain.event.discount.WeekendEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class EventConfig {
+ public static List<BaseEvent> configEvent() {
+ List<BaseEvent> arr = new ArrayList<>();
+ arr.add(new DdayEvent());
+ arr.add(new SpecialEvent(List.of(3, 10, 17, 24, 25, 31)));
+ arr.add(new WeekendEvent(List.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30)));
+ arr.add(new WeekEvent(List.of(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31)));
+ arr.add(new GiftEvent());
+ return arr;
+ }
+} | Java | ํ์ผ๊ณผ ์ฃผ๋ง์ ๊ตฌ๋ถํ๋ ๋ฐฉ๋ฒ์ ์์ผ์ ์ฌ์ฉํด๋ณด์
จ์ผ๋ฉด ์ข์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
e.g.) ์ ๋ LocalDate ์ getDayOfWeek()๋ฅผ ์ฌ์ฉํ์ต๋๋ค. |
@@ -0,0 +1,33 @@
+package christmas.back.domain.event.discount;
+
+import christmas.back.domain.event.config.BaseEvent;
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.order.MenuOrders;
+import christmas.back.domain.user.model.Client;
+import java.util.HashMap;
+import java.util.Map;
+
+public class DdayEvent extends BaseEvent {
+ private static final Integer D_DAY_BASE_MONEY = 1000;
+ private static final Integer D_DAY_BASE_DAY = 25;
+ @Override
+ public Boolean canGetEvent(Client client , MenuOrders menuOrders) {
+ return client.canGetEventByCheckDDay(D_DAY_BASE_DAY);
+ }
+ @Override
+ public Map<EventType,Integer> getEventBenefit(Client client,MenuOrders menuOrders) {
+ int amount = eventBenefitCalculate(client.getVisitDay());
+ Map<EventType, Integer> benefitMap = new HashMap<>();
+ benefitMap.put(EventType.DDayEvent, amount);
+ return benefitMap;
+ }
+ @Override
+ public void updateClientBenefit(Client client,MenuOrders menuOrders) {
+ client.joinEvent();
+ int benefit = eventBenefitCalculate(client.getVisitDay());
+ client. addBenefitToTotalDiscountAndEventBenefit(benefit);
+ }
+ public Integer eventBenefitCalculate(Integer givenDay){
+ return D_DAY_BASE_MONEY + (givenDay - 1) * 100;
+ }
+} | Java | ๊ธฐ์์ด๋ฉด 1๊ณผ 100๋ ์์๋ก ๋ณ๊ฒฝํ์
๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,33 @@
+package christmas.back.domain.event.discount;
+
+import christmas.back.domain.event.config.BaseEvent;
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.order.MenuOrders;
+import christmas.back.domain.user.model.Client;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SpecialEvent extends BaseEvent {
+ public static final Integer SPECIAL_EVENT_BENEFIT_VALUE = 1000;
+ private final List<Integer> days;
+
+ public SpecialEvent(List<Integer> days) {
+ this.days = days;
+ }
+ @Override
+ public Boolean canGetEvent(Client client, MenuOrders menuOrders) {
+ return days.contains(client.getVisitDay());
+ }
+ @Override
+ public Map<EventType,Integer> getEventBenefit(Client client,MenuOrders menuOrders) {
+ Map<EventType, Integer> benefitMap = new HashMap<>();
+ benefitMap.put(EventType.SpecialEvent,SPECIAL_EVENT_BENEFIT_VALUE);
+ return benefitMap;
+ }
+ @Override
+ public void updateClientBenefit(Client client,MenuOrders menuOrders) {
+ client.joinEvent();
+ client. addBenefitToTotalDiscountAndEventBenefit(SPECIAL_EVENT_BENEFIT_VALUE);
+ }
+} | Java | client. addBenefitToTotalDiscountAndEventBenefit
. ๋ค์์ ๋์ด์ฐ๊ธฐ ์คํ๊ฐ ์์ต๋๋ค! |
@@ -0,0 +1,61 @@
+package christmas.back.domain.menu;
+
+public enum MenuItem {
+
+ APPETIZER_BUTTON_MUSHROOM_SOUP("์ ํผํ์ด์ ", "์์ก์ด์ํ", 6000),
+ APPETIZER_TAPAS("์ ํผํ์ด์ ", "ํํ์ค", 5500),
+ APPETIZER_CAESAR_SALAD("์ ํผํ์ด์ ", "์์ ์๋ฌ๋", 8000),
+
+ MAIN_T_BONE_STEAK("๋ฉ์ธ", "ํฐ๋ณธ์คํ
์ดํฌ", 55000),
+ MAIN_BBQ_RIB("๋ฉ์ธ", "๋ฐ๋นํ๋ฆฝ", 54000),
+ MAIN_SEAFOOD_PASTA("๋ฉ์ธ", "ํด์ฐ๋ฌผํ์คํ", 35000),
+ MAIN_CHRISTMAS_PASTA("๋ฉ์ธ", "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+
+ DESSERT_CHOCO_CAKE("๋์ ํธ", "์ด์ฝ์ผ์ดํฌ", 15000),
+ DESSERT_ICE_CREAM("๋์ ํธ", "์์ด์คํฌ๋ฆผ", 5000),
+
+ BEVERAGE_ZERO_COLA("์๋ฃ", "์ ๋ก์ฝ๋ผ", 3000),
+ BEVERAGE_RED_WINE("์๋ฃ", "๋ ๋์์ธ", 60000),
+ BEVERAGE_CHAMPAGNE("์๋ฃ", "์ดํ์ธ", 25000);
+
+ private final String category;
+ private final String itemName;
+ private final int itemPrice;
+
+ MenuItem(String category, String itemName, int itemPrice) {
+ this.category = category;
+ this.itemName = itemName;
+ this.itemPrice = itemPrice;
+ }
+
+ public static MenuItem getMenuByName(String menuName) {
+ for (MenuItem item : values()) {
+ if (item.getItemName().equals(menuName)) {
+ return item;
+ }
+ }
+ return null;
+ }
+
+ public static boolean isNotMenu(String givenName) {
+ for (MenuItem item : values()) {
+ if (item.getItemName().equals(givenName)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public String getItemName() {
+ return itemName;
+ }
+
+ public int getItemPrice() {
+ return itemPrice;
+ }
+
+} | Java | ๋ถ๋ฅ๋ enum์ผ๋ก ๊ด๋ฆฌํ๋ ๊ฑด ์ด๋ป๊ฒ ์๊ฐํ์๋์?
ํด๋น ๋ถ๋ฅ์ ๋ฉ๋ด๋ฅผ ์ฐพ์ ๋๋ String ๋ฌธ์์ด๋ก ์ฐพ๋ ๊ฒ๋ณด๋จ enum์ผ๋ก ์ ์๋ ๋ถ๋ฅ๋ก ์ฐพ๋๊ฒ ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,37 @@
+package christmas.back.domain.event.discount;
+
+import christmas.back.domain.event.config.BaseEvent;
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.order.MenuOrders;
+import christmas.back.domain.user.model.Client;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class WeekendEvent extends BaseEvent {
+ public static final Integer WEEKEND_EVENT_BENEFIT_VALUE = 2023;
+
+ public WeekendEvent(List<Integer> days) {
+ this.days = days;
+ }
+
+ private final List<Integer> days;
+ @Override
+ public Boolean canGetEvent(Client client, MenuOrders menuOrders) {
+ return days.contains(client.getVisitDay()) & menuOrders.isOrderHaveMenu("๋ฉ์ธ");
+ }
+ @Override
+ public Map<EventType,Integer> getEventBenefit(Client client,MenuOrders menuOrders) {
+ int amount = WEEKEND_EVENT_BENEFIT_VALUE * menuOrders.getValueSumByMenu("๋ฉ์ธ");
+ Map<EventType, Integer> benefitMap = new HashMap<>();
+ benefitMap.put(EventType.WeekendEvent, amount);
+ return benefitMap;
+ }
+ @Override
+ public void updateClientBenefit(Client client,MenuOrders menuOrders) {
+ client.joinEvent();
+ int amount = WEEKEND_EVENT_BENEFIT_VALUE * menuOrders.getValueSumByMenu("๋ฉ์ธ");
+ client.addBenefitToTotalDiscountAndEventBenefit(amount);
+ }
+} | Java | ์ ์ธ ์์๊ฐ ์์ฌ์๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,37 @@
+package christmas.back.domain.event.discount;
+
+import christmas.back.domain.event.config.BaseEvent;
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.order.MenuOrders;
+import christmas.back.domain.user.model.Client;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class WeekendEvent extends BaseEvent {
+ public static final Integer WEEKEND_EVENT_BENEFIT_VALUE = 2023;
+
+ public WeekendEvent(List<Integer> days) {
+ this.days = days;
+ }
+
+ private final List<Integer> days;
+ @Override
+ public Boolean canGetEvent(Client client, MenuOrders menuOrders) {
+ return days.contains(client.getVisitDay()) & menuOrders.isOrderHaveMenu("๋ฉ์ธ");
+ }
+ @Override
+ public Map<EventType,Integer> getEventBenefit(Client client,MenuOrders menuOrders) {
+ int amount = WEEKEND_EVENT_BENEFIT_VALUE * menuOrders.getValueSumByMenu("๋ฉ์ธ");
+ Map<EventType, Integer> benefitMap = new HashMap<>();
+ benefitMap.put(EventType.WeekendEvent, amount);
+ return benefitMap;
+ }
+ @Override
+ public void updateClientBenefit(Client client,MenuOrders menuOrders) {
+ client.joinEvent();
+ int amount = WEEKEND_EVENT_BENEFIT_VALUE * menuOrders.getValueSumByMenu("๋ฉ์ธ");
+ client.addBenefitToTotalDiscountAndEventBenefit(amount);
+ }
+} | Java | menuOrders.getValueSumByMenu("๋ฉ์ธ"); ์ด ๋ค์ ๋ชจํธํ ๊ฒ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์?
๋งฅ๋ฝ์ ํ ์ธ ๊ธ์ก์ผ๋ก ๋ณด์ด๋๋ฐ ๋ช
ํํ๊ฒ ํํํ๋ฉด ๋ ์ข์ง ์์๊น ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,35 @@
+package christmas.back.domain.event.gift;
+
+import christmas.back.domain.event.config.BaseEvent;
+import christmas.back.domain.order.MenuOrders;
+import christmas.back.domain.user.model.Client;
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.menu.MenuItem;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GiftEvent extends BaseEvent {
+ private static final Integer GIFT_EVENT_BENEFIT_VALUE = 25000;
+ private static final Integer DECEMBER_GIFT_EVENT_MIN_MONEY = 120000;
+ public static String getGiftMenu(Client client) {
+ if (client.checkCanGetEvent(DECEMBER_GIFT_EVENT_MIN_MONEY)) {
+ return MenuItem.BEVERAGE_CHAMPAGNE.getItemName();
+ }
+ return "์์";
+ }
+ @Override
+ public Boolean canGetEvent(Client client, MenuOrders menuOrders) {
+ return client.checkCanGetEvent(DECEMBER_GIFT_EVENT_MIN_MONEY);
+ }
+ @Override
+ public Map<EventType, Integer> getEventBenefit(Client client,MenuOrders menuOrders) {
+ Map<EventType, Integer> benefitMap = new HashMap<>();
+ benefitMap.put(EventType.GiftEvent,GIFT_EVENT_BENEFIT_VALUE);
+ return benefitMap;
+ }
+ @Override
+ public void updateClientBenefit(Client client,MenuOrders menuOrders) {
+ client.joinEvent();
+ client.addBenefitToTotalEventAmount(GIFT_EVENT_BENEFIT_VALUE);
+ }
+} | Java | ์ซ์์ ๋จ์๋ณ ๊ตฌ๋ถ์๋ฅผ ๋ฃ์ผ๋ฉด ๊ฐ๋
์ฑ์ด ์ข์์ง ๊ฒ ๊ฐ์ต๋๋ค!
e.g.) 25_000, 120_000 |
@@ -0,0 +1,66 @@
+package christmas.back.domain.order;
+
+import christmas.back.domain.menu.MenuItem;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class MenuOrders {
+ private final Long id;
+ private final Map<MenuItem, Integer> orders;
+
+ private MenuOrders(Long id, Map<MenuItem, Integer> orders) {
+ OrderValidate.checkOrders(orders);
+ this.id = id;
+ this.orders = orders;
+ }
+
+ public MenuOrders(Map<MenuItem, Integer> orders) {
+ this(null, new TreeMap<>(orders));
+ }
+
+ public MenuOrders(Long id, MenuOrders menuOrders) {
+ this(id, menuOrders.orders);
+ }
+
+ public List<Map<String, Integer>> getOrderForMessage() {
+ return orders.entrySet().stream()
+ .map(entry -> {
+ Map<String, Integer> orderMap = new HashMap<>();
+ orderMap.put(entry.getKey().getItemName(), entry.getValue());
+ return orderMap;
+ })
+ .toList();
+ }
+
+ public Integer getTotalAmountBeforeDiscount() {
+ return orders.entrySet().stream()
+ .mapToInt(entry -> entry.getKey().getItemPrice() * entry.getValue())
+ .sum();
+ }
+
+ public boolean isOrderHaveMenu(String menu) {
+ return orders.entrySet().stream()
+ .anyMatch(entry -> entry.getKey().getCategory().equals(menu));
+ }
+
+ public Integer getValueSumByMenu(String menu) {
+ return orders.entrySet().stream()
+ .filter(entry -> entry.getKey().getCategory().equals(menu))
+ .mapToInt(Map.Entry::getValue)
+ .sum();
+ }
+
+ public Boolean canNotGetEvent() {
+ int totalPrice = orders.entrySet().stream()
+ .mapToInt(entry -> entry.getKey().getItemPrice() * entry.getValue())
+ .sum();
+ return totalPrice < 10000;
+ }
+
+ public Long getId() {
+ return id;
+ }
+} | Java | MenuOrders๊ฐ ์ฃผ๋ฌธ ๋ชฉ๋ก์ ๊ด๋ฆฌํ๋ ์ฑ
์ ์ธ์ ์ด๋ฒคํธ ์ฐธ์ฌ ์ฌ๋ถ์ ์ฑ
์๊น์ง ๊ฐ์ง ๊ฒ์ผ๋ก ๋ณด์ด๋๋ฐ ๋ถ๋ฆฌํ๋ ๊ฑด ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -1,7 +1,19 @@
package christmas;
+import christmas.back.application.service.ClientService;
+import christmas.back.application.service.MenuOrderService;
+import christmas.front.controller.IOController;
+import christmas.back.controller.PlannerController;
+import christmas.front.view.InputView;
+import christmas.front.view.OutputView;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ var clientService = new ClientService();
+ var menuOrderService = new MenuOrderService();
+ var ioController = new IOController(new InputView(),new OutputView());
+ PlannerController plannerController = new PlannerController(ioController,clientService,menuOrderService);
+ plannerController.startPlanner();
+ plannerController.showOrderResult();
}
} | Java | ์์กด์ฑ์ ์๊ฐํ์ฌ ๋ช
์์ ์ผ๋ก ๋ฐํ ํด๋ผ์ค๋ฅผ ์ ๋๊ฒ์ ๋จ์ ์ด ์์ด ํผํ๊ณ ์ ํ์ต๋๋ค.
๋ฐํ ํ์
์ด ์ ํ๋ ์๊ฐ์ ๊ฐ๋
์ฑ์ ์ข์์ง์ง๋ง, ํด๋ผ์ค๋ช
์ด ๋ฐ๋๋ฉด ๊ฐ์ด ์์ ํ ๋ฒ์๊ฐ ๋์ด๋๋๊ฒ์ ์๊ฐํ์ต๋๋ค |
@@ -0,0 +1,21 @@
+package christmas.back.domain.event.config;
+
+import christmas.back.domain.event.gift.GiftEvent;
+import christmas.back.domain.event.discount.DdayEvent;
+import christmas.back.domain.event.discount.SpecialEvent;
+import christmas.back.domain.event.discount.WeekEvent;
+import christmas.back.domain.event.discount.WeekendEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class EventConfig {
+ public static List<BaseEvent> configEvent() {
+ List<BaseEvent> arr = new ArrayList<>();
+ arr.add(new DdayEvent());
+ arr.add(new SpecialEvent(List.of(3, 10, 17, 24, 25, 31)));
+ arr.add(new WeekendEvent(List.of(1, 2, 8, 9, 15, 16, 22, 23, 29, 30)));
+ arr.add(new WeekEvent(List.of(3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 24, 25, 26, 27, 28, 31)));
+ arr.add(new GiftEvent());
+ return arr;
+ }
+} | Java | ์ข์ ์์ด๋์ด ๊ฐ์ต๋๋ค ๊ณ ๋ คํ ๋ง ํ๊ฒ ๊ฐ๋ค์ |
@@ -0,0 +1,61 @@
+package christmas.back.domain.menu;
+
+public enum MenuItem {
+
+ APPETIZER_BUTTON_MUSHROOM_SOUP("์ ํผํ์ด์ ", "์์ก์ด์ํ", 6000),
+ APPETIZER_TAPAS("์ ํผํ์ด์ ", "ํํ์ค", 5500),
+ APPETIZER_CAESAR_SALAD("์ ํผํ์ด์ ", "์์ ์๋ฌ๋", 8000),
+
+ MAIN_T_BONE_STEAK("๋ฉ์ธ", "ํฐ๋ณธ์คํ
์ดํฌ", 55000),
+ MAIN_BBQ_RIB("๋ฉ์ธ", "๋ฐ๋นํ๋ฆฝ", 54000),
+ MAIN_SEAFOOD_PASTA("๋ฉ์ธ", "ํด์ฐ๋ฌผํ์คํ", 35000),
+ MAIN_CHRISTMAS_PASTA("๋ฉ์ธ", "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+
+ DESSERT_CHOCO_CAKE("๋์ ํธ", "์ด์ฝ์ผ์ดํฌ", 15000),
+ DESSERT_ICE_CREAM("๋์ ํธ", "์์ด์คํฌ๋ฆผ", 5000),
+
+ BEVERAGE_ZERO_COLA("์๋ฃ", "์ ๋ก์ฝ๋ผ", 3000),
+ BEVERAGE_RED_WINE("์๋ฃ", "๋ ๋์์ธ", 60000),
+ BEVERAGE_CHAMPAGNE("์๋ฃ", "์ดํ์ธ", 25000);
+
+ private final String category;
+ private final String itemName;
+ private final int itemPrice;
+
+ MenuItem(String category, String itemName, int itemPrice) {
+ this.category = category;
+ this.itemName = itemName;
+ this.itemPrice = itemPrice;
+ }
+
+ public static MenuItem getMenuByName(String menuName) {
+ for (MenuItem item : values()) {
+ if (item.getItemName().equals(menuName)) {
+ return item;
+ }
+ }
+ return null;
+ }
+
+ public static boolean isNotMenu(String givenName) {
+ for (MenuItem item : values()) {
+ if (item.getItemName().equals(givenName)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public String getItemName() {
+ return itemName;
+ }
+
+ public int getItemPrice() {
+ return itemPrice;
+ }
+
+} | Java | ์๊ฐ์ด ์์ด ๋ชป ๋ฐ๊พผ.. ์ข์ ์๊ฐ์ธ๊ฒ๊ฐ์์
๊ฐ์ฌํฉ๋๋ค |
@@ -0,0 +1,66 @@
+package christmas.back.domain.order;
+
+import christmas.back.domain.menu.MenuItem;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class MenuOrders {
+ private final Long id;
+ private final Map<MenuItem, Integer> orders;
+
+ private MenuOrders(Long id, Map<MenuItem, Integer> orders) {
+ OrderValidate.checkOrders(orders);
+ this.id = id;
+ this.orders = orders;
+ }
+
+ public MenuOrders(Map<MenuItem, Integer> orders) {
+ this(null, new TreeMap<>(orders));
+ }
+
+ public MenuOrders(Long id, MenuOrders menuOrders) {
+ this(id, menuOrders.orders);
+ }
+
+ public List<Map<String, Integer>> getOrderForMessage() {
+ return orders.entrySet().stream()
+ .map(entry -> {
+ Map<String, Integer> orderMap = new HashMap<>();
+ orderMap.put(entry.getKey().getItemName(), entry.getValue());
+ return orderMap;
+ })
+ .toList();
+ }
+
+ public Integer getTotalAmountBeforeDiscount() {
+ return orders.entrySet().stream()
+ .mapToInt(entry -> entry.getKey().getItemPrice() * entry.getValue())
+ .sum();
+ }
+
+ public boolean isOrderHaveMenu(String menu) {
+ return orders.entrySet().stream()
+ .anyMatch(entry -> entry.getKey().getCategory().equals(menu));
+ }
+
+ public Integer getValueSumByMenu(String menu) {
+ return orders.entrySet().stream()
+ .filter(entry -> entry.getKey().getCategory().equals(menu))
+ .mapToInt(Map.Entry::getValue)
+ .sum();
+ }
+
+ public Boolean canNotGetEvent() {
+ int totalPrice = orders.entrySet().stream()
+ .mapToInt(entry -> entry.getKey().getItemPrice() * entry.getValue())
+ .sum();
+ return totalPrice < 10000;
+ }
+
+ public Long getId() {
+ return id;
+ }
+} | Java | ์ฝ๋ฉํธ ์ ๋ง ๊ฐ์ฌํฉ๋๋ค. ์ฌ์ฉ์์์ ํ๋ณ์ ํ ์ง ์ด๋ฒคํธ์์ ํ๋ณ์ ํ ์ง ๋ง์ ๊ณ ๋ฏผ์ ํ๋ ๋ถ๋ถ์ธ๋ฐ ๋ค์ํ๋ฒ ์๊ฐํด๋ณด๊ฒ ์ต๋๋ค!
๋ถ๋ฆฌ๊ฐ ๋ง๋๊ฒ ๊ฐ๋ค์
๊ฐ์ฌํฉ๋๋ค |
@@ -1,7 +1,19 @@
package christmas;
+import christmas.back.application.service.ClientService;
+import christmas.back.application.service.MenuOrderService;
+import christmas.front.controller.IOController;
+import christmas.back.controller.PlannerController;
+import christmas.front.view.InputView;
+import christmas.front.view.OutputView;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ var clientService = new ClientService();
+ var menuOrderService = new MenuOrderService();
+ var ioController = new IOController(new InputView(),new OutputView());
+ PlannerController plannerController = new PlannerController(ioController,clientService,menuOrderService);
+ plannerController.startPlanner();
+ plannerController.showOrderResult();
}
} | Java | Controller๊ฐ Controller๋ฅผ (๋๋ Service๊ฐ Service๋ฅผ) ์์กดํ๋ ๋ฐฉ์์ ์ผ๋ฐ์ ์ผ๋ก ๊ถ์ฅ๋์ง ์๋ ๊ฒ์ผ๋ก ์๊ณ ์์ต๋๋ค. ๊ฐ์ฅ ํฐ ์ด์ ๊ฐ ๊ท๋ชจ๊ฐ ์ปค์ง๋ฉด ์ํ ์ฐธ์กฐ๊ฐ ์ผ์ด๋ ์ฌ์ง๋ฅผ ๋จ๊ธฐ๊ฒ ๋๊ณ ์ด๋ฅผ ์๋ฐฉํ๋ ค๋ฉด ์๋ก ๊ฐ์ ๊ณ์ธต์ ๋๋ ทํ๊ฒ ๋๋์ด์ผ ํ๋๋ฐ ๋ฐฉ๋ฒ์ด ๋ง๋
์น ์๋ค๋ ์ ์ ์์ต๋๋ค. ์ด ๋ถ๋ถ ์ด๋ป๊ฒ ์๊ฐํ์๋์ง ์๊ฒฌ ๋๋์ด๋ณด๊ณ ์ถ์ด์. |
@@ -0,0 +1,47 @@
+package christmas.back.application.service;
+
+import christmas.back.domain.event.gift.GiftEvent;
+import christmas.back.domain.user.ClientRepository;
+import christmas.back.domain.user.model.Client;
+import christmas.back.infrastructure.repository.ClientRepositoryImpl;
+
+public class ClientService {
+ private final ClientRepository clientRepository;
+
+ public ClientService() {
+ this.clientRepository = new ClientRepositoryImpl();
+ }
+
+ public Client saveClient(Client clientInfo) {
+ Client client = new Client(clientInfo);
+ return clientRepository.save(client);
+ }
+
+ public Client findClientById(Long id) {
+ return clientRepository.findById(id);
+ }
+
+ public Integer getTotalAmountBeforeDiscount(Long clientId) {
+ return findClientById(clientId).getPayment().getTotalPaymentBeforeDiscount();
+ }
+
+ public String getGiftEventMenu(Long clientId) {
+ return GiftEvent.getGiftMenu(findClientById(clientId));
+ }
+
+ public Integer getTotalDiscountAmount(Long clientId) {
+ return findClientById(clientId).getPayment().getTotalDiscountMoney();
+ }
+
+ public Integer getAfterDiscount(Long clientId) {
+ return findClientById(clientId).getPayment().getAfterDiscount();
+ }
+
+ public String getBadgeContent(Long clientId) {
+ return findClientById(clientId).getBadgeContent();
+ }
+
+ public void updateBadge(Long clientId) {
+ findClientById(clientId).applyBadge();
+ }
+} | Java | JPA๋ฅผ ์ฌ์ฉํ ์๋น์ค ๊ณ์ธต์ ๋ณด๋ ๊ฒ ๊ฐ์์ ์ธ์ ๊น์ต๋๋ค. ๋ฉ์๋์ ์๋ฏธ๋ ๊ฐ๊ฒฐํ๊ฒ ์ ๋ฌ๋๋ค์ ๐ |
@@ -0,0 +1,21 @@
+package christmas.back.application.service;
+
+import christmas.back.domain.order.MenuOrders;
+import christmas.back.domain.order.MenuOrdersRepository;
+import christmas.back.infrastructure.repository.MenuOrdersRepositoryImpl;
+
+public class MenuOrderService {
+ private final MenuOrdersRepository menuOrdersRepository;
+
+ public MenuOrderService() {
+ this.menuOrdersRepository = new MenuOrdersRepositoryImpl();
+ }
+
+ public MenuOrders saveOrders(MenuOrders menuOrders) {
+ return menuOrdersRepository.save(menuOrders);
+ }
+
+ public MenuOrders findMenuOrdersById(Long menuOrdersId) {
+ return menuOrdersRepository.findById(menuOrdersId);
+ }
+} | Java | Controller์ Service๋ main ๋ฉ์๋์์ ์์ฑํ์
จ๋๋ฐ Repository๋ง ์๋น์ค์์ ์์ฑํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,36 @@
+package christmas.back.application.usecase;
+
+import christmas.back.application.service.ClientService;
+import christmas.back.application.service.MenuOrderService;
+import christmas.back.domain.event.config.BaseEvent;
+import christmas.back.domain.event.config.EventConfig;
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.order.MenuOrders;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+public class CheckEventAndUpdateClientPayment {
+ private final MenuOrderService menuOrderService;
+ private final ClientService clientService;
+ private final List<BaseEvent> events;
+
+ public CheckEventAndUpdateClientPayment(ClientService clientService,MenuOrderService menuOrderService) {
+ this.events = EventConfig.configEvent();
+ this.menuOrderService = menuOrderService;
+ this.clientService = clientService;
+ }
+ public List<Map<EventType,Integer>> execute(Long clientId) {
+ var client = clientService.findClientById(clientId);
+ List<Map<EventType,Integer>> output = new ArrayList<>();
+ MenuOrders menuOrders = menuOrderService.findMenuOrdersById(client.getMenuOrdersId());
+ events.forEach(event ->{
+ if(event.canGetEvent(client,menuOrders)) {
+ output.add(event.getEventBenefit(client,menuOrders));
+ event.updateClientBenefit(client,menuOrders);
+ }
+ });
+ return output;
+ }
+} | Java | ํค-๊ฐ์ ํ ์์ฉ์ ๋ฆฌ์คํธ ํํ๋ก ๊ตฌ์ฑํ๊ณ ์ ํ์ ๊ฑฐ๋ผ๋ฉด ๋ฌผ๋ก Map๋ ๋ฌผ๋ก ์ข์ง๋ง Entry๋ ์ข์ ์ ํ์ง์ผ ๊ฑฐ๋ผ๊ณ ์๊ฐํฉ๋๋ค. ์ ๋ ์ผ๊ธ๊ฐ์ฒด๋ง์ ์ฌ์ฉํด์ ์ฌ๋ฌ ํค-๊ฐ์ ์ด๋ป๊ฒ ๋ฐํํด์ค ์ง ๊ณ ๋ฏผํ์๋๋ฐ List์ Map์ ํต์งธ๋ก ๋ฃ๋ ๊ฒ์ ๋ญ๋น๋ผ๋ ์๊ฐ์ด ๋ค๋๋ผ๊ตฌ์ |
@@ -0,0 +1,21 @@
+package christmas.back.application.service;
+
+import christmas.back.domain.order.MenuOrders;
+import christmas.back.domain.order.MenuOrdersRepository;
+import christmas.back.infrastructure.repository.MenuOrdersRepositoryImpl;
+
+public class MenuOrderService {
+ private final MenuOrdersRepository menuOrdersRepository;
+
+ public MenuOrderService() {
+ this.menuOrdersRepository = new MenuOrdersRepositoryImpl();
+ }
+
+ public MenuOrders saveOrders(MenuOrders menuOrders) {
+ return menuOrdersRepository.save(menuOrders);
+ }
+
+ public MenuOrders findMenuOrdersById(Long menuOrdersId) {
+ return menuOrdersRepository.findById(menuOrdersId);
+ }
+} | Java | ์์กด์ฑ์ ์๊ฐํ์ฌ ๋ ํฌ์งํ ๋ฆฌ์ ๊ตฌํ์ฒด๋ ์๋น์ค์์ ์์ฑํ๋ ๊ฒ์ผ๋ก ์๊ฐํ์ต๋๋ค. (+ ํ ์ค ๊ฐ๋ฐ ์์ ์ค ๊ณ์ธต๊ฐ์ ์ด๋์ ๋ฐ์ด ๋์ง ์๋๋ค๋ผ๋ ๋ฃฐ์ด ์๊ฐ๋ฌ์ต๋๋ค)
๊ทธ๋๋ ์ปดํฌ๋ํธ ์ค์บ์ ๋ง๋ค์ด์ DI ๋ก ๊ตฌํํ์ผ๋ฉด ๋ ์๋ฒฝํ์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -1,7 +1,19 @@
package christmas;
+import christmas.back.application.service.ClientService;
+import christmas.back.application.service.MenuOrderService;
+import christmas.front.controller.IOController;
+import christmas.back.controller.PlannerController;
+import christmas.front.view.InputView;
+import christmas.front.view.OutputView;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ var clientService = new ClientService();
+ var menuOrderService = new MenuOrderService();
+ var ioController = new IOController(new InputView(),new OutputView());
+ PlannerController plannerController = new PlannerController(ioController,clientService,menuOrderService);
+ plannerController.startPlanner();
+ plannerController.showOrderResult();
}
} | Java | (์ผ๋จ ์ง๋ฌธ์ ๋ฐ์ ๋๋ ์๊ฐ์ ์ ์์ง๋ง ๋ด์ผ๊น์ง ๋ค์ํ๋ฒ ์๊ฐํด๋ณด๊ฒ ์ต๋๋คใ
ใ
)
Front controller ์ ์ญํ ์ ํ๋ ๋์คํจ์ฒ ์๋ธ๋ฆฟ์ด ์๋ค๋ผ๋ ๊ฒ์ ์๊ฐํ์ฌ io ์ปจํธ๋กค๋ฌ์ ๊ฒฝ์ฐ Front ์ ์ฝ๋๋ผ๊ณ ์๊ฐ์ ํ์์ต๋๋ค. ๋ฉ์ธ์ด ๋ ์ดํ๋ฆฌ์ผ์ด์
๋ก์ง์ ๋ด๋นํ๋ ์ปจํธ๋กค๋ฌ์ธ PlannerController ์์ ๋๋ฉ์ธ ๋ชจ๋ธ์ ๋ค๋ฃจ์ง ์๋ IO ์ปจํธ๋กค๋ฌ๋ฅผ ํธ์ถํด๋ ์ํ์ ์ํ ๊ฒ ๊ฐ๋ค๋ผ๊ณ ์๊ฐ์ ํ์ต๋๋ค.(ํด๋ผ์ค ์ด๋ฆ์ ๋ค์ํ๋ฒ ๊ณ ๋ฏผํด๋ณด๊ฒ ์ต๋๋ค !!)
์๋น์ค์ ๊ฒฝ์ฐ ๊ด๋ฆฌํ๋ ๋๋ฉ์ธ์ ์์ญ์ด ์ปค์ง๋ฉด ์ธํฐํ์ด์ค๋ฅผ ํตํ์ฌ ์๋ก ์ฐธ์กฐํ๋ ๋ฐฉ์์ผ๋ก ๊ฐ๋ฐ์ ํ ๊ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
์ํ์ฐธ์กฐ์ ์ค๋ฅ๋ฅผ ๊ฐ์ง์ ์์ง๋ง , ํ๋์ ์๋น์ค์์ ๋ค๋ฅธ ๋๋ฉ์ธ๋ค์ ๋ ํฌ์งํ ๋ฆฌ๋ฅผ ํธ์ถํ๊ฒ ๋๋ฉด ๋๋ฉ์ธ๊ฐ์ ๋ถ๋ฆฌ๊ฐ ๋ ์ด๋ ค์ธ ๊ฒ ๊ฐ๋ค๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๊ณ์ธต๊ฐ์ ๋ถ๋ฆฌ ์ฆ ์ปจํธ๋กค๋ฌ , ์๋น์ค , ๋๋ฉ์ธ ๋ชจ๋ธ , ๋ ํฌ์งํ ๋ฆฌ์ ๊ฒฝ๊ณ๋ฅผ ๋๋๋ ๊ฒ์ ๋์ํ๋ ์
์ฅ์
๋๋ค.
๋๋ฉ์ธ๊ฐ์ ์๋น์ค ๊ณ์ธต์ ๊ฐ์ ๊ณ์ธต์ผ๋ก ์ดํด๋ฅผ ํ์ฌ ๋จ๋ฐฉํฅ์ผ๋ก ํธ์ถํ๋ ์ํฉ์ ๊ด์ฐฎ๋ค๋ผ๊ณ ์๊ฐํฉ๋๋ค.
์ค์ restapi ๋ฅผ ์ง์ํ๋ ์ดํ๋ฆฌ์ผ์ด์
์ ๊ฒฝ์ฐ ์ธ๊ธํด ์ฃผ์ ๊ฒ์ฒ๋ผ ์๋ก ์ปจํธ๋กค๋ฌ ๊ฐ์ ์์กดํ์ง ์๊ณ ๊ฐ๋ฐ์ ํ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,47 @@
+package christmas.back.application.service;
+
+import christmas.back.domain.event.gift.GiftEvent;
+import christmas.back.domain.user.ClientRepository;
+import christmas.back.domain.user.model.Client;
+import christmas.back.infrastructure.repository.ClientRepositoryImpl;
+
+public class ClientService {
+ private final ClientRepository clientRepository;
+
+ public ClientService() {
+ this.clientRepository = new ClientRepositoryImpl();
+ }
+
+ public Client saveClient(Client clientInfo) {
+ Client client = new Client(clientInfo);
+ return clientRepository.save(client);
+ }
+
+ public Client findClientById(Long id) {
+ return clientRepository.findById(id);
+ }
+
+ public Integer getTotalAmountBeforeDiscount(Long clientId) {
+ return findClientById(clientId).getPayment().getTotalPaymentBeforeDiscount();
+ }
+
+ public String getGiftEventMenu(Long clientId) {
+ return GiftEvent.getGiftMenu(findClientById(clientId));
+ }
+
+ public Integer getTotalDiscountAmount(Long clientId) {
+ return findClientById(clientId).getPayment().getTotalDiscountMoney();
+ }
+
+ public Integer getAfterDiscount(Long clientId) {
+ return findClientById(clientId).getPayment().getAfterDiscount();
+ }
+
+ public String getBadgeContent(Long clientId) {
+ return findClientById(clientId).getBadgeContent();
+ }
+
+ public void updateBadge(Long clientId) {
+ findClientById(clientId).applyBadge();
+ }
+} | Java | ๊ธฐํ๊ฐ๋์๋ฉด ์ ํฌ๋ธ ์ฐ์ํํ
ํฌ ์ธ๋ฏธ๋์ ์์กด์ฑ๊ณผ ๊ด๋ จ๋ ์์์ ์ถ์ฒ ๋๋ฆฌ๊ณ ์ถ์ต๋๋ค .
์๋ ์ ๋ช
ํ ์์์ด๋ผ ์ด๋ฏธ ๋ณด์
จ์ ์ ์์ง๋ง , ๋จ์ํ๊ฒ ์ ์ง๋ณด์์ ์ธก๋ฉด์ ๋๋ฉ์ธ์ ๋ถ๋ฆฌํ๋ ์ค๊ณ์ ์ค์์ฑ๋ฟ๋ง ์๋๋ผ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ์ฐ๊ด์ ๋ํ ์ค๋ช
๋ ํฌํจํ๋ ๋ด์ฉ์ด ์์ต๋๋ค :) |
@@ -0,0 +1,36 @@
+package christmas.back.application.usecase;
+
+import christmas.back.application.service.ClientService;
+import christmas.back.application.service.MenuOrderService;
+import christmas.back.domain.event.config.BaseEvent;
+import christmas.back.domain.event.config.EventConfig;
+import christmas.back.domain.event.config.EventType;
+import christmas.back.domain.order.MenuOrders;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+
+public class CheckEventAndUpdateClientPayment {
+ private final MenuOrderService menuOrderService;
+ private final ClientService clientService;
+ private final List<BaseEvent> events;
+
+ public CheckEventAndUpdateClientPayment(ClientService clientService,MenuOrderService menuOrderService) {
+ this.events = EventConfig.configEvent();
+ this.menuOrderService = menuOrderService;
+ this.clientService = clientService;
+ }
+ public List<Map<EventType,Integer>> execute(Long clientId) {
+ var client = clientService.findClientById(clientId);
+ List<Map<EventType,Integer>> output = new ArrayList<>();
+ MenuOrders menuOrders = menuOrderService.findMenuOrdersById(client.getMenuOrdersId());
+ events.forEach(event ->{
+ if(event.canGetEvent(client,menuOrders)) {
+ output.add(event.getEventBenefit(client,menuOrders));
+ event.updateClientBenefit(client,menuOrders);
+ }
+ });
+ return output;
+ }
+} | Java | ๋ง์ง๋ง์ ์๋ฃ๊ตฌ์กฐ์ ๋ํ์ฌ ๊ณ ๋ฏผ์ ํ๋ ๋ถ๋ถ์ธ๋ฐ ํผ๋๋ฐฑ ์ ๋ง ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | ```javascript
import ClickMeButton from './components/ClickMeButton';
import NumberButtons from './components/NumberButtons';
```
์ด๋ ๊ฒ ํ์ฅ์ ์์ด ์์ฑํด ๋ณด์ธ์ |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | handlerํจ์์ ์ด๋ฆ๊ณผ ์ปดํฌ๋ํธ์ ์์ฑ ์ด๋ฆ์ ๋๊ฐ์ด ๋ง์ถฐ์ฃผ์ ๊ฒ ๊ฐ์์.
ํธ๋ค๋ฌ ํจ์์ `handle*`์ด๋ผ๊ณ ์ด๋ฆ์ ๋ถ์ด๋ ์ด์ ๋ ํน์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์ ๋ ๊ทธ ์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ๋ ํจ์์ด๊ธฐ ๋๋ฌธ์
๋๋ค.
```jsx
function handleClick() {
alert('๋ฒํผ์ด ํด๋ฆญ๋์ด์!');
}
<Button onClick={handleClick} />
```
์์ ์์ ๋ฅผ ๋ณด๋ฉด ๋ณด๋ฉด `Click ํ์ ๋ handleClick์ด ์ฒ๋ฆฌํ๋ค` ๋ผ๊ณ ์ฝ์ ์ ์์ต๋๋ค. ๊ทธ๋์ ์ด๋ฒคํธ ์ฒ๋ฆฌ ํจ์๋ฅผ ์ปดํฌ๋ํธ๋ก ์ ๋ฌํ ๋๋ on์ผ๋ก ์์ํ๋ ์ด๋ฆ์ผ๋ก ์ ๋ฌํฉ๋๋ค. |
@@ -0,0 +1,9 @@
+import React from 'react';
+
+export default function ClickMeButton({ counterNumber, onClick, number }) {
+ return (
+ <button type="button" onClick={() => onClick({ number })}>
+ Click me ({counterNumber})
+ </button>
+ );
+} | Unknown | ๋ฒํผ์ ํด๋ฆญํ์ ๋ 1์ฉ ์ฆ๊ฐํด์ `{ number: 1}`๋ก ์ ๋ฌํ๊ณ ์๋ค์. ๋ง์ฝ์ 1์ฉ ์ฆ๊ฐํ๋ ๊ฒ์ด ์๋๋ผ 2์ฉ ์ฆ๊ฐํ๋๋ก ๋ณ๊ฒฝํ๋ค๋ฉด ์ด ์ปดํฌ๋ํธ๋ฅผ ๋ณ๊ฒฝํด์ค์ผ๊ฒ ์ต๋๋ค.
๋ง์ฝ ์ด๋ฌํ ๋ก์ง์ ์ธ๋ถ์์ ๋ณ๊ฒฝํ ์ ์๋๋ก ํ๋ ค๋ฉด ์ด๋ป๊ฒ ํด์ผ ํ ๊น์ |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | <img width="406" alt="แแ
ณแแ
ณแ
แ
ตแซแแ
ฃแบ 2023-05-12 แแ
ฉแแ
ฎ 7 00 47" src="https://github.com/CodeSoom/react-week2-assignment-1/assets/103479322/dc146c47-9a01-4296-8d1d-357ee875bf9f">
ํ์ฅ์๋ฅผ ์ง์๋ ๋๊ฐ์ด ๋ฌธ์ ๊ฐ ๋ฐ์ํฉ๋๋ค! |
@@ -0,0 +1,9 @@
+import React from 'react';
+
+export default function ClickMeButton({ counterNumber, onClick, number }) {
+ return (
+ <button type="button" onClick={() => onClick({ number })}>
+ Click me ({counterNumber})
+ </button>
+ );
+} | Unknown | ` <ClickMeButton
counterNumber={counterNumber}
onClick={handlerClickButton}
whatNumberToAdd={1}
/>`
` return (
<button type="button" onClick={() => onClick({ number: whatNumberToAdd })}>
Click me ({counterNumber})
</button>
);`
์ด๋ฐ์์ผ๋ก ์ปดํฌ๋ํธ ์์ฑํ ๋ whatNumberToAdd๋ผ๋ ๊ฐ๋ props๋ก ๋๊ฒจ์ฃผ๊ณ
์ค์ clickํ ๋๋ ํด๋น props์ ๊ฐ์ ๋๊ฒจ์ฃผ๋ ํํ๋ก ํด๋ดค์ต๋๋ค!
์ด๋ ๊ฒ ๋๋ฉด ์์ ์ปดํฌ๋ํธ์์ ๋ค์ด๊ฐ๋ ๋ณ์๋ ํ๋๋ ์์ด ์ ๋ฌ๋ฐ์ ๊ฐ๋ง ๋ณด์ฌ์ฃผ๊ณ ,
๋ชจ๋ ๋ถ๋ชจ ์ปดํฌ๋ํธ์์ ํธ๋ค๋งํ๊ธฐ ๋๋ฌธ์ ๊ด์ฌ์ฌ๊ฐ ๋ถ๋ฆฌ๋ ์ฝ๋๋ผ๊ณ ์๊ฐํฉ๋๋ค! ๐ |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | ํธ๋ค๋ฌ ํจ์์ handle*์ด๋ผ๊ณ ์ด๋ฆ์ ๋ถ์ด๋ ์ด์ ๋ ํน์ ์ด๋ฒคํธ๊ฐ ๋ฐ์ํ์ ๋ ๊ทธ ์ด๋ฒคํธ๋ฅผ ์ฒ๋ฆฌํ๋ ํจ์๋ผ๋ ๋งฅ๋ฝ์ ์ดํด๊ฐ ๋์๊ณ , ๊ทธ๋์ on์ผ๋ก ์์ํ๋ ์ด๋ฆ์ผ๋ก ์ ๋ฌํ๋ ์๋ฏธ๋ ์ดํด๋ ๋์์ต๋๋ค!
๊ทธ๋ฐ๋ฐ ์์ ๊ฒฝ์ฐ์์ ์์์์์์ handleClick์ด๋ผ๋ ํจ์๋ฅผ ์ธ ๋๋ ์๋์ ๊ฐ์ด ์ฌ์ฉํ๊ฒ ๋ ๊ฒ ๊ฐ์๋ฐ์!
```
<button onClick={()=>onClick()} ></button>
```
์ด๋ ๊ฒ ๋ ๊ฒฝ์ฐ์๋ onClick์ด๋ผ๋ ๊ฒ์ onClick์ผ๋ก ์ ๋ฌ๋ฐ์ ํจ์๋ฅผ ์คํํ๋ค๋ ์๋ฏธ์ธ๋ฐ
์ ๊ฐ ๋ดค์ ๋๋ onClick์ ํ์ ๋ onClickํจ์๋ฅผ ์คํํ๋ค๋๊ฒ ์คํ๋ ค ์ด์ํ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ๋ ๋ค์ด์์๐ฅฒ
๊ทธ๋ผ์๋ on์ผ๋ก ์์ํ๋ ์ด๋ฆ์ผ๋ก ์ ๋ฌํด์ฃผ๋ ๊ฒ์ด๋ค๋ผ๋ ์๋ฏธ๋ฅผ ๊ฐ์กฐํ๋ ๋ชฉ์ ์ด ๋ ํฌ๋ ์ด๋ ๊ฒ ์ฐ๋๊ฒ ๋ ๋์ ๋ฐฉ์์ด๋ผ๊ณ ์ดํดํ๋ฉด ๋ ๊น์? |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | https://baeharam.netlify.app/posts/lint/Lint-ESLint-+-Prettier-%EC%84%A4%EC%A0%95%ED%95%98%EA%B8%B0
```
"rules": {
"react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx"] }]
}
```
eslint-plugin-react ์ค์น ์ฌ๋ถ๋ฅผ ์ฒดํฌํ๊ณ ์์ ๋ฃฐ์ ์ถ๊ฐ๋ก ๊ธฐ์
ํด์ฃผ๋ฉด ํด๊ฒฐ๋๋ค๋ ์ฌ๋ก๋ ์์ด์
ํด๋ดค๋๋ฐ ์ด ์ญ์๋ ์๋๋ค์ ๐ฅบ |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | ํด๋น ์ปดํฌ๋ํธ์์ onClick์ด๋ผ๋ ์ด๋ฆ์ผ๋ก ํจ์๋ฅผ ์คํํ๋ ์ด์ํ๊ฒ ๋๊ปด์ง ์ ์๊ฒ ๋ค์. ์ฌ์ฉํ๋ ์ปดํฌ๋ํธ์์ ์ฌ์ฉํ๋๊ฒ ์ด์ํ๊ฒ ๋๊ปด์ง์ ๋ค๋ฉด ์ด๋ฆ์ ๋ฐ๊ฟ์ ์ฌ์ฉํ ์ ์๊ธด ํ๊ฒ ๋ค์.
```javascript
const ButtonComponent = ({ onClick: handleClick }) => {
return (
<button onClick={handleClick}></button>
);
};
```
์ ๋ ์ปดํฌ๋ํธ๋ฅผ ์ฐ๋ ์
์ฅ์์ ์ดํดํ๊ธฐ ์ข์ ์ด๋ฆ์ด์ด์ผ ํ๋ค๋ ์๊ฐ๋๋ฌธ์ ๊ทธ๋ฌ๋ ๊ฒ ๊ฐ์ต๋๋ค ใ
ใ
|
@@ -0,0 +1,9 @@
+import React from 'react';
+
+export default function ClickMeButton({ counterNumber, onClick, number }) {
+ return (
+ <button type="button" onClick={() => onClick({ number })}>
+ Click me ({counterNumber})
+ </button>
+ );
+} | Unknown | ๋ณ๋์ ์์ฑ์ ๋ฃ์ด์ ๊ฐ์ ๋ช์ฉ ๋ํ ์ง ๋ณ๊ฒฝํ ์ ์๊ฒ ๋ค์ ใ
ใ
์ข์ต๋๋ค. ์ ๋ ํธ๋ค๋ฌ ํจ์๋ฅผ ์ธ๋ถ์์ ์ ๋ฌํ๊ณ ์ปดํฌ๋ํธ์์๋ ๋จ์ํ ์คํ๋ง ํ๋๋ก ํ๋ ๊ฒ์ ์๊ฐํด ๋ณด์์ด์
```javascript
const handleClickMeButton = () => {
setCounerNumber(counterNumber + 10);
}
return (
<ClickMeButton>
counterNumber={counterNumber}
onClick={handleClickMeButton}>
</ClickMeButton>
)
//
export default function ClickMeButton({ counterNumber, onClick }) {
return (
<button type="button" onClick={onClick}>
Click me (
{counterNumber}
)
</button>
);
}
``` |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | ์ํ! ์ ์ํด์ฃผ์ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ธ๊ฒ๊ฐ์์!
์ญ์ ์ด๋ฆ ์ง๋ ๊ฑด ์ฐธ ์ด๋ ค์ด์ผ์ด๋ค์ ใ
ใ
๊ฐ์ฌํฉ๋๋ค :) ใ
ใ
|
@@ -0,0 +1,9 @@
+import React from 'react';
+
+export default function ClickMeButton({ counterNumber, onClick, number }) {
+ return (
+ <button type="button" onClick={() => onClick({ number })}>
+ Click me ({counterNumber})
+ </button>
+ );
+} | Unknown | ์ํ! ์ข์ ๊ฒ ๊ฐ์์ :)
์ ๊ฐ์ ๊ฒฝ์ฐ์๋ handleClickButton์ด๋ผ๋ ํธ๋ค๋ฌํจ์๋ฅผ clickmebutton ์ปดํฌ๋ํธ์ numberbutton์ ๊ณตํต์ผ๋ก ์ฌ์ฉ๋๋ ํจ์๋ก ๋๊ณ ์ถ์์ด์!
์ด์ ๋ ๋ ๋ค ํน์ ๊ฐ์ ๋ํด์ ๋ฑ์ด์ฃผ๋ ์ญํ ์ ํ๊ธฐ ๋๋ฌธ์ ๊ตณ์ด ๊ฐ๊ฐ์ ํธ๋ค๋ฌ ํจ์๋ฅผ ๋ง๋ค๊ณ ์ถ์ง ์์์ต๋๋ท!
๊ทธ๋์ ๊ฐ์ ํธ๋ค๋ฌ ํจ์๋ฅผ ์ฐ๊ณ , ๋ํด์ฃผ๋ ๊ฐ๋ง ์ฌ์ฉ๋๋ ์ปดํฌ๋ํธ์ ์ธ์๋ก ๋ฃ์ด์ฃผ๋ฉด ์ข์ง ์์๊น ์๊ฐํด์ ์ฌ์ฉํ์ต๋๋คใ
ใ
ํผ๋๋ฐฑํด์ฃผ์
์ ๊ฐ์ฌํด์ :) |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | ์์ฑ๋ช
์ ์์ฃผ ์์ธํ ์์ฑํด ์ฃผ์
จ๋ค์. ๊ทธ๋ฌ๋ค๋ณด๋ ์ปดํฌ๋ํธ๊ฐ ์ด๋ค ์ผ์ ํ๋์ง๋ฅผ ๋ณ์๋ช
์๋ ๋๋ฌ๋ฌ๋ค์. ์ฃผ์ด์ง ๊ฐ์ผ๋ก ๋ํ๋ค๋ ์ฌ์ค์ ๋ฐ๋ก ์์์ ์ข์ ์๋ ์์ง๋ง ์ด๊ฑด ๋จ์ ์ด ๋ ์๋ ์์ต๋๋ค. ์ฐ๋ฆฌ๊ฐ ์ด ์ปดํฌ๋ํธ์๊ฒ ๋งก๊ธฐ๋ ๊ฒ์ ๋จ์ํ ๊ฐ์ด๊ณ ์ด ๊ฐ์ผ๋ก ๋ฌด์์ ํ ์ง๋ ์ด ์ปดํฌ๋ํธ๋ง ์๊ณ ์์ด์ผ ํฉ๋๋ค. ์ด๊ฒ ์บก์ํ์
๋๋ค.
์กฐ๊ธ ์ต์ง์ผ์๋ ์์ง๋ง ๋ง์ฝ ์ฃผ์ด์ง ๊ฐ์ ์ ๊ณฑ์ผ๋ก ๋ํ๊ธฐ๋ก ํ๋ค๊ณ ํฉ์๋ค. ๊ทธ๋ฌ๋ฉด ์ด ์์ฑ์ ์ด๋ฆ๋ ๋ฐ๋์ด์ผ ํ ๊ฑฐ์์. |
@@ -0,0 +1,24 @@
+import React, { useState } from 'react';
+import ClickMeButton from './components/ClickMeButton';
+import NumberButtons from './components/NumberButtons';
+
+export default function App() {
+ const [counterNumber, setCounterNumber] = useState(0);
+
+ function handlerClickButton({ number }) {
+ setCounterNumber(counterNumber + number);
+ }
+
+ return (
+ <div>
+ <p>Counter</p>
+ <ClickMeButton
+ counterNumber={counterNumber}
+ onClick={handlerClickButton}
+ number={1}
+ />
+ <br />
+ <NumberButtons onClick={handlerClickButton} />
+ </div>
+ );
+} | Unknown | ๊ฐ์ฌํฉ๋๋ค :) ๋๋ถ์ ์ถ์ํ๋ฅผ ํญ์ ์ ๋
ํ๋ฉด์ ์ฝ๋๋ฅผ ์ง๊ฒ ๋๋ ๊ฒ ๊ฐ์์!
์์ฑ๋ช
์ number๋ก ๋ณ๊ฒฝํด์ ํด๋น ์ปดํฌ๋ํธ์์๋ง ๋ช
ํํ ์ญํ ์ ์๊ฒ ์์ ํ์ต๋๋ค! |
@@ -0,0 +1,58 @@
+package lotto.domain;
+
+import static lotto.global.Error.DUPLICATED;
+import static lotto.global.Error.INVALID_SIZE;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validateSize(numbers);
+ validateDuplicated(numbers);
+ validateNumberRange(numbers);
+ this.numbers = numbers;
+ }
+
+ private void validateSize(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(INVALID_SIZE.getMessage());
+ }
+ }
+
+ private void validateDuplicated(List<Integer> numbers) {
+ if (numbers.stream()
+ .distinct().count() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATED.getMessage());
+ }
+ }
+
+ private void validateNumberRange(List<Integer> numbers) {
+ numbers.forEach(Number::new);
+ }
+
+ // TODO: ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
+ public WinningResult checkWinningResult(WinningLotto winningLotto) {
+ int winningCount = checkWinningCount(winningLotto);
+ boolean hasBonusNumber = hasBonusNumber(winningLotto);
+ return new WinningResult(winningCount, hasBonusNumber);
+ }
+
+ private int checkWinningCount(WinningLotto winningLotto) {
+ return (int) numbers.stream()
+ .filter(number -> winningLotto
+ .getWinningNumbers()
+ .contains(number))
+ .count();
+ }
+
+ private boolean hasBonusNumber(WinningLotto winningLotto) {
+ return numbers.contains(winningLotto.getBonusNumber());
+ }
+
+ public List<Integer> getNumbers() {
+ return Collections.unmodifiableList(numbers);
+ }
+} | Java | ๋งค์ง ๋๋ฒ ๋ฐ๋ก ๊ด๋ฆฌ ํด์ฃผ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,58 @@
+package lotto.domain;
+
+import static lotto.global.Error.DUPLICATED;
+import static lotto.global.Error.INVALID_SIZE;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validateSize(numbers);
+ validateDuplicated(numbers);
+ validateNumberRange(numbers);
+ this.numbers = numbers;
+ }
+
+ private void validateSize(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(INVALID_SIZE.getMessage());
+ }
+ }
+
+ private void validateDuplicated(List<Integer> numbers) {
+ if (numbers.stream()
+ .distinct().count() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATED.getMessage());
+ }
+ }
+
+ private void validateNumberRange(List<Integer> numbers) {
+ numbers.forEach(Number::new);
+ }
+
+ // TODO: ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
+ public WinningResult checkWinningResult(WinningLotto winningLotto) {
+ int winningCount = checkWinningCount(winningLotto);
+ boolean hasBonusNumber = hasBonusNumber(winningLotto);
+ return new WinningResult(winningCount, hasBonusNumber);
+ }
+
+ private int checkWinningCount(WinningLotto winningLotto) {
+ return (int) numbers.stream()
+ .filter(number -> winningLotto
+ .getWinningNumbers()
+ .contains(number))
+ .count();
+ }
+
+ private boolean hasBonusNumber(WinningLotto winningLotto) {
+ return numbers.contains(winningLotto.getBonusNumber());
+ }
+
+ public List<Integer> getNumbers() {
+ return Collections.unmodifiableList(numbers);
+ }
+} | Java | ํด๋น ๋ถ๋ถ์ Intstream์ผ๋ก ์ฌ์ฉ์ด ๊ฐ๋ฅํ์ง ์์๊น์???? |
@@ -0,0 +1,30 @@
+package lotto.domain;
+
+import java.util.Collections;
+import java.util.List;
+import lotto.global.Error;
+
+public class WinningLotto {
+ private final List<Integer> winningNumbers;
+ private final int bonusNumber;
+
+ public WinningLotto(List<Integer> winningNumbers, int bonusNumber) {
+ validateBonusNumber(winningNumbers, bonusNumber);
+ this.winningNumbers = winningNumbers;
+ this.bonusNumber = bonusNumber;
+ }
+
+ private void validateBonusNumber(List<Integer> winningNumbers, int bonusNumber) {
+ if (winningNumbers.contains(bonusNumber)) {
+ throw new IllegalArgumentException(Error.INVALID_BONUS_NUMBER.getMessage());
+ }
+ }
+
+ public List<Integer> getWinningNumbers() {
+ return Collections.unmodifiableList(winningNumbers);
+ }
+
+ public int getBonusNumber() {
+ return bonusNumber;
+ }
+} | Java | ๋น์ฒจ ๋ฒํธ ๋ก๋๋ฅผ ๋ฐ๋ก ๋์
จ๋ค์. ์ข์ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ์์. ์ ๋ ๋๊ฐ์ ๋ก๋๋ผ๊ณ ๊ผญ ๊ฐ์ด ์ฌ์ฉํด์ผ ํ๋ค๊ณ ๋ง ์๊ฐํ์๋๋ฐ. ์ด๋ฌ๋ฉด ๋ณด๋์ค ๋ฒํธ ํ์ธ์ ๋ณด๋ค ์ฝ๊ฒ ํ ์ ์์ ๊ฒ ๊ฐ์์ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,38 @@
+package lotto.domain;
+
+import static lotto.domain.Rank.NONE;
+
+import java.util.Arrays;
+
+public class WinningResult {
+ private static final int SECOND_OR_THIRD = 5;
+ private final int winningCount;
+ private final boolean hasBonusNumber;
+
+ public WinningResult(int winningCount, boolean matchingBonusNumber) {
+ this.winningCount = winningCount;
+ this.hasBonusNumber = matchingBonusNumber;
+ }
+
+ public Rank toRank() {
+ if (winningCount == SECOND_OR_THIRD) {
+ return Arrays.stream(Rank.values())
+ .filter(rank -> rank.getWinningCount() == winningCount)
+ .filter(rank -> rank.hasBonusNumber() == hasBonusNumber)
+ .findAny()
+ .orElse(NONE);
+ }
+ return Arrays.stream(Rank.values())
+ .filter(rank -> rank.getWinningCount() == winningCount)
+ .findAny()
+ .orElse(NONE);
+ }
+
+ public int getWinningCount() {
+ return winningCount;
+ }
+
+ public boolean hasBonusNumber() {
+ return hasBonusNumber;
+ }
+} | Java | enum์ด ์ ์ธ๋ ์์๋๋ก ์ธ๋ฑ์ค๊ฐ ์ ํด์ง๋ ๊ฑธ๋ก ์๊ณ ์์ต๋๋ค. ์ด๋ฅผ ์ด์ฉํด์ 2๋ฑ, 3๋ฑ์ ๋น์ฒจ ๋ฒํธ ๊ฐฏ์๋ฅผ filterํ ํ ๋ค์ filter๋ก ๋ณด๋์ค ์ฌ๋ถ ์ฒดํฌ ํ๊ณ ์ดํ ๋๋จธ์ง ๋ญํฌ๋ฅผ ์ฒดํฌํ๋ ๋ฐฉ๋ฒ์ ์ฐ๋ฉด ํด๋น ๋ถ๋ถ์ ์ฝ๋๋ฅผ ์กฐ๊ธ ์ค์ผ ์ ์์ง ์์๊น์??? ์์ถ๋์ ์๊ฐ์ด ๊ถ๊ธํฉ๋๋ค^^ |
@@ -0,0 +1,26 @@
+package lotto.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class LottoRepository {
+ private final List<Lotto> lottos = new ArrayList<>();
+
+ public void issueLottos(int purchaseQuantity) {
+ for (int i = 0; i < purchaseQuantity; i++) {
+ Lotto lotto = new Lotto(Number.generateNumbers());
+ lottos.add(lotto);
+ }
+ }
+
+ public List<WinningResult> checkWinningResults(WinningLotto winningLotto) {
+ return lottos.stream()
+ .map(lotto -> lotto.checkWinningResult(winningLotto))
+ .collect(Collectors.toList());
+ }
+
+ public List<Lotto> getLottos() {
+ return lottos;
+ }
+} | Java | ์ ์ญ๋ณ์๋ฅผ ์ด๋ ๊ฒ new๋ก ์์ฑํ๋ ๊ฒ์ด๋ ์์ฑ์๋ก ๊ฐ์ฒด๊ฐ ์์ฑ๋ ๋ this๋ก ์ง์ ํด์ค์ ์์ฑํ๋ ๊ฒ์ ๋ํด ์ด๋ค ๋ฐฉ์์ด ๋์ ํํ์ธ์ง ์๊ฒฌ์ ๋๋ ๋ณด๊ณ ์ถ์ต๋๋ค. |
@@ -0,0 +1,57 @@
+package lotto.view;
+
+import java.util.Arrays;
+import java.util.Map;
+import lotto.domain.Lotto;
+import lotto.domain.LottoRepository;
+import lotto.domain.Rank;
+import lotto.domain.WinningStats;
+
+public class OutputView {
+ private static final String PURCHASE_QUANTITY_FORMAT = "%n%d๊ฐ๋ฅผ ๊ตฌ๋งคํ์ต๋๋ค.%n";
+ private static final String WINNING_STATS = "\n๋น์ฒจ ํต๊ณ\n---";
+ private static final String WINNING_STATS_FORMAT = "%d๊ฐ ์ผ์น%s (%,d์) - %d๊ฐ%n";
+ private static final String HAS_BONUS_NUMBER = ", ๋ณด๋์ค ๋ณผ ์ผ์น";
+ private static final String HAS_NOT_BONUS_NUMBER = "";
+ private static final String TOTAL_PROFIT_RATE_FORMAT = "์ด ์์ต๋ฅ ์ %.1f%%์
๋๋ค.";
+
+ public static void printError(Exception e) {
+ System.out.println(e.getMessage());
+ }
+
+ public static void printPurchaseQuantity(int purchaseQuantity) {
+ System.out.printf(PURCHASE_QUANTITY_FORMAT, purchaseQuantity);
+ }
+
+ public static void printLottos(LottoRepository lottoRepository) {
+ for (Lotto lotto : lottoRepository.getLottos()) {
+ System.out.println(lotto.getNumbers()
+ .stream()
+ .sorted()
+ .toList());
+ }
+ }
+
+ public static void printWinningStats(WinningStats winningStats) {
+ Map<Rank, Integer> rankCounts = winningStats.getWinningStats();
+ System.out.println(WINNING_STATS);
+ Arrays.stream(Rank.values())
+ .skip(1)
+ .forEach(rank -> System.out.printf(WINNING_STATS_FORMAT
+ , rank.getWinningCount()
+ , checkBonusNumber(rank)
+ , rank.getPrize()
+ , rankCounts.get(rank)));
+ }
+
+ private static String checkBonusNumber(Rank rank) {
+ if (rank.hasBonusNumber()) {
+ return HAS_BONUS_NUMBER;
+ }
+ return HAS_NOT_BONUS_NUMBER;
+ }
+
+ public static void printTotalProfitRate(double totalProfitRate) {
+ System.out.printf(TOTAL_PROFIT_RATE_FORMAT, totalProfitRate);
+ }
+} | Java | stream์ ๊ต์ฅํ ์ ์ฌ์ฉํ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ๋ฐฐ์๊ฐ๋๋ค. |
@@ -0,0 +1,85 @@
+package lotto.controller;
+
+import java.util.List;
+import lotto.domain.Lotto;
+import lotto.domain.LottoRepository;
+import lotto.domain.Number;
+import lotto.domain.PurchaseAmount;
+import lotto.domain.Rank;
+import lotto.domain.WinningLotto;
+import lotto.domain.WinningResult;
+import lotto.domain.WinningStats;
+import lotto.view.InputView;
+import lotto.view.OutputView;
+
+public class Controller {
+
+ public void run() {
+ PurchaseAmount purchaseAmount = createPurchaseAmount();
+ int purchaseQuantity = createPurchaseQuantity(purchaseAmount);
+ LottoRepository lottoRepository = createLottoRepository(purchaseQuantity);
+ WinningLotto winningLotto = createWinningLotto();
+ List<WinningResult> winningResults = lottoRepository.checkWinningResults(winningLotto);
+ WinningStats winningStats = createWinningStats(winningResults);
+ createTotalProfitRate(winningStats, purchaseAmount);
+ }
+
+ private PurchaseAmount createPurchaseAmount() {
+ while (true) {
+ try {
+ return new PurchaseAmount(InputView.askPurchaseAmount());
+ } catch (IllegalArgumentException e) {
+ OutputView.printError(e);
+ }
+ }
+ }
+
+ private int createPurchaseQuantity(PurchaseAmount purchaseAmount) {
+ int purchaseQuantity = purchaseAmount.calculatePurchaseQuantity();
+ OutputView.printPurchaseQuantity(purchaseQuantity);
+ return purchaseQuantity;
+ }
+
+ private LottoRepository createLottoRepository(int purchaseQuantity) {
+ LottoRepository lottoRepository = new LottoRepository();
+ lottoRepository.issueLottos(purchaseQuantity);
+ OutputView.printLottos(lottoRepository);
+ return lottoRepository;
+ }
+
+ private List<Integer> createWinningNumbers() {
+ while (true) {
+ try {
+ List<Integer> winningNumbers = InputView.askWinningNumbers();
+ new Lotto(winningNumbers);
+ return winningNumbers;
+ } catch (IllegalArgumentException e) {
+ OutputView.printError(e);
+ }
+ }
+ }
+
+ private WinningLotto createWinningLotto() {
+ List<Integer> winningNumbers = createWinningNumbers();
+ while (true) {
+ try {
+ int bonusNumber = InputView.askBonusNumber();
+ new Number(bonusNumber);
+ return new WinningLotto(winningNumbers, bonusNumber);
+ } catch (IllegalArgumentException e) {
+ OutputView.printError(e);
+ }
+ }
+ }
+
+ private WinningStats createWinningStats(List<WinningResult> winningResults) {
+ WinningStats winningStats = Rank.countRanks(winningResults);
+ OutputView.printWinningStats(winningStats);
+ return winningStats;
+ }
+
+ private void createTotalProfitRate(WinningStats winningStats, PurchaseAmount purchaseAmount) {
+ double totalProfitRate = winningStats.calculateTotalProfitRate(purchaseAmount);
+ OutputView.printTotalProfitRate(totalProfitRate);
+ }
+} | Java | ์ฌ๊ธฐ์ ์์ฑ๋ Lotto ๊ฐ์ฒด๋ ์ฌ์ฉ๋์ง ์๊ณ List<Integer>๋ง returnํ๋๊ฑฐ ๊ฐ์๋ฐ ๋ฐ๋ก ์๋ํ์ ๋ถ๋ถ์ด ์๋๊ฑด๊ฐ์ ?! ์๋ ๋ณด๋์ค๋ ๊ทธ๋ ๊ตฌ์ !! |
@@ -0,0 +1,58 @@
+package lotto.domain;
+
+import static lotto.global.Error.DUPLICATED;
+import static lotto.global.Error.INVALID_SIZE;
+
+import java.util.Collections;
+import java.util.List;
+
+public class Lotto {
+ private final List<Integer> numbers;
+
+ public Lotto(List<Integer> numbers) {
+ validateSize(numbers);
+ validateDuplicated(numbers);
+ validateNumberRange(numbers);
+ this.numbers = numbers;
+ }
+
+ private void validateSize(List<Integer> numbers) {
+ if (numbers.size() != 6) {
+ throw new IllegalArgumentException(INVALID_SIZE.getMessage());
+ }
+ }
+
+ private void validateDuplicated(List<Integer> numbers) {
+ if (numbers.stream()
+ .distinct().count() != numbers.size()) {
+ throw new IllegalArgumentException(DUPLICATED.getMessage());
+ }
+ }
+
+ private void validateNumberRange(List<Integer> numbers) {
+ numbers.forEach(Number::new);
+ }
+
+ // TODO: ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
+ public WinningResult checkWinningResult(WinningLotto winningLotto) {
+ int winningCount = checkWinningCount(winningLotto);
+ boolean hasBonusNumber = hasBonusNumber(winningLotto);
+ return new WinningResult(winningCount, hasBonusNumber);
+ }
+
+ private int checkWinningCount(WinningLotto winningLotto) {
+ return (int) numbers.stream()
+ .filter(number -> winningLotto
+ .getWinningNumbers()
+ .contains(number))
+ .count();
+ }
+
+ private boolean hasBonusNumber(WinningLotto winningLotto) {
+ return numbers.contains(winningLotto.getBonusNumber());
+ }
+
+ public List<Integer> getNumbers() {
+ return Collections.unmodifiableList(numbers);
+ }
+} | Java | ์ค .. ๊ทธ๋ฐ๊ฒ ์์๊ตฐ์ ๊ฐ์ธ์ ์ผ๋ก ํ๋ณํํ๋๊ฒ ์ง์ ๋ถํ๊ฒ ๋ณด์ด๊ณ ๊ฐ์ ํ๋๊ฑฐ ๊ฐ์์ ๋ณ๋ก ์ ํธํ์ง ์์์๋๋ฐ ์๋ก ์๊ฒ๋๋ค์ (๋ฉ๋ชจ) |
@@ -0,0 +1,26 @@
+package lotto.domain;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class LottoRepository {
+ private final List<Lotto> lottos = new ArrayList<>();
+
+ public void issueLottos(int purchaseQuantity) {
+ for (int i = 0; i < purchaseQuantity; i++) {
+ Lotto lotto = new Lotto(Number.generateNumbers());
+ lottos.add(lotto);
+ }
+ }
+
+ public List<WinningResult> checkWinningResults(WinningLotto winningLotto) {
+ return lottos.stream()
+ .map(lotto -> lotto.checkWinningResult(winningLotto))
+ .collect(Collectors.toList());
+ }
+
+ public List<Lotto> getLottos() {
+ return lottos;
+ }
+} | Java | lottos ๋ณ์๋ ์ ์ญ๋ณ์๋ ์๋๊ฑฐ ๊ฐ๊ณ ์ด๊ธฐํ๋ฅผ ์งํํด์ค์ ํท๊ฐ๋ฆฌ์ ๊ฑฐ ๊ฐ์์ !!! ์๋ ์ฝ๋๋ณด๋ฉด lottos.add ํ๋๋ผ๊ตฌ์ ์ ๋ ๊ฐ์ธ์ ์ผ๋ก this ํํ์ ํ์ง ์์ผ๋ฉด ์ ๋ง ์์๋ณด๊ธฐ ํ๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฉด ์ ์ฌ์ฉํ์ง ์์ต๋๋ค๐ค |
@@ -0,0 +1,30 @@
+package lotto.domain;
+
+import java.util.Collections;
+import java.util.List;
+import lotto.global.Error;
+
+public class WinningLotto {
+ private final List<Integer> winningNumbers;
+ private final int bonusNumber;
+
+ public WinningLotto(List<Integer> winningNumbers, int bonusNumber) {
+ validateBonusNumber(winningNumbers, bonusNumber);
+ this.winningNumbers = winningNumbers;
+ this.bonusNumber = bonusNumber;
+ }
+
+ private void validateBonusNumber(List<Integer> winningNumbers, int bonusNumber) {
+ if (winningNumbers.contains(bonusNumber)) {
+ throw new IllegalArgumentException(Error.INVALID_BONUS_NUMBER.getMessage());
+ }
+ }
+
+ public List<Integer> getWinningNumbers() {
+ return Collections.unmodifiableList(winningNumbers);
+ }
+
+ public int getBonusNumber() {
+ return bonusNumber;
+ }
+} | Java | winningNumbers ๋ฅผ List<Integer>๋์ Lottoํ์ ์ฌ์ฉํ๋ ๊ฒ์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์๋์ ?!?! ์ ๋ ์ฌ์ค winningLotto์ ๊ฒฝ์ฐ Lotto1๊ฐ๋ฅผ ๊ฐ์ง๋ ๋ณด๋์ค ๋ฒํธ๋ ์ถ๊ฐ๋ก ๊ฐ์ง๊ณ ์๋ค๋ ํํ๋ก ์ฝ๋๋ฅผ ์์ฑํ์๊ฑฐ๋ ์ ๊ฐ์ฒด์ํ๊ฐ ์ซ์ 6๊ฐ๋ฅผ ๊ฐ์ง๋ ๊ฒ๋ ๋์ผํ๊ตฌ์ !!! ์ด๋ป๊ฒ ์๊ฐํ๋์ง ๊ถ๊ธํฉ๋๋ค |
@@ -0,0 +1,38 @@
+package lotto.domain;
+
+import static lotto.domain.Rank.NONE;
+
+import java.util.Arrays;
+
+public class WinningResult {
+ private static final int SECOND_OR_THIRD = 5;
+ private final int winningCount;
+ private final boolean hasBonusNumber;
+
+ public WinningResult(int winningCount, boolean matchingBonusNumber) {
+ this.winningCount = winningCount;
+ this.hasBonusNumber = matchingBonusNumber;
+ }
+
+ public Rank toRank() {
+ if (winningCount == SECOND_OR_THIRD) {
+ return Arrays.stream(Rank.values())
+ .filter(rank -> rank.getWinningCount() == winningCount)
+ .filter(rank -> rank.hasBonusNumber() == hasBonusNumber)
+ .findAny()
+ .orElse(NONE);
+ }
+ return Arrays.stream(Rank.values())
+ .filter(rank -> rank.getWinningCount() == winningCount)
+ .findAny()
+ .orElse(NONE);
+ }
+
+ public int getWinningCount() {
+ return winningCount;
+ }
+
+ public boolean hasBonusNumber() {
+ return hasBonusNumber;
+ }
+} | Java | ์ ๊ฐ์ธ์ ์ธ ์๊ฒฌ์ผ๋ก ์ ๋ enum์ด ์ ์ธ๋ ์์๋ก ์ธ๋ฑ์ค๊ฐ ๋ถ์ฌ๋์ง๋ง enum์ ์์๋ ์ธ์ ๋ ๋ณ๊ฒฝ๋ ์ ์๊ณ , ๋ค๋ฅธ ํญ๋ชฉ์ด ์ถ๊ฐ๋๋ฉด์ enum ์์๊ฐ ์ํฌ์ ์๊ฒ ๋๋ค๋ ์ ์์ ์ธ๋ฑ์ค ์์๋ก ์ฝ๋๋ฅผ ๊ฐ๋ฐํ๋ ๋ฐฉ์์ ์ง์ํ๋ ํธ์
๋๋ค !! ๊ทผ๋ฐ ์ฝ๋ฉํธ ๋ณด๊ณ ์๊ฐํด๋ณด๋ ์ ๋ enum ์ธ๋ฑ์ค๋๋ก print ์ฐ๋๋ก ์ฝ๋๋ฅผ ์์ฑํ๊ฒ ์์๋๊ฑฐ ๊ฐ์๋ฐ .......๐ค๐ฅฒ |
@@ -0,0 +1,21 @@
+package lotto.global;
+
+public enum Error {
+ INVALID_SIZE("๋ก๋๋ 6๊ฐ์ ๋ฒํธ๋ก ๊ตฌ์ฑ๋์ด์ผ ํฉ๋๋ค."),
+ DUPLICATED("๋ก๋ ๋ฒํธ๋ ์๋ก ์ค๋ณต๋ ์ ์์ต๋๋ค."),
+ INVALID_TYPE("์ซ์๋ง ์
๋ ฅ ๊ฐ๋ฅํฉ๋๋ค."),
+ INVALID_UNIT("1,000์ ๋จ์๋ก๋ง ์
๋ ฅ ๊ฐ๋ฅํฉ๋๋ค."),
+ INVALID_AMOUNT_RANGE("๊ตฌ๋งค๊ธ์ก์ 1,000์ ์ด์ 100,000์ ์ดํ์ฌ์ผ ํฉ๋๋ค."),
+ INVALID_NUMBER_RANGE("๋ก๋ ๋ฒํธ๋ 1-45 ์ฌ์ด์ ์ซ์๋ง ์
๋ ฅ ๊ฐ๋ฅํฉ๋๋ค."),
+ INVALID_BONUS_NUMBER("๋ณด๋์ค ๋ฒํธ๋ ๋ก๋๋ฒํธ์ ์ค๋ณต๋ ์ ์์ต๋๋ค.");
+ private static final String ERROR = "[ERROR] ";
+ private final String message;
+
+ Error(String message) {
+ this.message = ERROR + message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ์๋ฌ ๋ฉ์ธ์ง ์์ ๋ถ๋ [ERROR]๋ฅผ ์์ ์ฒ๋ฆฌ ํด์ฃผ์
จ๋ค์!
์ ๋ enumํด๋์ค ์์์๋ ์์์ฒ๋ฆฌํ ์๊ฐ์ ๋ชปํ๋๋ฐ ๋ฐฐ์๊ฐ๋๋ค |
@@ -0,0 +1,58 @@
+package lotto.domain;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public enum Rank {
+ NONE(0, false, 0),
+ FIFTH(3, false, 5_000),
+ FOURTH(4, false, 50_000),
+ THIRD(5, false, 1_500_000),
+ SECOND(5, true, 30_000_000),
+ FIRST(6, false, 2_000_000_000);
+
+ private final int winningCount;
+ private final boolean hasBonusNumber;
+ private final int prize;
+
+ Rank(int winningCount, boolean hasBonusNumber, int prize) {
+ this.winningCount = winningCount;
+ this.hasBonusNumber = hasBonusNumber;
+ this.prize = prize;
+ }
+
+ public static WinningStats countRanks(List<WinningResult> winningResults) {
+ Map<Rank, Integer> winningStats = new EnumMap<>(Rank.class);
+ List<Rank> ranks = convertToRanks(winningResults);
+ for (Rank rank : values()) {
+ int count = Collections.frequency(ranks, rank);
+ winningStats.put(rank, count);
+ }
+ return new WinningStats(winningStats);
+ }
+
+ private static List<Rank> convertToRanks(List<WinningResult> winningResults) {
+ return winningResults.stream()
+ .map(WinningResult::toRank)
+ .collect(Collectors.toList());
+ }
+
+ public long calculateProfit(int count) {
+ return (long) prize * count;
+ }
+
+ public int getWinningCount() {
+ return winningCount;
+ }
+
+ public boolean hasBonusNumber() {
+ return hasBonusNumber;
+ }
+
+ public int getPrize() {
+ return prize;
+ }
+} | Java | ```java
public enum BonusMatchStatus {
MATCHED, NOT_MATCHED, IRRELEVANT;
}
```
```java
FIRST(6, BonusMatchStatus.IRRELEVANT, 2_000_000_000),
SECOND(5, BonusMatchStatus.MATCHED, 30_000_000),
THIRD(5, BonusMatchStatus.NOT_MATCHED, 1_500_000),
FOURTH(4, BonusMatchStatus.IRRELEVANT, 50_000),
FIFTH(3, BonusMatchStatus.IRRELEVANT, 5_000),
LOSING(0, BonusMatchStatus.IRRELEVANT, 0);
```
enum์์์ boolean ํ์
์ ์ด์ฉํ์ฌ 2๋ฑ๊ณผ 3๋ฑ์ ๊ตฌ๋ถํด์ฃผ์
จ๋ค์!
์ ๋ if๋ก ํ๋ํ๋ ๋ค๊ตฌ๋ถํด์คฌ๋๋ฐ ๋ ํจ์จ์ ์ธ ๋ฐฉ๋ฒ์ธ๊ฒ ๊ฐ์ต๋๋ค.
๊ทธ๋์ ์ ๋ ์ด ๋ถ๋ถ์ ๋ํด์ ๋ค๋ฅธ ๋ฆฌ๋ทฐ๋ฅผ ๋ณด๋ฉด์ ๊ณต๋ถํ๋ค๊ฐ ์๊ฒ ๋ ์ฌ์ค์ธ๋ฐ
๋ณด๋์ค๋ณผ์ ์ผ์น์ฌ๋ถ๋ฅผ true/false๋ก ๊ด๋ฆฌํ๊ฒ ๋๋ค๋ฉด ์๋ก false๊ฐ์ ๋ํด ์๋ก ๋ค๋ฅธ ๊ด์ ์ด ์์ ์ ์๋ค๊ณ ํฉ๋๋ค.
false๋ผ๋ ๊ฐ์ด "์ผ์นํ๋ฉด ์๋๋ค๋ ๊ฒ", "์๊ด์๋ค" ๋๊ฐ๋ก ๋๋ ์ ์๊ธฐ ๋๋ฌธ์
2๋ฑ(์ผ์นํด์ผํ๋ค), 3๋ฑ(์ผ์นํ๋ฉด ์๋๋ค), ๋๋จธ์ง๋ฑ์(์๊ด์๋ค) 3๊ฐ์ง ์ผ์ด์ค๊ฐ ๋์จ๋ค๊ณ ํฉ๋๋ค
๊ทธ๋์ ์ด๋ ๊ฒ enum์ ํ์ฉํ๋ ๋ฐฉ๋ฒ๋ ์๋ค๊ณ ํฉ๋๋ค! |
@@ -0,0 +1,47 @@
+package lotto.view;
+
+import static lotto.global.Error.INVALID_TYPE;
+
+import camp.nextstep.edu.missionutils.Console;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class InputView {
+ private static final String ASK_PURCHASE_AMOUNT = "๊ตฌ์
๊ธ์ก์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String ASK_WINNING_NUMBERS = "\n๋น์ฒจ ๋ฒํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.";
+ private static final String ASK_BONUS_NUMBER = "\n๋ณด๋์ค ๋ฒํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.";
+
+
+ public static int askPurchaseAmount() {
+ System.out.println(ASK_PURCHASE_AMOUNT);
+ String input = Console.readLine();
+ validateType(input);
+ return Integer.parseInt(input);
+ }
+
+ public static List<Integer> askWinningNumbers() {
+ System.out.println(ASK_WINNING_NUMBERS);
+ String input = Console.readLine();
+ return Arrays.stream(input.trim()
+ .split(","))
+ .peek(number -> validateType(number))
+ .mapToInt(number -> Integer.parseInt(number))
+ .boxed()
+ .collect(Collectors.toList());
+ }
+
+ public static int askBonusNumber() {
+ System.out.println(ASK_BONUS_NUMBER);
+ String input = Console.readLine();
+ validateType(input);
+ return Integer.parseInt(input);
+ }
+
+ private static void validateType(String input) {
+ if (!input.chars()
+ .allMatch(Character::isDigit)) {
+ throw new IllegalArgumentException(INVALID_TYPE.getMessage());
+ }
+ }
+} | Java | ํด๋น ๋ถ๋ถ์์ ์๋ฌด๋ฐ ์
๋ ฅ์์ด ์ํฐ๋ฅผ ๋๋ ์์ ๋ฌธ์๋ก ์กํ์ง ์๊ณ
For input string: "" ์ค๋ฅ๋ก ๋น ์ง๊ฒ ๋ฉ๋๋ค. ์ ๋ ๊ทธ ์ด์ ๊ฐ ๊ถ๊ธํ์ฌ ๊ตฌ๊ธ๋ง์ ํด๋ดค์ต๋๋ค.
**isDigit**
public static boolean isDigit(int codePoint)
์ง์ ๋ ๋ฌธ์ (Unicode ์ฝ๋ ํฌ์ธํธ)๊ฐ ์ซ์์ธ๊ฐ ์ด๋ค๊ฐ๋ฅผ ํ์ ํฉ๋๋ค.
[getType(codePoint)](http://cris.joongbu.ac.kr/course/java/api/java/lang/Character.html#getType(int)) ์ ์ํด ๋ํ๋๋ ๋ฒ์ฉ ์นดํ
๊ณ ๋ฆฌํ์ด **DECIMAL_DIGIT_NUMBER**์ธ ๊ฒฝ์ฐ, ์ซ์๊ฐ ๋ฉ๋๋ค.
**DECIMAL_DIGIT_NUMBER**
public static final byte DECIMAL_DIGIT_NUMBER
Unicode ์ฌ์์ ๋ฒ์ฉ ์นดํ
๊ณ ๋ฆฌ ใNdใ
์ด๋ฌํ ์ด์ ๋๋ฌธ์ ์๋ฌด๊ฒ๋ ์
๋ ฅ๋ฐ์ง ์์ "" ์ฆ Nd ์ผ๋ ์ซ์๋ก ํต๊ณผ ํ์๋ค๊ฐ ๋์ค์ NumberFormatException ์ค๋ฅ๊ฐ ๋จ๋ ๋ฏ ํฉ๋๋ค.
(isDigit ํด๋์ค)
http://cris.joongbu.ac.kr/course/java/api/java/lang/Character.html#isDigit(int) |
@@ -0,0 +1,58 @@
+package lotto.domain;
+
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public enum Rank {
+ NONE(0, false, 0),
+ FIFTH(3, false, 5_000),
+ FOURTH(4, false, 50_000),
+ THIRD(5, false, 1_500_000),
+ SECOND(5, true, 30_000_000),
+ FIRST(6, false, 2_000_000_000);
+
+ private final int winningCount;
+ private final boolean hasBonusNumber;
+ private final int prize;
+
+ Rank(int winningCount, boolean hasBonusNumber, int prize) {
+ this.winningCount = winningCount;
+ this.hasBonusNumber = hasBonusNumber;
+ this.prize = prize;
+ }
+
+ public static WinningStats countRanks(List<WinningResult> winningResults) {
+ Map<Rank, Integer> winningStats = new EnumMap<>(Rank.class);
+ List<Rank> ranks = convertToRanks(winningResults);
+ for (Rank rank : values()) {
+ int count = Collections.frequency(ranks, rank);
+ winningStats.put(rank, count);
+ }
+ return new WinningStats(winningStats);
+ }
+
+ private static List<Rank> convertToRanks(List<WinningResult> winningResults) {
+ return winningResults.stream()
+ .map(WinningResult::toRank)
+ .collect(Collectors.toList());
+ }
+
+ public long calculateProfit(int count) {
+ return (long) prize * count;
+ }
+
+ public int getWinningCount() {
+ return winningCount;
+ }
+
+ public boolean hasBonusNumber() {
+ return hasBonusNumber;
+ }
+
+ public int getPrize() {
+ return prize;
+ }
+} | Java | ์ด๋ฒ์ ํฐ ์์ ์๋ฃํ์ ์ฐพ์๋ณด๋ค๊ฐ BigDecimal์ ์๊ฒ ๋์๋๋ฐ
๋ง์ฝ ๊ทธ๋ด์ผ ์๊ฒ ์ง๋ง long๋ฒ์๋ ๋ฒ์ด๋๋ค๋ฉด ์ฐ๋ฉด ์ข์๊ฒ ๊ฐ์์ |
@@ -0,0 +1,30 @@
+package christmas.controller;
+
+import christmas.model.UserOrder;
+import christmas.service.ChristmasEventService;
+
+public class ChristmasEventController {
+
+ private static final String EVENT_START_MESSAGE = "์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.";
+
+ private final ChristmasEventService christmasEventService;
+
+ public ChristmasEventController() {
+ System.out.println(EVENT_START_MESSAGE);
+ christmasEventService = new ChristmasEventService();
+ }
+
+ public void run() {
+ UserOrder userOrder = requestUserInput();
+
+ requestUserBenefit(userOrder);
+ }
+
+ public UserOrder requestUserInput() {
+ return christmasEventService.requestUserInput();
+ }
+
+ public void requestUserBenefit(UserOrder userOrder) {
+ christmasEventService.requestUserBenefit(userOrder);
+ }
+} | Java | ํน์ view๊ฐ ์๋ controller์ ๋ฐ๋ก ์ถ๋ ฅ ๋ฉ์ธ์ง๋ฅผ ๋์ ์ด์ ๊ฐ ์์ผ์ ์ง ๊ถ๊ธํฉ๋๋น |
@@ -0,0 +1,22 @@
+package christmas.constant;
+
+public class Constants {
+
+ public static final String DEFAULT_CONDITION = "์์";
+ public static final String STAR_BADGE = "๋ณ";
+ public static final String TREE_BADGE = "ํธ๋ฆฌ";
+ public static final String SANTA_BADGE = "์ฐํ";
+ public static final int MAX_ORDER_COUNT = 20;
+ public static final int MIN_INPUT_DATE = 1;
+ public static final int MAX_INPUT_DATE = 31;
+ public static final int D_DAY_SALE_DEFAULT = 1000;
+ public static final int D_DAY_SALE_DATE = 25;
+ public static final int D_DAY_INCREASE_PRICE = 100;
+ public static final int SPECIAL_SALE_DEFAULT = 1000;
+ public static final int WEEKDAY_SALE_DEFAULT = 2023;
+ public static final int WEEKEND_SALE_DEFAULT = 2023;
+ public static final int PRESENT_CHAMPAGNE_PRICE = 25000;
+ public static final int MIN_BENEFITABLE_PRICE = 10000;
+ public static final int MIN_PRESENTABLE_PRICE = 120000;
+
+} | Java | ๋ค์์๋ enum์ผ๋ก ๋ถ๋ฆฌํด์ ์ฌ์ฉํด ๋ณด์๋๊ฑธ ์ถ์ฒํฉ๋๋ค |
@@ -0,0 +1,187 @@
+package christmas.model;
+
+import static christmas.constant.Constants.DEFAULT_CONDITION;
+import static christmas.constant.Constants.D_DAY_INCREASE_PRICE;
+import static christmas.constant.Constants.D_DAY_SALE_DATE;
+import static christmas.constant.Constants.D_DAY_SALE_DEFAULT;
+import static christmas.constant.Constants.MIN_BENEFITABLE_PRICE;
+import static christmas.constant.Constants.MIN_PRESENTABLE_PRICE;
+import static christmas.constant.Constants.PRESENT_CHAMPAGNE_PRICE;
+import static christmas.constant.Constants.SANTA_BADGE;
+import static christmas.constant.Constants.SPECIAL_SALE_DEFAULT;
+import static christmas.constant.Constants.STAR_BADGE;
+import static christmas.constant.Constants.TREE_BADGE;
+import static christmas.constant.Constants.WEEKDAY_SALE_DEFAULT;
+import static christmas.constant.Constants.WEEKEND_SALE_DEFAULT;
+
+import java.util.LinkedHashMap;
+
+public class BenefitCalculator {
+
+ private static int totalPrice;
+ private static int discountedTotalPrice;
+
+ private static int dDaySalePrice;
+ private static int weekendSalePrice;
+ private static int weekdaySalePrice;
+ private static int specialSalePrice;
+
+ private static String present;
+ private static int presentPrice;
+
+ private static LinkedHashMap<String, Integer> totalBenefitResult;
+ private static int totalBenefitPrice;
+
+ private static String eventBadge;
+
+ private static UserOrder userOrder;
+
+ public BenefitCalculator(UserOrder userOrder) {
+ this.userOrder = userOrder;
+ totalPrice = 0;
+ discountedTotalPrice = 0;
+ dDaySalePrice = 0;
+ weekendSalePrice = 0;
+ weekdaySalePrice = 0;
+ specialSalePrice = 0;
+ present = DEFAULT_CONDITION;
+ presentPrice = 0;
+ totalBenefitResult = new LinkedHashMap<>();
+ totalBenefitPrice = 0;
+ eventBadge = DEFAULT_CONDITION;
+ }
+
+ public void calculate() {
+ totalPrice();
+ dDaySalePrice();
+ weekdaySalePrice();
+ weekendSalePrice();
+ specialSalePrice();
+ presentPrice();
+ totalBenefit();
+ discountedTotalPrice();
+ eventBadge();
+ }
+
+ public LinkedHashMap<String, Integer> getReservationOrder() {
+ return userOrder.getReservationOrder();
+ }
+
+ public int getReservationDate() {
+ return userOrder.getReservationDate();
+ }
+
+ public int getTotalPrice() {
+ return totalPrice;
+ }
+
+ public String getPresent() {
+ return present;
+ }
+
+ public LinkedHashMap<String, Integer> getBenefitResult() {
+ return totalBenefitResult;
+ }
+
+ public int getBenefitPrice() {
+ return totalBenefitPrice;
+ }
+
+ public int getDiscountedTotalPrice() {
+ return discountedTotalPrice;
+ }
+
+ public String getEventBadge() {
+ return eventBadge;
+ }
+
+ private void totalPrice() {
+ getReservationOrder().forEach((key, value) -> {
+ totalPrice += Menu.getPrice(key) * value;
+ });
+ }
+
+ private void dDaySalePrice() {
+ int date = getReservationDate();
+ if (date <= D_DAY_SALE_DATE) {
+ dDaySalePrice -= D_DAY_SALE_DEFAULT + (date - 1) * D_DAY_INCREASE_PRICE;
+ }
+ }
+
+ private void weekdaySalePrice() {
+ if (!isWeekend()) {
+ getReservationOrder().forEach((key, value) -> {
+ if (Menu.isDessert(key)) {
+ weekdaySalePrice -= value * WEEKDAY_SALE_DEFAULT;
+ }
+ });
+ }
+ }
+
+ private void weekendSalePrice() {
+ if (isWeekend()) {
+ getReservationOrder().forEach((key, value) -> {
+ if (Menu.isMainDish(key)) {
+ weekendSalePrice -= value * WEEKEND_SALE_DEFAULT;
+ }
+ });
+ }
+ }
+
+ private void specialSalePrice() {
+ if (isSpecialDay()) {
+ specialSalePrice -= SPECIAL_SALE_DEFAULT;
+ }
+ }
+
+ private void presentPrice() {
+ if (isPresentAvailable()) {
+ present = "์ดํ์ธ 1๊ฐ";
+ presentPrice -= PRESENT_CHAMPAGNE_PRICE;
+ }
+ }
+
+ private void totalBenefit() {
+ totalBenefitResult.put("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ", dDaySalePrice);
+ totalBenefitResult.put("ํ์ผ ํ ์ธ", weekdaySalePrice);
+ totalBenefitResult.put("์ฃผ๋ง ํ ์ธ", weekendSalePrice);
+ totalBenefitResult.put("ํน๋ณ ํ ์ธ", specialSalePrice);
+ totalBenefitResult.put("์ฆ์ ์ด๋ฒคํธ", presentPrice);
+
+ totalBenefitResult.forEach((key, value) -> {
+ totalBenefitPrice += value;
+ });
+ }
+
+ private void discountedTotalPrice() {
+ discountedTotalPrice = totalPrice + totalBenefitPrice - presentPrice;
+ }
+
+ private void eventBadge() {
+ if (totalBenefitPrice < -5000) {
+ eventBadge = STAR_BADGE;
+ }
+ if (totalBenefitPrice < -10000) {
+ eventBadge = TREE_BADGE;
+ }
+ if (totalBenefitPrice < -20000) {
+ eventBadge = SANTA_BADGE;
+ }
+ }
+
+ public boolean isBenefitAvailable() {
+ return totalPrice >= MIN_BENEFITABLE_PRICE;
+ }
+
+ private boolean isSpecialDay() {
+ return getReservationDate() % 7 == 3 || getReservationDate() == 25;
+ }
+
+ private boolean isWeekend() {
+ return getReservationDate() % 7 == 1 || getReservationDate() % 7 == 2;
+ }
+
+ private boolean isPresentAvailable() {
+ return totalPrice >= MIN_PRESENTABLE_PRICE;
+ }
+} | Java | ๋ง์ ํ๋์ ์๋ก ๋ณด์ ํด๋์ค๊ฐ ๋ง์ ์ฑ
์์ ๊ฐ์ง๊ณ ์๋๊ฒ ๊ฐ์ต๋๋ค. ๋ถ๋ฆฌ๋ฅผ ํด๋ณด์๋๊ฒ ์ข์ ๊ฑฐ ๊ฐ์์ |
@@ -0,0 +1,108 @@
+package christmas.validator;
+
+import static christmas.constant.Constants.MAX_ORDER_COUNT;
+import static christmas.constant.ErrorMessages.WRONG_ORDER;
+
+import christmas.model.Menu;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+public class OrderValidator {
+
+ private static LinkedHashMap<String, Integer> reservationOrder;
+
+ public OrderValidator() {
+ reservationOrder = new LinkedHashMap<>();
+ }
+
+ public LinkedHashMap<String, Integer> validate(String input) {
+ List<String> orders = isCorrectFormat(input);
+ isCountNumber(orders);
+ isMenuDuplicate(orders);
+ isInMenu();
+ isMenuOnlyBeverage();
+ isCountInRange();
+ isTotalCountInRange();
+ return reservationOrder;
+ }
+
+ private List<String> isCorrectFormat(String input) {
+ List<String> orders = List.of(input.split(","));
+ for (String order : orders) {
+ List<String> menuAndCount = List.of(order.split("-"));
+ if (menuAndCount.size() != 2) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ return orders;
+ }
+
+ private void isCountNumber(List<String> orders) {
+ for (String order : orders) {
+ List<String> menuAndCount = List.of(order.split("-"));
+ try {
+ Integer.parseInt(menuAndCount.get(1));
+ } catch (NumberFormatException e) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ }
+
+ private void isMenuDuplicate(List<String> orders) {
+ for (String order : orders) {
+ List<String> menuAndCount = List.of(order.split("-"));
+ String foodName = menuAndCount.get(0);
+ int count = Integer.parseInt(menuAndCount.get(1));
+
+ if (reservationOrder.containsKey(foodName)) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ reservationOrder.put(foodName, count);
+ }
+ }
+
+ private void isInMenu() {
+ for (String foodName : reservationOrder.keySet()) {
+ if (!Menu.isInMenu(foodName)) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ }
+
+ private void isMenuOnlyBeverage() {
+ boolean flag = true;
+ for (String foodName : reservationOrder.keySet()) {
+ if (!Menu.isBeverage(foodName)) {
+ flag = false;
+ }
+ }
+ if (flag) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+
+ private void isCountInRange() {
+ for (int count : reservationOrder.values()) {
+ if (count < 1) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ }
+
+ private void isTotalCountInRange() {
+ int totalCount = 0;
+ for (int count : reservationOrder.values()) {
+ totalCount += count;
+ }
+ if (totalCount > MAX_ORDER_COUNT) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+} | Java | ์ฃผ๋ฌธ์ด ,๋ก ๋๋์ด์ ธ ์์ง ์๋๊ฒฝ์ฐ๋ ์ ํจ์ฑ ์ฒดํฌ๋ฅผ ํด์ฃผ๋์? |
@@ -0,0 +1,108 @@
+package christmas.validator;
+
+import static christmas.constant.Constants.MAX_ORDER_COUNT;
+import static christmas.constant.ErrorMessages.WRONG_ORDER;
+
+import christmas.model.Menu;
+import java.util.LinkedHashMap;
+import java.util.List;
+
+public class OrderValidator {
+
+ private static LinkedHashMap<String, Integer> reservationOrder;
+
+ public OrderValidator() {
+ reservationOrder = new LinkedHashMap<>();
+ }
+
+ public LinkedHashMap<String, Integer> validate(String input) {
+ List<String> orders = isCorrectFormat(input);
+ isCountNumber(orders);
+ isMenuDuplicate(orders);
+ isInMenu();
+ isMenuOnlyBeverage();
+ isCountInRange();
+ isTotalCountInRange();
+ return reservationOrder;
+ }
+
+ private List<String> isCorrectFormat(String input) {
+ List<String> orders = List.of(input.split(","));
+ for (String order : orders) {
+ List<String> menuAndCount = List.of(order.split("-"));
+ if (menuAndCount.size() != 2) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ return orders;
+ }
+
+ private void isCountNumber(List<String> orders) {
+ for (String order : orders) {
+ List<String> menuAndCount = List.of(order.split("-"));
+ try {
+ Integer.parseInt(menuAndCount.get(1));
+ } catch (NumberFormatException e) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ }
+
+ private void isMenuDuplicate(List<String> orders) {
+ for (String order : orders) {
+ List<String> menuAndCount = List.of(order.split("-"));
+ String foodName = menuAndCount.get(0);
+ int count = Integer.parseInt(menuAndCount.get(1));
+
+ if (reservationOrder.containsKey(foodName)) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ reservationOrder.put(foodName, count);
+ }
+ }
+
+ private void isInMenu() {
+ for (String foodName : reservationOrder.keySet()) {
+ if (!Menu.isInMenu(foodName)) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ }
+
+ private void isMenuOnlyBeverage() {
+ boolean flag = true;
+ for (String foodName : reservationOrder.keySet()) {
+ if (!Menu.isBeverage(foodName)) {
+ flag = false;
+ }
+ }
+ if (flag) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+
+ private void isCountInRange() {
+ for (int count : reservationOrder.values()) {
+ if (count < 1) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+ }
+
+ private void isTotalCountInRange() {
+ int totalCount = 0;
+ for (int count : reservationOrder.values()) {
+ totalCount += count;
+ }
+ if (totalCount > MAX_ORDER_COUNT) {
+ reservationOrder.clear();
+ throw new IllegalArgumentException(WRONG_ORDER.getMessage());
+ }
+ }
+} | Java | ','์ผํ๊ฐ ์๋ ๊ฒฝ์ฐ ์ ์ฒด ์
๋ ฅ์ ํ๋์ ์ฃผ๋ฌธ์ผ๋ก ์ธ์ํ๊ณ ๊ทธ ๋ค์ ๋จ๊ณ์์ ์์ธ๊ฐ ๋ฐ์ํ๋๋ก ํ๋ฌ๊ฐ๊ณ ์์ต๋๋ค. ํ๋์ ๊ฒ์ฆ ๋ก์ง์ ์ฌ๋ฌ ๊ฒฝ์ฐ์ ์๋ฅผ ์ปค๋ฒํ๋ ๋ก์ง์ด๋ผ ์๊ฐ๋์ด ๋ถ๋ฆฌ๊ฐ ํ์ํ ๊ฒ ๊ฐ์์ ใ
|
@@ -0,0 +1,40 @@
+package racingcar.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import java.util.Arrays;
+import java.util.List;
+import racingcar.util.validator.AttemptsNumberValidator;
+import racingcar.util.validator.CarNamesValidator;
+import racingcar.util.Constant;
+import racingcar.util.validator.Validator;
+
+public class InputView {
+
+ private final Validator namesValidator;
+ private final Validator attempsValidator;
+
+ private InputView() {
+ this.namesValidator = new CarNamesValidator();
+ this.attempsValidator = new AttemptsNumberValidator();
+ }
+
+ public static InputView getInstance() {
+ return new InputView();
+ }
+
+ public List<String> readCarNames() {
+ String input = input();
+ namesValidator.validate(input);
+ return Arrays.asList(input.split(Constant.DELIMITER_COMMA));
+ }
+
+ public int readAttemptsNumber() {
+ String input = input();
+ attempsValidator.validate(input);
+ return Integer.parseInt(input);
+ }
+
+ private String input() {
+ return Console.readLine();
+ }
+} | Java | ์ฑ๊ธํค ํจํด์ ์ฌ์ฉํ์๋ ค๊ณ ํ๊ฒ ๊ฐ์๋ฐ ํ๋ ์์ InputView instance = new InputView() ๋ฅผ ์ ์ธํด๋์๊ฒ ์๋๋ฉด getInstance๋ฅผ ํ ๋๋ง๋ค ์๋ก์ด ๊ฐ์ฒด๊ฐ ์์ฑ๋์ด์ ์ฑ๊ธํค ํจํด์ ์ฌ์ฉํ๋ ค๊ณ ํ์ ์๋ฏธ๊ฐ ์์ง ์๋์??? ๊ถ๊ธํด์ ์ฌ์ญค๋ด
๋๋ค! |
@@ -0,0 +1,31 @@
+package racingcar.domain.car;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class Cars {
+
+ private final List<Car> cars = new ArrayList<>();
+
+ public void addCar(Car car) {
+ cars.add(car);
+ }
+
+ public List<String> getWinners() {
+ return cars.stream()
+ .filter(car -> car.isWinner(getMaxPosition()))
+ .map(Car::getName)
+ .collect(Collectors.toList());
+ }
+
+ private int getMaxPosition() {
+ return Collections.max(cars.stream()
+ .map(Car::getPosition).toList());
+ }
+
+ public List<Car> getCars() {
+ return Collections.unmodifiableList(cars);
+ }
+} | Java | ๋ฐ์ดํฐ๋ฅผ ๊ฐ๊ณตํ ๋ getter๋ฅผ ์ง์ํ๋ ๋ฐฉํฅ์ผ๋ก ์ค๊ณ๋ฅผ ์ํ์ ๋ค๋ฉด ํด๋น ๊ธ์ ์ถ์ฒ๋๋ฆฝ๋๋ค!
https://tecoble.techcourse.co.kr/post/2020-04-28-ask-instead-of-getter/ |
@@ -0,0 +1,44 @@
+package racingcar.util.validator;
+
+import java.util.regex.Pattern;
+
+public class AttemptsNumberValidator extends Validator {
+
+ private static final int ATTEMPTS_MIN_RANGE = 1;
+ private static final int ATTEMPTS_MAX_RANGE = 20;
+ private final Pattern numberValidatePattern = Pattern.compile("^[0-9]{1,2}$");
+
+ @Override
+ public void validate(String input) {
+ validateNumber(input);
+ validateNumberRange(input);
+ }
+
+ private void validateNumberRange(String input) {
+ int number = Integer.parseInt(input);
+ if (number < ATTEMPTS_MIN_RANGE || number > ATTEMPTS_MAX_RANGE) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_NUMBER.getMessage());
+ }
+ }
+
+ private void validateNumber(String input) {
+ if (!numberValidatePattern.matcher(input).matches()) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_NUMBER.getMessage());
+ }
+ }
+
+ private enum ErrorMessage {
+ INVALID_NUMBER("1 ์ด์ 20 ์ดํ์ ์ซ์๋ง ์
๋ ฅํด์ฃผ์ธ์.");
+
+ private final String Message;
+
+ ErrorMessage(String message) {
+ Message = message;
+ }
+
+ public String getMessage() {
+ return Message;
+ }
+ }
+
+} | Java | ํด๋น enum์ ์๋ฌ๋ฉ์์ง๊ฐ 1๊ฐ๋ผ์ Validator์ ์์๋ก ์ ์ธํด์ฃผ์
๋ ๋ ๊ฑฐ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,53 @@
+package racingcar.util.validator;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+import racingcar.util.Constant;
+
+public class CarNamesValidator extends Validator {
+
+ private static final int CAR_NAMES_MIN_RANGE = 2;
+ private static final int CAR_NAMES_MAX_RANGE = 20;
+ private final Pattern nameValidatePattern = Pattern.compile("^[a-zA-Z๊ฐ-ํฃ0-9]{1,5}$");
+
+ @Override
+ public void validate(String input) {
+ List<String> carNames = Arrays.asList(input.split(Constant.DELIMITER_COMMA));
+ validateIterator(carNames);
+ validateCarNamesNumbers(carNames);
+ }
+
+ private void validateIterator(List<String> carNames) {
+ for (String carName : carNames) {
+ validateNamePattern(carName);
+ }
+ }
+
+ private void validateNamePattern(String carName) {
+ if (!nameValidatePattern.matcher(carName).matches()) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_NAMES.getMessage());
+ }
+ }
+
+ private void validateCarNamesNumbers(List<String> carNames) {
+ if (carNames.size() < CAR_NAMES_MIN_RANGE || carNames.size() > CAR_NAMES_MAX_RANGE) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_NAMES_NUMBERS.getMessage());
+ }
+ }
+
+ private enum ErrorMessage {
+ INVALID_NAMES("ํน์๋ฌธ์๋ฅผ ์ ์ธํ 5์ ์ดํ์ ์ด๋ฆ์ ์
๋ ฅํด์ฃผ์ธ์."),
+ INVALID_NAMES_NUMBERS("2์ด์ 20๊ฐ ์ดํ์ ์ด๋ฆ์ ์์ฑํด ์ฃผ์ธ์.");
+
+ private final String Message;
+
+ ErrorMessage(String message) {
+ Message = message;
+ }
+
+ public String getMessage() {
+ return Message;
+ }
+ }
+} | Java | ์ ๊ท์ ํํ ์ฌ๊ธฐ์๋ ๋ฐฐ์๊ฐ๋๋ค! |
@@ -0,0 +1,63 @@
+package racingcar.view;
+
+import java.util.List;
+import racingcar.domain.car.Car;
+import racingcar.domain.car.Cars;
+
+public class OutputView {
+
+ private OutputView() {
+ }
+
+ public static OutputView getInstance() {
+ return new OutputView();
+ }
+
+ public void printCarNamesInput() {
+ System.out.println(Message.INPUT_CAR_NAMES.getMessage());
+ }
+
+ public void printAttemptsInput() {
+ System.out.println(Message.INPUT_ATTEMPTS_NUMBER.getMessage());
+ }
+
+ public void printExecutionResult() {
+ System.out.printf(Message.EXECUTION_RESULT.getMessage());
+ }
+
+ public void printResult(Cars cars) {
+ for (Car car : cars.getCars()) {
+ System.out.printf(Message.RESULT_FORM.getMessage(), car.getName(),
+ Message.POSITION_MARK.getMessage().repeat(car.getPosition()));
+ }
+ }
+
+ public void printSpace() {
+ System.out.println();
+ }
+
+ public void printWinners(List<String> winners) {
+ System.out.printf(Message.WINNERS.getMessage(),
+ String.join(Message.WINNERS_DELIMITER.getMessage(), winners));
+ }
+
+ private enum Message {
+ INPUT_CAR_NAMES("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)"),
+ INPUT_ATTEMPTS_NUMBER("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?"),
+ EXECUTION_RESULT("%n์คํ๊ฒฐ๊ณผ%n"),
+ RESULT_FORM("%s : %s%n"),
+ POSITION_MARK("-"),
+ WINNERS("์ต์ข
์ฐ์น์ : %s%n"),
+ WINNERS_DELIMITER(", ");
+
+ private final String message;
+
+ Message(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ }
+} | Java | ```suggestion
Message.POSITION_MARK
.getMessage()
.repeat(car.getPosition()));
```
๊ฐํ์ ํตํด ๊ฐ๋
์ฑ์ ๋์ฌ์ฃผ์๋๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,31 @@
+package racingcar.domain.car;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class Cars {
+
+ private final List<Car> cars = new ArrayList<>();
+
+ public void addCar(Car car) {
+ cars.add(car);
+ }
+
+ public List<String> getWinners() {
+ return cars.stream()
+ .filter(car -> car.isWinner(getMaxPosition()))
+ .map(Car::getName)
+ .collect(Collectors.toList());
+ }
+
+ private int getMaxPosition() {
+ return Collections.max(cars.stream()
+ .map(Car::getPosition).toList());
+ }
+
+ public List<Car> getCars() {
+ return Collections.unmodifiableList(cars);
+ }
+} | Java | ์ข์ ์๋ฃ ๋งํฌ ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,40 @@
+package racingcar.view;
+
+import camp.nextstep.edu.missionutils.Console;
+import java.util.Arrays;
+import java.util.List;
+import racingcar.util.validator.AttemptsNumberValidator;
+import racingcar.util.validator.CarNamesValidator;
+import racingcar.util.Constant;
+import racingcar.util.validator.Validator;
+
+public class InputView {
+
+ private final Validator namesValidator;
+ private final Validator attempsValidator;
+
+ private InputView() {
+ this.namesValidator = new CarNamesValidator();
+ this.attempsValidator = new AttemptsNumberValidator();
+ }
+
+ public static InputView getInstance() {
+ return new InputView();
+ }
+
+ public List<String> readCarNames() {
+ String input = input();
+ namesValidator.validate(input);
+ return Arrays.asList(input.split(Constant.DELIMITER_COMMA));
+ }
+
+ public int readAttemptsNumber() {
+ String input = input();
+ attempsValidator.validate(input);
+ return Integer.parseInt(input);
+ }
+
+ private String input() {
+ return Console.readLine();
+ }
+} | Java | ์ ๊ฐ ์ด๋ฆ์ ์คํด์ ์์ง๊ฐ ์๋๋ก ์์ฑํ๋ค์. ์ฌ์ค ์ฑ๊ธํค๋ ๊ณ ๋ฏผ ํ์๊ธฐ๋ ํ์ต๋๋ค. ํ์ง๋ง ์ด๋ฒ์๋ ์ ์ ํฉํ ๋ฆฌ ๋ฉ์๋ ํจํด ์ฌ์ฉ ์ด์ ์ค ํ๋์ธ new๋ฅผ ์ด์ฉํด ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ธฐ๋ณด๋ค ์ ์ ๋ฉ์๋์ด๋ฆ์ ํตํด ์์ฑ ๋ชฉ์ ์ ๋ํ ๊ฐ๋
์ฑ?์ด๋ผ๋ ์ธก๋ฉด์์ ์ฌ์ฉํ๋ฉด ์ด๋ค์ง ์๊ฒฌ์ ์ฌ์ญค๋ณด๊ธฐ ์ํด ์ฌ์ฉํ์ต๋๋ค. |
@@ -0,0 +1,35 @@
+package christmas.domain.booking;
+
+import christmas.domain.booking.dto.MenuItem;
+import christmas.domain.booking.dto.MenuType;
+import java.util.Arrays;
+import java.util.List;
+
+public class Menu {
+ // APPETIZER
+ public static final MenuItem APPETIZER_1 = new MenuItem(MenuType.APPETIZER, "์์ก์ด์ํ", 6_000);
+ public static final MenuItem APPETIZER_2 = new MenuItem(MenuType.APPETIZER, "ํํ์ค", 5_500);
+ public static final MenuItem APPETIZER_3 = new MenuItem(MenuType.APPETIZER, "์์ ์๋ฌ๋", 8_000);
+
+ // MAIN
+ public static final MenuItem MAIN_1 = new MenuItem(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000);
+ public static final MenuItem MAIN_2 = new MenuItem(MenuType.MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000);
+ public static final MenuItem MAIN_3 = new MenuItem(MenuType.MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000);
+ public static final MenuItem MAIN_4 = new MenuItem(MenuType.MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000);
+
+ // DESSERT
+ public static final MenuItem DESSERT_1 = new MenuItem(MenuType.DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000);
+ public static final MenuItem DESSERT_2 = new MenuItem(MenuType.DESSERT, "์์ด์คํฌ๋ฆผ", 5_000);
+
+ // BEVERAGE
+ public static final MenuItem BEVERAGE_1 = new MenuItem(MenuType.BEVERAGE, "์ ๋ก์ฝ๋ผ", 3_000);
+ public static final MenuItem BEVERAGE_2 = new MenuItem(MenuType.BEVERAGE, "๋ ๋์์ธ", 60_000);
+ public static final MenuItem BEVERAGE_3 = new MenuItem(MenuType.BEVERAGE, "์ดํ์ธ", 25_000);
+
+ public static final List<MenuItem> MENU_ITEMS = Arrays.asList(
+ APPETIZER_1, APPETIZER_2, APPETIZER_3,
+ MAIN_1, MAIN_2, MAIN_3, MAIN_4,
+ DESSERT_1, DESSERT_2,
+ BEVERAGE_1, BEVERAGE_2, BEVERAGE_3
+ );
+} | Java | Enum์ ํ์ฉํด์ ๋ฉ๋ด๋ฅผ ๊ตฌํํด๋ณด์๋ ๊ฒ๋ ์ถ์ฒ๋๋ ค์! |
@@ -0,0 +1,33 @@
+package christmas.domain.payment.discount;
+
+import static christmas.domain.payment.constants.Constant.PRESENT_YEAR;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.Month;
+
+public enum DayType {
+ WEEKDAY,
+ WEEKEND;
+
+ public static boolean isWeekday(int day) {
+ LocalDate orderDate = LocalDate.of(PRESENT_YEAR, Month.DECEMBER, day);
+ DayOfWeek dayOfWeek = orderDate.getDayOfWeek();
+ if (isSunday(day)) {
+ return true;
+ }
+ return dayOfWeek.getValue() <= DayOfWeek.THURSDAY.getValue();
+ }
+
+ public static boolean isSunday(int day) {
+ LocalDate orderDate = LocalDate.of(PRESENT_YEAR, Month.DECEMBER, day);
+ DayOfWeek dayOfWeek = orderDate.getDayOfWeek();
+ return dayOfWeek.getValue() == DayOfWeek.SUNDAY.getValue();
+ }
+
+ public static boolean isWeekend(int day) {
+ LocalDate orderDate = LocalDate.of(PRESENT_YEAR, Month.DECEMBER, day);
+ DayOfWeek dayOfWeek = orderDate.getDayOfWeek();
+ return dayOfWeek.getValue() >= DayOfWeek.FRIDAY.getValue();
+ }
+} | Java | ๋๋จธ์ง ์ฐ์ฐ์ ํ์ฉํ๋ค๋ฉด ํ ์ธ ์กฐ๊ฑด์ ํ์ํ ์์ผ์ ๊ตฌํ๋ ์ฐ์ฐ์ ๋ ๊ฐ๊ฒฐํ๊ฒ ์์ฑํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,161 @@
+package christmas.service;
+
+import static christmas.domain.booking.MenuSearch.findMenuItem;
+import static christmas.domain.booking.constants.Constant.AMOUNT_INDEX;
+import static christmas.domain.booking.constants.Constant.AMOUNT_MAX;
+import static christmas.domain.booking.constants.Constant.FIRST_DAY;
+import static christmas.domain.booking.constants.Constant.LAST_DAY;
+import static christmas.domain.booking.constants.Constant.MENU_AMOUNT_DELIMITER;
+import static christmas.domain.booking.constants.Constant.MENU_INDEX;
+import static christmas.domain.booking.constants.Constant.MENU_TYPE_DELIMITER;
+import static christmas.domain.booking.constants.Constant.SEPARATE_TWO;
+import static christmas.exception.ErrorMessage.AMOUNT_OUT_OF_RANGE;
+import static christmas.exception.ErrorMessage.DATE_OUT_OF_RANGE;
+import static christmas.exception.ErrorMessage.REQUEST_INVALID_DATE;
+import static christmas.exception.ErrorMessage.REQUEST_INVALID_MENU;
+
+import christmas.domain.booking.MenuSearch;
+import christmas.domain.booking.dto.MenuItem;
+import christmas.domain.booking.dto.MenuType;
+import christmas.exception.PlannerException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class Parser {
+
+ public static int parseInt(String input) {
+ try {
+ validateOutOfRange(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw PlannerException.of(REQUEST_INVALID_DATE, exception);
+ }
+ }
+
+ private static void validateOutOfRange(String input) {
+ int day = Integer.parseInt(input);
+ if (FIRST_DAY <= day && day <= LAST_DAY) {
+ return;
+ }
+ throw PlannerException.from(DATE_OUT_OF_RANGE);
+ }
+
+ public static Map<MenuItem, Integer> splitMenuAndAmount(String input) {
+ Map<MenuItem, Integer> menuAndAmountMap = new HashMap<>();
+ try {
+ validateOmittedArgument(input);
+ validateDuplicateMenu(input);
+ validateFood(input);
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ Arrays.stream(menuAndAmount).forEach(entry -> processMenuEntry(entry, menuAndAmountMap));
+ validateEmpty(menuAndAmountMap);
+ validateAmount(sumAmount(menuAndAmountMap));
+ } catch (PlannerException exception) {
+ throw PlannerException.of(REQUEST_INVALID_MENU, exception);
+ }
+ return menuAndAmountMap;
+ }
+
+
+ private static void processMenuEntry(String entry, Map<MenuItem, Integer> menuAndAmountMap) {
+ String[] parts = entry.split(MENU_AMOUNT_DELIMITER);
+ Integer amount = 0;
+ try {
+ amount = Integer.parseInt(parts[AMOUNT_INDEX].trim());
+ } catch (NumberFormatException exception) {
+ throw PlannerException.of(REQUEST_INVALID_MENU, exception);
+ }
+ if (parts.length == SEPARATE_TWO) {
+ int eachAmount = Integer.parseInt(parts[AMOUNT_INDEX].trim());
+ validateAmount(eachAmount);
+ String menu = parts[MENU_INDEX].trim();
+ Optional<MenuItem> item = MenuSearch.findMenuItem(menu);
+ Integer finalAmount = amount;
+ item.ifPresent(menuItem -> menuAndAmountMap.put(menuItem, finalAmount));
+ }
+ }
+
+ private static int sumAmount(Map<MenuItem, Integer> menuAndAmountMap) {
+ return menuAndAmountMap.values()
+ .stream()
+ .mapToInt(Integer::intValue)
+ .sum();
+ }
+
+ private static void validateFood(String input) {
+ try {
+ onlyBeverage(input);
+ certainFoods(input);
+ } catch (PlannerException exception) {
+ throw PlannerException.of(REQUEST_INVALID_MENU, exception);
+ }
+ }
+
+ private static void certainFoods(String input) {
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ boolean allCertains = Arrays.stream(menuAndAmount)
+ .map(entry -> entry.split(MENU_AMOUNT_DELIMITER)[MENU_INDEX])
+ .allMatch(Parser::isCertainFood);
+ if (!allCertains) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static boolean isCertainFood(String menu) {
+ return findMenuItem(menu)
+ .map(menuItem -> Arrays.asList(MenuType.values()).contains(menuItem.type()))
+ .orElse(false);
+ }
+
+ private static void onlyBeverage(String input) {
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ boolean allMatch = Arrays.stream(menuAndAmount)
+ .map(entry -> entry.split(MENU_AMOUNT_DELIMITER)[MENU_INDEX])
+ .allMatch(menu -> findMenuItem(menu)
+ .map(menuItem -> menuItem.type() == MenuType.BEVERAGE)
+ .orElse(false)
+ );
+ if (allMatch) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static void validateDuplicateMenu(String input) {
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ String[] menus = Arrays.stream(menuAndAmount)
+ .map(entry -> entry.split(MENU_AMOUNT_DELIMITER)[MENU_INDEX])
+ .toArray(String[]::new);
+ if (Arrays.stream(menus).distinct().count() != menus.length) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+
+ private static void validateAmount(int amount) {
+ if (AMOUNT_INDEX <= amount && amount <= AMOUNT_MAX) {
+ return;
+ }
+ throw PlannerException.from(AMOUNT_OUT_OF_RANGE);
+ }
+
+ private static void validateEmpty(Map<MenuItem, Integer> menuAndAmountMap) {
+ if (menuAndAmountMap.isEmpty()) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static void validateOmittedArgument(String input) {
+ validateWhiteSpace(input);
+ if (input.endsWith(MENU_AMOUNT_DELIMITER) || input.endsWith(MENU_TYPE_DELIMITER)) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static void validateWhiteSpace(String input) {
+ if (input.contains(" ")) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+} | Java | ์ฐธ๊ณ : [๋ธ๋ก๊ทธ ๊ธ](https://velog.io/@kasania/Java-Static-import%EC%97%90-%EB%8C%80%ED%95%9C-%EA%B4%80%EC%B0%B0#static-import%EA%B0%80-%EC%9E%98%EB%AA%BB-%EC%82%AC%EC%9A%A9%EB%90%98%EB%8A%94-%EA%B2%BD%EC%9A%B0)
> static import๋ ์ ๋ง ์์ฃผ ์ฌ์ฉํ๋ ํด๋์ค์ "์ด๋ฆ๋ง ๋ณด์๋ ์ด๋์ ์ํ๋์ง ์ ์ ์๋," "์ ์ ๋ฉค๋ฒ" ๋ฅผ ์ฌ์ฉํ๋ ๋ฐ๋ง ์ฐ๋๋ก ํ์.
์ ๋ฐ์ ์ธ ์ฝ๋ ๊ตฌ์กฐ๋ฅผ ๋ชจ๋ฅด๋ ์ฌ๋์ `AMOUNT_INDEX`๋ง ๋ณด๋๋ผ๋ ์ด๊ฒ `domain.booking.constants.Constant.java` ํ์ผ์ ์๋ค๊ณ ์์ธกํ๊ธฐ๋ ํ๋ค ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,161 @@
+package christmas.service;
+
+import static christmas.domain.booking.MenuSearch.findMenuItem;
+import static christmas.domain.booking.constants.Constant.AMOUNT_INDEX;
+import static christmas.domain.booking.constants.Constant.AMOUNT_MAX;
+import static christmas.domain.booking.constants.Constant.FIRST_DAY;
+import static christmas.domain.booking.constants.Constant.LAST_DAY;
+import static christmas.domain.booking.constants.Constant.MENU_AMOUNT_DELIMITER;
+import static christmas.domain.booking.constants.Constant.MENU_INDEX;
+import static christmas.domain.booking.constants.Constant.MENU_TYPE_DELIMITER;
+import static christmas.domain.booking.constants.Constant.SEPARATE_TWO;
+import static christmas.exception.ErrorMessage.AMOUNT_OUT_OF_RANGE;
+import static christmas.exception.ErrorMessage.DATE_OUT_OF_RANGE;
+import static christmas.exception.ErrorMessage.REQUEST_INVALID_DATE;
+import static christmas.exception.ErrorMessage.REQUEST_INVALID_MENU;
+
+import christmas.domain.booking.MenuSearch;
+import christmas.domain.booking.dto.MenuItem;
+import christmas.domain.booking.dto.MenuType;
+import christmas.exception.PlannerException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class Parser {
+
+ public static int parseInt(String input) {
+ try {
+ validateOutOfRange(input);
+ return Integer.parseInt(input);
+ } catch (NumberFormatException exception) {
+ throw PlannerException.of(REQUEST_INVALID_DATE, exception);
+ }
+ }
+
+ private static void validateOutOfRange(String input) {
+ int day = Integer.parseInt(input);
+ if (FIRST_DAY <= day && day <= LAST_DAY) {
+ return;
+ }
+ throw PlannerException.from(DATE_OUT_OF_RANGE);
+ }
+
+ public static Map<MenuItem, Integer> splitMenuAndAmount(String input) {
+ Map<MenuItem, Integer> menuAndAmountMap = new HashMap<>();
+ try {
+ validateOmittedArgument(input);
+ validateDuplicateMenu(input);
+ validateFood(input);
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ Arrays.stream(menuAndAmount).forEach(entry -> processMenuEntry(entry, menuAndAmountMap));
+ validateEmpty(menuAndAmountMap);
+ validateAmount(sumAmount(menuAndAmountMap));
+ } catch (PlannerException exception) {
+ throw PlannerException.of(REQUEST_INVALID_MENU, exception);
+ }
+ return menuAndAmountMap;
+ }
+
+
+ private static void processMenuEntry(String entry, Map<MenuItem, Integer> menuAndAmountMap) {
+ String[] parts = entry.split(MENU_AMOUNT_DELIMITER);
+ Integer amount = 0;
+ try {
+ amount = Integer.parseInt(parts[AMOUNT_INDEX].trim());
+ } catch (NumberFormatException exception) {
+ throw PlannerException.of(REQUEST_INVALID_MENU, exception);
+ }
+ if (parts.length == SEPARATE_TWO) {
+ int eachAmount = Integer.parseInt(parts[AMOUNT_INDEX].trim());
+ validateAmount(eachAmount);
+ String menu = parts[MENU_INDEX].trim();
+ Optional<MenuItem> item = MenuSearch.findMenuItem(menu);
+ Integer finalAmount = amount;
+ item.ifPresent(menuItem -> menuAndAmountMap.put(menuItem, finalAmount));
+ }
+ }
+
+ private static int sumAmount(Map<MenuItem, Integer> menuAndAmountMap) {
+ return menuAndAmountMap.values()
+ .stream()
+ .mapToInt(Integer::intValue)
+ .sum();
+ }
+
+ private static void validateFood(String input) {
+ try {
+ onlyBeverage(input);
+ certainFoods(input);
+ } catch (PlannerException exception) {
+ throw PlannerException.of(REQUEST_INVALID_MENU, exception);
+ }
+ }
+
+ private static void certainFoods(String input) {
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ boolean allCertains = Arrays.stream(menuAndAmount)
+ .map(entry -> entry.split(MENU_AMOUNT_DELIMITER)[MENU_INDEX])
+ .allMatch(Parser::isCertainFood);
+ if (!allCertains) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static boolean isCertainFood(String menu) {
+ return findMenuItem(menu)
+ .map(menuItem -> Arrays.asList(MenuType.values()).contains(menuItem.type()))
+ .orElse(false);
+ }
+
+ private static void onlyBeverage(String input) {
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ boolean allMatch = Arrays.stream(menuAndAmount)
+ .map(entry -> entry.split(MENU_AMOUNT_DELIMITER)[MENU_INDEX])
+ .allMatch(menu -> findMenuItem(menu)
+ .map(menuItem -> menuItem.type() == MenuType.BEVERAGE)
+ .orElse(false)
+ );
+ if (allMatch) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static void validateDuplicateMenu(String input) {
+ String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
+ String[] menus = Arrays.stream(menuAndAmount)
+ .map(entry -> entry.split(MENU_AMOUNT_DELIMITER)[MENU_INDEX])
+ .toArray(String[]::new);
+ if (Arrays.stream(menus).distinct().count() != menus.length) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+
+ private static void validateAmount(int amount) {
+ if (AMOUNT_INDEX <= amount && amount <= AMOUNT_MAX) {
+ return;
+ }
+ throw PlannerException.from(AMOUNT_OUT_OF_RANGE);
+ }
+
+ private static void validateEmpty(Map<MenuItem, Integer> menuAndAmountMap) {
+ if (menuAndAmountMap.isEmpty()) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static void validateOmittedArgument(String input) {
+ validateWhiteSpace(input);
+ if (input.endsWith(MENU_AMOUNT_DELIMITER) || input.endsWith(MENU_TYPE_DELIMITER)) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+
+ private static void validateWhiteSpace(String input) {
+ if (input.contains(" ")) {
+ throw PlannerException.from(REQUEST_INVALID_MENU);
+ }
+ }
+} | Java | ์ด๋์ ๊ฐ ๋ดค์๋๋ฐ, "try ์์ ์๋ ํ๋๋ ํ๋์ ์ญํ ์ด๋ผ ๋ณผ ์ ์๊ธฐ ๋๋ฌธ์ ํ์ค๋ก ๋ค์ด๊ฐ๋ ๊ฒ์ด ์ข๋ค"๋ผ๊ณ ํฉ๋๋ค.
```java
public static Map<MenuItem, Integer> splitMenuAndAmount(String input) {
Map<MenuItem, Integer> menuAndAmountMap = new HashMap<>();
try {
validate(input);
} catch (PlannerException exception) {
throw PlannerException.of(REQUEST_INVALID_MENU, exception);
}
return menuAndAmountMap;
}
public static Map<MenuItem, Integer> validate(String input) {
validateOmittedArgument(input);
validateDuplicateMenu(input);
validateFood(input);
String[] menuAndAmount = input.split(MENU_TYPE_DELIMITER);
Arrays.stream(menuAndAmount).forEach(entry -> processMenuEntry(entry, menuAndAmountMap));
validateEmpty(menuAndAmountMap);
validateAmount(sumAmount(menuAndAmountMap));
}
``` |
@@ -0,0 +1,35 @@
+package christmas.view.output;
+
+import static christmas.domain.booking.constants.Message.AMOUNT_BEFORE_DISCOUNT;
+import static christmas.domain.booking.constants.Message.ORDER;
+import static christmas.domain.booking.constants.Message.ORDER_DETAIL;
+import static christmas.domain.booking.constants.Message.RECEPTION;
+
+import christmas.domain.booking.dto.BookMessage;
+import java.text.DecimalFormat;
+
+public class BookingWriterView extends OutputView {
+ private BookingWriterView() {
+ }
+
+ public static void MenuOrder(BookMessage bookMessage) {
+ String message = String.format(RECEPTION.getMessage(), bookMessage.reservationDay());
+ long[] amount = {0};
+ bookMessage.menuAndAmountMap().forEach((key, value) -> {
+ amount[0] += (long) key.price() * value;
+ });
+ println(message);
+ println(ORDER.getMessage());
+ bookMessage.menuAndAmountMap().forEach((key, value) -> {
+ println(String.format(ORDER_DETAIL.getMessage(), key.name(), value));
+
+ });
+ totalRawPrice(amount);
+ }
+
+ private static void totalRawPrice(long[] amount) {
+ DecimalFormat df = new DecimalFormat("#,###");
+ String formatted = df.format(amount[0]);
+ println(String.format(AMOUNT_BEFORE_DISCOUNT.getMessage(), formatted));
+ }
+} | Java | ์ค static method ๋ฐ์ ์์ด ์ธ๋ถ์์ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๊ฒ์ ๋ง์ผ์
จ๊ตฐ์! |
@@ -0,0 +1,35 @@
+package christmas.view.output;
+
+import static christmas.domain.booking.constants.Message.AMOUNT_BEFORE_DISCOUNT;
+import static christmas.domain.booking.constants.Message.ORDER;
+import static christmas.domain.booking.constants.Message.ORDER_DETAIL;
+import static christmas.domain.booking.constants.Message.RECEPTION;
+
+import christmas.domain.booking.dto.BookMessage;
+import java.text.DecimalFormat;
+
+public class BookingWriterView extends OutputView {
+ private BookingWriterView() {
+ }
+
+ public static void MenuOrder(BookMessage bookMessage) {
+ String message = String.format(RECEPTION.getMessage(), bookMessage.reservationDay());
+ long[] amount = {0};
+ bookMessage.menuAndAmountMap().forEach((key, value) -> {
+ amount[0] += (long) key.price() * value;
+ });
+ println(message);
+ println(ORDER.getMessage());
+ bookMessage.menuAndAmountMap().forEach((key, value) -> {
+ println(String.format(ORDER_DETAIL.getMessage(), key.name(), value));
+
+ });
+ totalRawPrice(amount);
+ }
+
+ private static void totalRawPrice(long[] amount) {
+ DecimalFormat df = new DecimalFormat("#,###");
+ String formatted = df.format(amount[0]);
+ println(String.format(AMOUNT_BEFORE_DISCOUNT.getMessage(), formatted));
+ }
+} | Java | - ํ๋ฆฌ์ฝ์ค 1์ฃผ์ฐจ ๊ณตํต ํผ๋๋ฐฑ ์ค
> ์ถ์ฝํ์ง ์๋๋ค
์๋๋ฅผ ๋๋ฌ๋ผ ์ ์๋ค๋ฉด ์ด๋ฆ์ด ๊ธธ์ด์ ธ๋ ๊ด์ฐฎ๋ค.
๋๊ตฌ๋ ์ค์ ํด๋์ค, ๋ฉ์๋, ๋๋ ๋ณ์์ ์ด๋ฆ์ ์ค์ด๋ ค๋ ์ ํน์ ๊ณง์ ๋น ์ง๊ณค ํ๋ค. ๊ทธ๋ฐ ์ ํน์ ๋ฟ๋ฆฌ์ณ๋ผ. ์ถ์ฝ์ ํผ๋์ ์ผ๊ธฐํ๋ฉฐ, ๋ ํฐ ๋ฌธ์ ๋ฅผ ์จ๊ธฐ๋ ๊ฒฝํฅ์ด ์๋ค. ํด๋์ค์ ๋ฉ์๋ ์ด๋ฆ์ ํ ๋ ๋จ์ด๋ก ์ ์งํ๋ ค๊ณ ๋
ธ๋ ฅํ๊ณ ๋ฌธ๋งฅ์ ์ค๋ณตํ๋ ์ด๋ฆ์ ์์ ํ์. ํด๋์ค ์ด๋ฆ์ด Order๋ผ๋ฉด shipOrder๋ผ๊ณ ๋ฉ์๋ ์ด๋ฆ์ ์ง์ ํ์๊ฐ ์๋ค. ์งง๊ฒ ship()์ด๋ผ๊ณ ํ๋ฉด ํด๋ผ์ด์ธํธ์์๋ order.ship()๋ผ๊ณ ํธ์ถํ๋ฉฐ, ๊ฐ๊ฒฐํ ํธ์ถ์ ํํ์ด ๋๋ค.
๊ฐ์ฒด ์งํฅ ์ํ ์ฒด์กฐ ์์น 5: ์ค์ฌ์ฐ์ง ์๋๋ค (์ถ์ฝ ๊ธ์ง)
- `new DecimalFormat("#,###")`์ ๋งค๋ฒ ์์ฑํ์ง ์์๋ ๋๋ฏ๋ก `private static final`๋ก ํด๋์ค ๋ณ์๋ก ์ ์ธํด์ ์ฐ์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค! |
@@ -0,0 +1,6 @@
+package christmas.view.output;
+
+public class PaymentWriterView extends OutputView {
+ public PaymentWriterView() {
+ }
+} | Java | ์ด ํด๋์ค๋ ๋ฌด์์ ์ํ ๊ฒ์ผ๊น์? |
@@ -0,0 +1,33 @@
+package christmas.controller;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import christmas.domain.booking.dto.MenuItem;
+import christmas.domain.booking.dto.MenuType;
+import christmas.service.Parser;
+import christmas.service.Payment;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+class PaymentControllerTest {
+
+ @Test
+ void getRawTotal() {
+ // given
+ int reservationDay = 26;
+ Map<MenuItem, Integer> expected = new HashMap<>();
+ Map<MenuItem, Integer> menuAndAmountMap = new HashMap<>();
+ MenuItem MenuItem1 = new MenuItem(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000);
+ MenuItem MenuItem2 = new MenuItem(MenuType.MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000);
+ expected.put(MenuItem1, 1);
+ expected.put(MenuItem2, 1);
+ menuAndAmountMap = Parser.splitMenuAndAmount("ํฐ๋ณธ์คํ
์ดํฌ-1,๋ฐ๋นํ๋ฆฝ-1");
+ Payment payment = new Payment(reservationDay, menuAndAmountMap);
+ // when
+ int expectedTotal = 109_000;
+ int actualTotal = payment.getRawTotal(menuAndAmountMap);
+ // then
+ assertEquals(expectedTotal, actualTotal);
+ }
+}
\ No newline at end of file | Java | - ๋ฉ์๋์ ์ด๋ฆ์ ํตํด ํด๋น ์ฝ๋๊ฐ ์ด๋ค ์ํฉ์์ ๋ฌด์์ ํ
์คํธ ํ์๋์ง ๋ํ๋ด์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. ๋์ค์ ๋ค๋ฅธ์ฌ๋์ด ์์ ๋ณด๋๋ผ๋ ๋ญ ํ
์คํธํ๋์ง ์์๋ณด๊ธฐ ์ฌ์์ผ ํ๋๊น์
- `assertEquals()`๋ณด๋ค๋ `assertThat().isEqualTo()`๋ฅผ ์ฌ์ฉํ์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. ์์ด ๋ฌธ์ฅ ์์์ ๋์ผํ๊ฒ ๋์ด์์ด ํจ์ฌ ์ฝ๊ธฐ ์ฝ์ต๋๋ค.
- ์๋ ์ฝ๋๋ ์ ๊ฐ ์์ฑํ ํ
์คํธ ์์์
๋๋ค.
```java
@ParameterizedTest(name = "{0}; ๋์ ํธ ๋ฉ๋ด ๊ฐ์ : {1}")
@MethodSource
@DisplayName("์ฃผ๋ฌธํ ์ด ๋์ ํธ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
์ ์๋ค")
void countDessertMenuTest(Map<Menu, Integer> menuToCount, int expected) {
Order order = Order.from(menuToCount);
int actual = order.countDessertMenu();
assertThat(actual).isEqualTo(expected);
}
private static Stream<Arguments> countDessertMenuTest() {
return Stream.of(
Arguments.of(Map.of(DRINK_EXAMPLE, 3, DESSERT_EXAMPLE, 4), 4),
Arguments.of(Map.of(MAIN_EXAMPLE, 5, APPETIZER_EXAMPLE, 3), 0),
Arguments.of(Map.of(Menu.CHOCOLATE_CAKE, 6, Menu.ICE_CREAM, 4), 10)
);
}
``` |
@@ -0,0 +1,101 @@
+import React, { useEffect } from 'react';
+import styled from 'styled-components';
+import { BiMessageAlt } from 'react-icons/bi';
+import { useIssues } from '../hooks/useIssues';
+import { IssueSchema } from '../types/issuesApi';
+import { Link } from 'react-router-dom';
+import AD from '../components/AD';
+import InfiniteScroll from '../components/InfiniteScroll';
+
+function Times(date: number) {
+ let times;
+ const time = Math.floor(date / (1000 * 60 * 60)); // ์๊ฐ
+ const day = Math.floor(date / (1000 * 60 * 60 * 24)); // ์ผ
+ const year = Math.floor(date / (1000 * 60 * 60 * 24 * 365)); // ๋
+
+ if (year > 0) {
+ times = `${year}๋
์ `;
+ } else if (day > 0) {
+ times = `${day}์ผ ์ `;
+ } else {
+ times = `${time}์๊ฐ ์ `;
+ }
+ return times;
+}
+
+function Home() {
+ const { issueList, fetchIssues, isLoading } = useIssues();
+
+ useEffect(() => {
+ fetchIssues();
+ }, []);
+
+ return (
+ <>
+ {issueList?.map((issue: IssueSchema, index: number) => {
+ const currentTime = new Date();
+ const createdAt = new Date(issue.created_at);
+ const timeDifference = currentTime.getTime() - createdAt.getTime();
+
+ return (
+ <React.Fragment key={issue.id}>
+ <InfiniteScroll>
+ <Container>
+ <Issues>
+ <Item>
+ <IssueLink to={`/issues/${issue.number}`}>{issue.title}</IssueLink>
+ <OpenedBy>
+ #{issue.number} opened {Times(timeDifference)} by {issue.user.login}
+ </OpenedBy>
+ </Item>
+ <Comment>
+ <BiMessageAlt /> {issue.comments}
+ </Comment>
+ </Issues>
+ </Container>
+ {<AD key={index} index={index} />}
+ </InfiniteScroll>
+ </React.Fragment>
+ );
+ })}
+ {isLoading && <span>Loading...</span>}
+ </>
+ );
+}
+
+export default Home;
+
+const Container = styled.div`
+ border: 1px solid black;
+ height: auto;
+ padding: 8px;
+ &:hover {
+ background-color: lightgray;
+ }
+`;
+
+const Issues = styled.li`
+ width: 100%;
+ display: flex;
+ justify-content: space-between;
+`;
+
+const Item = styled.div`
+ display: block;
+ flex: auto;
+`;
+
+const IssueLink = styled(Link)`
+ font-weight: bold;
+`;
+
+const OpenedBy = styled.span`
+ font-size: small;
+ margin-top: 1px;
+ display: flex;
+ color: whitegray;
+`;
+
+const Comment = styled.div`
+ white-space: nowrap;
+`; | Unknown | ์ต์ด ๋ก๋ฉ์ ์ ๋ณด์ด๋๋ฐ, ๋ฌดํ ์คํฌ๋กค์ ๋ก๋ฉ์ด ์๋ ค์ ๊ทธ๋ฐ๊ฑด์ง ์ ์๋ณด์ด๋ ๊ฒ ๊ฐ์๋ฐ ๋ง๋์? ์ธํฐ๋ท ๋๋ฆฌ๊ฒ ๋ณ๊ฒฝํด๋ ์๋ณด์ด๋ค์ ใ
ใ
|
@@ -0,0 +1,15 @@
+import { Outlet } from 'react-router-dom';
+import { styled } from 'styled-components';
+
+const Title = styled.h1`
+ text-align: center;
+`;
+
+export function Header() {
+ return (
+ <>
+ <Title>facebook/react</Title>
+ <Outlet />
+ </>
+ );
+} | Unknown | ์ปดํฌ๋ํธ๋ช
๊ณผ ํ์ผ๋ช
์ด ์ผ์นํ๋๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค
๋ ๊ฐ์ฌ๋์ด facebook/react๋ฅผ ํ๋์ฝ๋ฉ ์ํ๋ ๋ฐฉ์์ด ์ข์ ๊ฒ ๊ฐ๋ค๊ณ ํ์
์
๋ค๋ฅธ ๋ฐฉ๋ฒ๋ ์๊ฐํด๋ณด์๋ฉด ์ข์๊ฒ ๊ฐ๋ค์ :) |
@@ -0,0 +1,41 @@
+import React from 'react';
+import { useIssue } from '../hooks/useIssue';
+import { useParams } from 'react-router-dom';
+import { styled } from 'styled-components';
+import MarkdownViewer from '../components/MarkDownViewer';
+
+function Detail() {
+ const { issue, fetchIssue, isLoading } = useIssue();
+ const { id } = useParams();
+
+ React.useEffect(() => {
+ if (id) {
+ const parsedId = parseInt(id);
+ fetchIssue(parsedId);
+ }
+ }, []);
+
+ if (isLoading) return <div>Loading...</div>;
+ return (
+ <>
+ <Title>
+ <bdi>{issue?.title}</bdi>
+ <span>#{issue?.number}</span>
+ </Title>
+ <br />
+ <>
+ <MarkdownViewer markdown={issue?.body} />
+ </>
+ </>
+ );
+}
+
+export default Detail;
+
+const Title = styled.h1`
+ span {
+ color: gray;
+ font-size: 0.7em;
+ margin-left: 5px;
+ }
+`; | Unknown | ๊ณผ์ ํ์ด์ง์์ ์ด์ ์์ธ ํ๋ฉด์ชฝ ๊ตฌํํด์ผ ํ๋ ๋ด์ฉ์ ๋ณด๋ฉด
`์ด์๋ฒํธ, ์ด์์ ๋ชฉ, ์์ฑ์, ์์ฑ์ผ, ์ฝ๋ฉํธ ์, ์์ฑ์ ํ๋กํ ์ด๋ฏธ์ง, ๋ณธ๋ฌธ ํ์` ๋ผ๊ณ ๋์ด์์ต๋๋ค. issue์ ๋ณด๋ค์ ๋ ์ถ๊ฐํด์ผ ํ์ง ์์๊น ์ถ์ด์ |
@@ -0,0 +1,41 @@
+import React from 'react';
+import { useIssue } from '../hooks/useIssue';
+import { useParams } from 'react-router-dom';
+import { styled } from 'styled-components';
+import MarkdownViewer from '../components/MarkDownViewer';
+
+function Detail() {
+ const { issue, fetchIssue, isLoading } = useIssue();
+ const { id } = useParams();
+
+ React.useEffect(() => {
+ if (id) {
+ const parsedId = parseInt(id);
+ fetchIssue(parsedId);
+ }
+ }, []);
+
+ if (isLoading) return <div>Loading...</div>;
+ return (
+ <>
+ <Title>
+ <bdi>{issue?.title}</bdi>
+ <span>#{issue?.number}</span>
+ </Title>
+ <br />
+ <>
+ <MarkdownViewer markdown={issue?.body} />
+ </>
+ </>
+ );
+}
+
+export default Detail;
+
+const Title = styled.h1`
+ span {
+ color: gray;
+ font-size: 0.7em;
+ margin-left: 5px;
+ }
+`; | Unknown | ์.. ๊ทธ๋ฌ๋ค์ ์ ๊ฐ ์ ๋ถ๋ถ์ ๋ชป๋ดค๋๊ฑฐ ๊ฐ์ต๋๋ค |
@@ -6,25 +6,33 @@ import { css } from '@emotion/react';
import Rating from '@/components/Rating';
import Profile from '../Profile';
import { formatDate } from '@/utils/format';
+import useModalStore from '@/stores/useModalStore';
+import useDeleteReview from '@/hooks/query/useDeleteReview';
+import ConfirmModal from '@/components/ConfirmModal';
interface ReviewCardProps {
review: Review;
- onDelete?: () => void;
showTitle: boolean;
showUser: boolean;
showDate: boolean;
showDelete: boolean;
}
-const ReviewCard = ({
- review,
- onDelete,
- showTitle,
- showUser,
- showDate,
- showDelete,
-}: ReviewCardProps) => {
- // console.log(review.imgSrc.map((src, index) => src);
+const ReviewCard = ({ review, showTitle, showUser, showDate, showDelete }: ReviewCardProps) => {
+ const setModalName = useModalStore((state) => state.setModalName);
+ const { mutate } = useDeleteReview();
+
+ const handleDelete = () => {
+ mutate(
+ { reviewId: review.reviewId },
+ {
+ onSuccess: () => {
+ setModalName(null);
+ },
+ },
+ );
+ };
+
return (
<div css={reviewStyle}>
<div className="titleStyle">
@@ -52,7 +60,21 @@ const ReviewCard = ({
<Rating rating={Number(review.rating)} />
</div>
</div>
- {showDelete && <DeleteIcon onDelete={onDelete || (() => {})} />}
+ {showDelete && (
+ <ConfirmModal
+ modalId={`my.review.delete.${review.reviewId}`}
+ onConfirm={handleDelete}
+ trigger={
+ <DeleteIcon onClick={() => setModalName(`my.review.delete.${review.reviewId}`)} />
+ }
+ message={
+ <div css={modalStyle}>
+ <p className="modalText">์ ๋ง ๋ฆฌ๋ทฐ๋ฅผ ์ญ์ ํ์๊ฒ ์ต๋๊น?</p>
+ <p className="modalSubText">์ ์ ํ์ ์ ์ญ์ ๋์ง ์์ต๋๋ค</p>
+ </div>
+ }
+ />
+ )}
</div>
<div
css={css`
@@ -134,15 +156,16 @@ const reviewStyle = css`
.imgContainer {
display: flex;
justify-content: center;
- width: 110px;
- height: 120px;
+ width: 120px;
+ height: 100px;
margin-bottom: 16px;
border-radius: 5px;
overflow: hidden;
}
img {
width: 100%;
+ object-fit: cover;
}
.ratingContainer {
@@ -155,3 +178,17 @@ const reviewStyle = css`
transform: translateY(-3px);
}
`;
+
+const modalStyle = css`
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ .modalText {
+ font-weight: 600;
+ }
+
+ .modalSubText {
+ font-size: 14px;
+ color: #999;
+ }
+`; | Unknown | _:hammer_and_wrench: Refactor suggestion_
**์๋ฌ ์ฒ๋ฆฌ ๋ก์ง ์ถ๊ฐ ํ์**
`handleDelete` ํจ์์์ mutation ์คํจ ์์ ์๋ฌ ์ฒ๋ฆฌ๊ฐ ๋๋ฝ๋์ด ์์ต๋๋ค.
๋ค์๊ณผ ๊ฐ์ด `onError` ํธ๋ค๋ฌ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ ์ ์ํฉ๋๋ค:
```diff
const handleDelete = () => {
mutate(
{ reviewId: review.reviewId },
{
onSuccess: () => {
setModalName(null);
},
+ onError: (error) => {
+ console.error('๋ฆฌ๋ทฐ ์ญ์ ์คํจ:', error);
+ // ์๋ฌ ๋ฉ์์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ํ์ํ๋ ๋ก์ง ์ถ๊ฐ
+ },
},
);
};
```
<!-- suggestion_start -->
<details>
<summary>๐ Committable suggestion</summary>
> โผ๏ธ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
`````suggestion
const ReviewCard = ({ review, showTitle, showUser, showDate, showDelete }: ReviewCardProps) => {
const setModalName = useModalStore((state) => state.setModalName);
const { mutate } = useDeleteReview();
const handleDelete = () => {
mutate(
{ reviewId: review.reviewId },
{
onSuccess: () => {
setModalName(null);
},
onError: (error) => {
console.error('๋ฆฌ๋ทฐ ์ญ์ ์คํจ:', error);
// ์๋ฌ ๋ฉ์์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ํ์ํ๋ ๋ก์ง ์ถ๊ฐ
},
},
);
};
`````
</details>
<!-- suggestion_end -->
<!-- This is an auto-generated comment by CodeRabbit --> |
@@ -0,0 +1,21 @@
+import styled from "styled-components";
+import { flexCenter } from "@/styles/common";
+import { Product } from "@/types/products";
+import ItemCartMemo from "@/components/ItemCard";
+
+const ItemCardList = ({ products }: { products: Product[] }) => {
+ return (
+ <ItemCardWrapper>
+ {products && products.map((product) => <ItemCartMemo key={`${product.id}`} product={product} />)}
+ </ItemCardWrapper>
+ );
+};
+
+export default ItemCardList;
+
+const ItemCardWrapper = styled.div`
+ display: flex;
+ gap: 14px;
+ flex-wrap: wrap;
+ ${flexCenter}
+`; | Unknown | key ๊ฐ์ ์ด๋ ๊ฒ ๋๋ค์ผ๋ก ๊ด๋ฆฌ๋ฅผ ํ์
จ๊ตฐ์ ! ์ ๋ key ๊ฐ์ ๋ํ ๊ณ ๋ฏผ์ด ์์๋๋ฐ ๋ณดํต ์ด ๋ฐฉ๋ฒ์ด ๋ณดํธ์ ์ผ๋ก ์ฌ์ฉ๋๋ ๋ฐฉ๋ฒ์ธ์ง ๊ถ๊ธํฉ๋๋ค ๐ |
@@ -0,0 +1,21 @@
+import styled from "styled-components";
+import { flexCenter } from "@/styles/common";
+import { Product } from "@/types/products";
+import ItemCartMemo from "@/components/ItemCard";
+
+const ItemCardList = ({ products }: { products: Product[] }) => {
+ return (
+ <ItemCardWrapper>
+ {products && products.map((product) => <ItemCartMemo key={`${product.id}`} product={product} />)}
+ </ItemCardWrapper>
+ );
+};
+
+export default ItemCardList;
+
+const ItemCardWrapper = styled.div`
+ display: flex;
+ gap: 14px;
+ flex-wrap: wrap;
+ ${flexCenter}
+`; | Unknown | ๋ฆฌ๋ทฐ์ด์๊ฒ ๋ฌผ์ด๋ดค๋๋ UUID๋ฅผ ์ถ์ฒํ์๋๋ผ๊ตฌ์! ์ฌ๋ฐ์ด์ฒ๋ผ 'product-id' ๋ฅผ ์ฌ์ฉํด์ ๋์ ์ธ id๋ฅผ ์์ฑํด์ฃผ๋ ๊ฒ๋ ์ ๋ง ์ข์ ๊ฒ ๊ฐ์์ ๊ทธ๋ ๊ฒ ๋ฐ๊ฟ๋ณด๋ ค๊ตฌ์! ๊ฐ์ฌํฉ๋๋ค |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | ํน์ ์ด๋ฒ ๋ฏธ์
์์ Compound Component ์ฌ์ฉ์ ๋ํ ๊ณ ๋ฏผ์ด ์์ผ์
จ์๊น์?
์ง๊ธ Modal์ ์ธํฐํ์ด์ค๋ฅผ ๋ณด๋ฉด, ๋ชจ๋ ์ต์
๋ค์ด prop์ผ๋ก ๋ค์ด์ค๊ณ ์์ด์ ๊ด์ฌ์ฌ ๋ณ๋ก ๋๋์ด ํ์ธํ๋ ๋ฐ ์ค๋๊ฑธ๋ฆฌ๋ ๊ฒ ๊ฐ์์..! ์๋ฅผ ๋ค๋ฉด, ๋ชจ๋ฌ์ ์ธ์ ์ธ ์์์ธ size, position์ ๋ฌถ์ด์ ์๊ฐํด์ผ ๋ ๋ ๊ทธ ๋์ ํ ๋์ ํ์
ํ๊ธฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์ต๋๋ค!
๋ง์ฝ props์ผ๋ก ๊ด๋ฆฌํ๋ค๋ฉด, ๊ด์ฌ์ฌ ๋ณ๋ก ์กฐ๊ธ ๋ญ์ณ๋ณด๋ฉด ์ด๋จ๊น์? ์๋ ์์ ์ฝ๋ ์ฒ๋ผ์!
```typescript
interface ModalProps {
isOpened: boolean;
size?: ModalSize;
modalPosition?: ModalPosition;
title?: string;
showCloseButton?: boolean;
description?: string;
buttonPosition?: ButtonPosition;
primaryButton?: ButtonProps;
secondaryButton?: ButtonProps;
primaryColor?: string;
children?: JSX.Element;
onClose: () => void;
}
``` |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | ์ค.. ๋ฐ๋ค๊ฐ ๊ณต์ ํด ์ค createPortal์ ์ฌ์ฉํ์
จ๊ตฐ์! createPortal์ ์ฌ์ฉํ๋ฉด์ ์ป์ ์ธ์ฌ์ดํธ๋ ๋๋ ๋ฐ๊ฐ ์๋ค๋ฉด ๊ณต์ ํด์ฃผ์๋ฉด ์ ๋ง ์ข์ ๊ฒ ๊ฐ์์~~~
๋, Modal ์ปดํฌ๋ํธ์ UI ๋ก์ง์ ์ ๋ง ์ ๋๋ ์ ํ ๋์ ํ ๋ณด์ฌ์ ์ข์ต๋๋ค! |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | ๋ชจ๋ฌ ๋ด๋ถ์ ๊ฐ ์น์
์ ์ปดํฌ๋ํธ๋ก ๋ถ๋ฆฌํ์ฌ ์ฌ์ฌ์ฉ ํ ์ ์ด ์ธ์์ ์
๋๋ค!
์ปดํฌ๋ํธ๋ฅผ ์ ๋๋์ด์ Alert, Confirm, Prompt์ ๊ฐ์ ์ถ๊ฐ์ ์ธ ์๊ตฌ์ฌํญ์ด ์๋ ํฐ ๋ฌธ์ ์์ด ๋์ํ ์ ์๊ฒ ๋ค์!! |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | ๋ค ๋ง์์! Compound Component๋ฅผ ์ฌ์ฉํ๋ฉด, ์ฃผ์ด์ง alert, comfirm, prompt, ๊ทธ๋ฆฌ๊ณ ์ถํ ์ถ๊ฐ์ ์ผ๋ก ๋ฐ์ํ ์ ์๋ ์๊ตฌ์ฌํญ modal type์ ๋ง์ถฐ์ ์์ฝ๊ฒ ๋์์ด ๊ฐ๋ฅํ์ง ์์๊น ์๊ฐํ์ต๋๋ค!
๋ค๋ง, compound component์ ์ง์์ด ๋ถ์กฑํ๊ณ ์ฌ๊ธฐ์ ์์ ์๊ฐ์ด ๋ถ์กฑํด์ compound component์ ์ฅ์ ์ ์ ๋๋ก ์ด๋ฆฌ์ง ๋ชปํ๋ ๊ฒ ๊ฐ๋ค์!
interface๋ฅผ ์์ฑํ๊ณ docs๋ฅผ ์์ฑํ ๋ ์ ์ค์ค๋ก๋ ์์๊ฐ ํท๊ฐ๋ฆฌ๊ณ ์ด๋ป๊ฒ ์ ๋ ฌํด์ผ ์ข์์ง ๊ณ ๋ฏผ์ด์๋๋ฐ ๋ง์ํด ์ฃผ์ ๋๋ก ๊ด์ฌ์ฌ ๋ณ๋ก ๋ญ์ณ์ ์์ฑํ๋๊ฒ ์ข์ ๋ฐฉ๋ฒ์ด ๋ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | ์ฐ์ createPortal์ ์ด์ฉํด์ document.body๋ก ์์น๋ฅผ ์ฎ๊ฒจ์ฃผ๋ค ๋ณด๋ ๋ค๋ฅธ stack context๊ฐ ๋์ด์ z-Index ๊ด๋ฆฌ์ ์ ์ฉํ๋ค๋ ์ ์ด์์ด์!
๋ง์ฝ ์ฌ์ฉํ๋ ์ ์ ๊ฐ
```xml
<body>
<app>
<Modal />
<OtherComponent />
</app>
</body>
```
์ ๊ฐ์ด ์ฌ์ฉํ๋ค๊ณ ํ์ ๋, ์ ํฌ๊ฐ ์ ๊ณตํ๋ modal์ zindex๊ฐ 300 ์ด๊ณ , use์ OtherComponent์ zindex๊ฐ 500์ด๋ผ๋ฉด ์ด ๋์ ๊ฐ์ stack context์ ์๊ธฐ ๋๋ฌธ์, modal ์๋ก OtherComponent๊ฐ ์ฌ๋ผ์ฌ ์ ์๋ ๋ฌธ์ ์ ์ด ์๊ฒ ์ฃ !
์ค์ ๋ก step1์์ ์ด๋ฐ ํผ๋๋ฐฑ์ ๋ฐ์๊ณ , step1์ ๋ฆฌ๋ทฐ ๋ฐ์์์๋ Modal์ zindex๋ฅผ prop์ผ๋ก ๋ฐ์์ ์ฌ์ฉํ ์ ์๊ฒ ํ์์ด์.
ํ์ง๋ง ๊ฒฐ๊ตญ ์ฌ์ฉ์๋ component๋ค๊ณผ modal์ zindex๋ค์ ๋ํด์ ๋ง์ ์ดํด๊ฐ ํ์ํ๊ฒ ๋๊ธฐ ๋๋ฌธ์ ์๋ก์ด component๋ฅผ ์ถ๊ฐํ๋ ค๊ณ ํ ๋๋ ์ด๋ฅผ ๊ณ ๋ฏผํด์ผ ํ ๊ฒ ๊ฐ์์ด์.
```xml
<body>
<app>
<OtherComponent />
</app>
<Modal />
</body>
```
ํ์ง๋ง createPortal์ ์ด์ฉํด document.body๋ก ๋ฌผ๋ฆฌ์ ์ธ ์์น๋ฅผ ๋ณ๊ฒฝํด์ฃผ๋ฉด, Modal์ app๊ณผ ๊ฐ์ stack context ์ ์๊ธฐ ๋๋ฌธ์, app์ zindex๋ณด๋ค ๋๊ธฐ๋ง ํ๋ฉด app ๋ด๋ถ์ ์ด๋ค component๋ณด๋ค๋ ์์ ์์นํ ์ ์๊ฒ ๋์ด์ ์ด๋ถ๋ถ์ด ์ข์๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | ์ด๋ถ๋ถ์ ์ํด์ compound component๋ฅผ ์ ์ฉํ๋ ค๊ณ ํ๊ณ , ์ฅ์ ์ ์ ๋ชป์ด๋ ธ๋ค๊ณ ์๊ฐํ๋๋ฐ
์์ผ๊ฐ ์ ์๋๋ฅผ ์๋ฒฝํ ํ์
ํ์ ๊ฑธ ๋ณด๋, ๊ทธ๋ ์ง๋ง์ ์์๋ ๊ฒ ๊ฐ๋ค์! ๐ |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | ์์ธํ ๊ณต์ ๊ฐ์ฌํฉ๋๋ค!! ์ฌ์ฉํด๋ณด์ง ์์์ง๋ง, ๋๋ถ์ ์ด๋ค ์ ์ฉํจ์ด ์๋ ์ง๋ ํ์คํ ์๊ฒ ๋ค์!! |
@@ -0,0 +1,31 @@
+import {
+ ModalBody,
+ ModalButtonContainer,
+ ModalCloseButton,
+ ModalContainer,
+ ModalDescription,
+ ModalDimmedLayer,
+ ModalHeader,
+ ModalInputField,
+ ModalTitle,
+} from './index';
+
+interface ModalProp {
+ children: JSX.Element;
+}
+
+const Modal = ({ children }: ModalProp) => {
+ return <>{children}</>;
+};
+
+Modal.Body = ModalBody;
+Modal.ButtonContainer = ModalButtonContainer;
+Modal.CloseButton = ModalCloseButton;
+Modal.Container = ModalContainer;
+Modal.Description = ModalDescription;
+Modal.DimmedLayer = ModalDimmedLayer;
+Modal.Header = ModalHeader;
+Modal.InputField = ModalInputField;
+Modal.Title = ModalTitle;
+
+export default Modal; | Unknown | compound component ์ ์ฉ๋ง ์ํ์
จ์ง, ๊ฑฐ์ง ์ ์ฉ๋ ๊ฑฐ๋ ๋ค๋ฆ ์์ ์ ๋๋ก ์๋ฒฝํ ๋ถ๋ฆฌ์ธ ๊ฒ ๊ฐ์ต๋๋ค ใ
ใ
ใ
์ ์ฉํ๋ ค๊ณ ํ๋ฉด ์์ ๋ณ๋ก ์์ด ๊ธ๋ฐฉ ์ ์ฉ๋ ๊ฒ ๊ฐ๋ค์. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.