code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,55 @@
+package christmas.domain.event;
+
+import christmas.domain.calendar.Date;
+import christmas.domain.calendar.Order;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.MenuType;
+
+public final class FreeGiftEvent implements Event {
+
+ private static final int CHRISTMAS_EVENT_MONTH = 12;
+ private static final int CHRISTMAS_EVENT_MIN_DAY = 1;
+ private static final int CHRISTMAS_EVENT_MAX_DAY = 31;
+ private static final int CHRISTMAS_EVENT_FREE_STANDARD = 120_000;
+ private static final String CHRISTMAS_EVENT_FREE_QUANTITY = "1";
+ private static final String FREE_GIFT_EVENT_TITLE = "์ฆ์ ์ด๋ฒคํธ";
+ private Menu benefitGift = new Menu(MenuType.EMPTY.getTitle(), CHRISTMAS_EVENT_FREE_QUANTITY);
+ private int benefit;
+
+ @Override
+ public boolean isApplicable(Date date) {
+ return isEventPeriod(date);
+ }
+
+ private static boolean isEventPeriod(Date date) {
+ return date.getMonth() == CHRISTMAS_EVENT_MONTH &&
+ date.getDay() >= CHRISTMAS_EVENT_MIN_DAY
+ && date.getDay() <= CHRISTMAS_EVENT_MAX_DAY;
+ }
+
+ @Override
+ public int calculateDiscount(Date date, Order order) {
+ int beforeMoney = order.getBeforeMoney();
+ if (beforeMoney >= CHRISTMAS_EVENT_FREE_STANDARD) {
+ MenuType champagne = MenuType.CHAMPAGNE;
+ benefitGift = new Menu(champagne.getTitle(), CHRISTMAS_EVENT_FREE_QUANTITY);
+ benefit = champagne.getPrice();
+ }
+ return benefit;
+ }
+
+ public Menu getBenefitGift() {
+ return benefitGift;
+ }
+
+ @Override
+ public int getBenefit() {
+ return benefit;
+ }
+
+ @Override
+ public String getEventName() {
+ return FREE_GIFT_EVENT_TITLE;
+ }
+
+} | Java | ๋ฆฌ๋ทฐ ๊ฐ์ฌ๋๋ฆฝ๋๋ค :) |
@@ -0,0 +1,55 @@
+package christmas.domain.event;
+
+import christmas.domain.calendar.Date;
+import christmas.domain.calendar.Order;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.MenuType;
+
+public final class FreeGiftEvent implements Event {
+
+ private static final int CHRISTMAS_EVENT_MONTH = 12;
+ private static final int CHRISTMAS_EVENT_MIN_DAY = 1;
+ private static final int CHRISTMAS_EVENT_MAX_DAY = 31;
+ private static final int CHRISTMAS_EVENT_FREE_STANDARD = 120_000;
+ private static final String CHRISTMAS_EVENT_FREE_QUANTITY = "1";
+ private static final String FREE_GIFT_EVENT_TITLE = "์ฆ์ ์ด๋ฒคํธ";
+ private Menu benefitGift = new Menu(MenuType.EMPTY.getTitle(), CHRISTMAS_EVENT_FREE_QUANTITY);
+ private int benefit;
+
+ @Override
+ public boolean isApplicable(Date date) {
+ return isEventPeriod(date);
+ }
+
+ private static boolean isEventPeriod(Date date) {
+ return date.getMonth() == CHRISTMAS_EVENT_MONTH &&
+ date.getDay() >= CHRISTMAS_EVENT_MIN_DAY
+ && date.getDay() <= CHRISTMAS_EVENT_MAX_DAY;
+ }
+
+ @Override
+ public int calculateDiscount(Date date, Order order) {
+ int beforeMoney = order.getBeforeMoney();
+ if (beforeMoney >= CHRISTMAS_EVENT_FREE_STANDARD) {
+ MenuType champagne = MenuType.CHAMPAGNE;
+ benefitGift = new Menu(champagne.getTitle(), CHRISTMAS_EVENT_FREE_QUANTITY);
+ benefit = champagne.getPrice();
+ }
+ return benefit;
+ }
+
+ public Menu getBenefitGift() {
+ return benefitGift;
+ }
+
+ @Override
+ public int getBenefit() {
+ return benefit;
+ }
+
+ @Override
+ public String getEventName() {
+ return FREE_GIFT_EVENT_TITLE;
+ }
+
+} | Java | ๋์ํฉ๋๋ค..
์ฆ์ ์ด๋ฒคํธ๋ก ์ํ์ ์ค์, ์ด ํํ ๊ธ์ก์๋ ์ํฅ์ ๋ฏธ์น์ง ์๋๋ผ๊ตฌ์..
ํ์ฌ Event์์ 5๊ฐ์ง ์ด๋ฒคํธ๋ฅผ ์ ํํ์ฌ ์์ ๋ฐ์,
๊ฒ์ฆ, ํ ์ธ๊ณ์ฐ ์ด๋ผ๋ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
์ฌ๊ธฐ์ ์ดํ์ธ์ ์ฃผ๋ฌธํ ํ์์ด๋ผ๋ฉด
์ฆ์ ์ํ์ ๋ฐ์ง์๊ณ ๊ฐ๊ฒฉํ ์ธ์ ์ ์ฉ์ํฌ ์ ์์ํ
๋ฐ ๋ฐ๋ก ๋ฉ์๋๋ฅผ ๋ถ๋ฆฌํ์ฌ ๊ตฌํํด์ผํ ๊น?
๋ผ๋ ์๊ฐ์ ํ ์ธ๊ณ์ฐ ๋ฉ์๋๋ฅผ
๊ทธ๋๋ก ๊ฐ์ ธ์์ ๊ฐ์ด ์ฌ์ฉํด๋ ๋๋ค๊ณ ํ๋จํ์ต๋๋ค :) |
@@ -0,0 +1,65 @@
+package christmas.domain.calendar;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.format.TextStyle;
+import java.util.Locale;
+
+public class Date {
+ private static final int VISIT_YEAR = 2023;
+ private static final int VISIT_MONTH = 12;
+ private Year year;
+ private Month month;
+ private Day day;
+ private String dayFormat;
+
+ public Date(int day) {
+ this.year = new Year(VISIT_YEAR);
+ this.month = new Month(VISIT_MONTH);
+ this.day = new Day(day);
+ this.dayFormat = createVisitingDayFormat();
+ }
+
+ public String createVisitingDayFormat() {
+ LocalDate visitDay = createDateTimeFormat();
+ DayOfWeek dayOfWeek = visitDay.getDayOfWeek();
+ return dayOfWeek.getDisplayName(TextStyle.FULL, Locale.KOREA);
+ }
+
+ public boolean isWeekend() {
+ LocalDate visitDay = createDateTimeFormat();
+ DayOfWeek dayOfWeek = visitDay.getDayOfWeek();
+ return dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY;
+ }
+
+ public boolean isSunday() {
+ LocalDate visitDay = createDateTimeFormat();
+ DayOfWeek dayOfWeek = visitDay.getDayOfWeek();
+ return dayOfWeek == DayOfWeek.SUNDAY;
+ }
+
+ public LocalDate createDateTimeFormat() {
+ return LocalDate.of(getYear(), getMonth(), getDay());
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s์ %s์ผ", month.month(), day.day());
+ }
+
+ public int getYear() {
+ return year.year();
+ }
+
+ public int getMonth() {
+ return month.month();
+ }
+
+ public int getDay() {
+ return day.day();
+ }
+
+ public String getDayFormat() {
+ return dayFormat;
+ }
+} | Java | ํฌ์ผ DayOfWeek ๋ฐฐ์๊ฐ๋๋ค! |
@@ -0,0 +1,20 @@
+package christmas.domain.calendar;
+
+import static christmas.message.ErrorMessages.INVALID_DATE_RANGE;
+
+public record Day(int day) {
+
+ private static int MIN_DAY = 1;
+ private static int EVEN_MONTHS_MAX_DAY = 31;
+
+ public Day {
+ validateRangeFromDay(day);
+ }
+
+ private void validateRangeFromDay(int day) {
+ if (day < MIN_DAY || day > EVEN_MONTHS_MAX_DAY) {
+ throw new IllegalArgumentException(INVALID_DATE_RANGE.getMessage());
+ }
+ }
+
+} | Java | Exception์ enum์ผ๋ก ๊ด๋ฆฌํด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,57 @@
+package christmas.domain.calendar;
+
+import christmas.domain.event.ChristmasDailyDiscountEvent;
+import christmas.domain.event.Event;
+import christmas.domain.event.EventBadge;
+import christmas.domain.event.FreeGiftEvent;
+import christmas.domain.event.SpecialDiscountEvent;
+import christmas.domain.event.WeekdayDiscountEvent;
+import christmas.domain.event.WeekendDiscountEvent;
+import java.util.Collections;
+import java.util.List;
+
+public class Planner {
+
+ private static final int CHRISTMAS_EVENT_MIN_ORDER_AMOUNT = 10_000;
+ private static final int START_BENEFIT_AMOUNT = 0;
+ private final List<Event> events;
+ private int afterAmount;
+ private EventBadge eventBadge;
+
+ public Planner(Date date, Order order) {
+ if (order.getBeforeMoney() < CHRISTMAS_EVENT_MIN_ORDER_AMOUNT) {
+ this.events = Collections.EMPTY_LIST;
+ this.afterAmount = START_BENEFIT_AMOUNT;
+ return;
+ }
+
+ this.events = List.of(
+ new ChristmasDailyDiscountEvent(),
+ new WeekdayDiscountEvent(),
+ new WeekendDiscountEvent(),
+ new FreeGiftEvent(),
+ new SpecialDiscountEvent()
+ );
+ this.afterAmount = calculateBenefits(date, order);
+ }
+
+ public int calculateBenefits(Date date, Order order) {
+
+ return events.stream()
+ .filter(event -> event.isApplicable(date))
+ .mapToInt(event -> event.calculateDiscount(date, order))
+ .sum();
+ }
+
+ public List<Event> getEvents() {
+ return events;
+ }
+
+ public int getAfterAmount() {
+ return afterAmount;
+ }
+
+ public EventBadge getEventBadge() {
+ return EventBadge.findByBadgeType(afterAmount);
+ }
+} | Java | ์คํธ ์ฌ๊ธฐ์ ์ด๋ฒคํธ ๊ฐ์ฒด๋ฅผ ๋ฃ์ด์ ๊ด๋ฆฌํ ์ ์๋ค์! ์ ์ง๋ณด์ํ๊ธฐ ์ข์ ๋ณด์
๋๋ค. |
@@ -0,0 +1,57 @@
+package christmas.domain.calendar;
+
+import christmas.domain.event.ChristmasDailyDiscountEvent;
+import christmas.domain.event.Event;
+import christmas.domain.event.EventBadge;
+import christmas.domain.event.FreeGiftEvent;
+import christmas.domain.event.SpecialDiscountEvent;
+import christmas.domain.event.WeekdayDiscountEvent;
+import christmas.domain.event.WeekendDiscountEvent;
+import java.util.Collections;
+import java.util.List;
+
+public class Planner {
+
+ private static final int CHRISTMAS_EVENT_MIN_ORDER_AMOUNT = 10_000;
+ private static final int START_BENEFIT_AMOUNT = 0;
+ private final List<Event> events;
+ private int afterAmount;
+ private EventBadge eventBadge;
+
+ public Planner(Date date, Order order) {
+ if (order.getBeforeMoney() < CHRISTMAS_EVENT_MIN_ORDER_AMOUNT) {
+ this.events = Collections.EMPTY_LIST;
+ this.afterAmount = START_BENEFIT_AMOUNT;
+ return;
+ }
+
+ this.events = List.of(
+ new ChristmasDailyDiscountEvent(),
+ new WeekdayDiscountEvent(),
+ new WeekendDiscountEvent(),
+ new FreeGiftEvent(),
+ new SpecialDiscountEvent()
+ );
+ this.afterAmount = calculateBenefits(date, order);
+ }
+
+ public int calculateBenefits(Date date, Order order) {
+
+ return events.stream()
+ .filter(event -> event.isApplicable(date))
+ .mapToInt(event -> event.calculateDiscount(date, order))
+ .sum();
+ }
+
+ public List<Event> getEvents() {
+ return events;
+ }
+
+ public int getAfterAmount() {
+ return afterAmount;
+ }
+
+ public EventBadge getEventBadge() {
+ return EventBadge.findByBadgeType(afterAmount);
+ }
+} | Java | ์ฌ๊ธฐ์ ๊ถ๊ธํ๊ฒ
```java
public sealed interface Event permits ChristmasDailyDiscountEvent, WeekdayDiscountEvent, WeekendDiscountEvent,
SpecialDiscountEvent,
FreeGiftEvent { ... }
```
์ด๋ ๊ฒ ๋ช
์ํด๋์๋๋ฐ, List.of ๋ถ๋ถ์ ๋ณ๊ฒฝํ๋ฉด Event ์ธํฐํ์ด์ค๋ ์์ ํด์ผ ํ๋์? |
@@ -0,0 +1,55 @@
+package christmas.domain.event;
+
+import christmas.domain.calendar.Date;
+import christmas.domain.calendar.Order;
+import christmas.domain.menu.Menu;
+import christmas.domain.menu.MenuType;
+
+public final class FreeGiftEvent implements Event {
+
+ private static final int CHRISTMAS_EVENT_MONTH = 12;
+ private static final int CHRISTMAS_EVENT_MIN_DAY = 1;
+ private static final int CHRISTMAS_EVENT_MAX_DAY = 31;
+ private static final int CHRISTMAS_EVENT_FREE_STANDARD = 120_000;
+ private static final String CHRISTMAS_EVENT_FREE_QUANTITY = "1";
+ private static final String FREE_GIFT_EVENT_TITLE = "์ฆ์ ์ด๋ฒคํธ";
+ private Menu benefitGift = new Menu(MenuType.EMPTY.getTitle(), CHRISTMAS_EVENT_FREE_QUANTITY);
+ private int benefit;
+
+ @Override
+ public boolean isApplicable(Date date) {
+ return isEventPeriod(date);
+ }
+
+ private static boolean isEventPeriod(Date date) {
+ return date.getMonth() == CHRISTMAS_EVENT_MONTH &&
+ date.getDay() >= CHRISTMAS_EVENT_MIN_DAY
+ && date.getDay() <= CHRISTMAS_EVENT_MAX_DAY;
+ }
+
+ @Override
+ public int calculateDiscount(Date date, Order order) {
+ int beforeMoney = order.getBeforeMoney();
+ if (beforeMoney >= CHRISTMAS_EVENT_FREE_STANDARD) {
+ MenuType champagne = MenuType.CHAMPAGNE;
+ benefitGift = new Menu(champagne.getTitle(), CHRISTMAS_EVENT_FREE_QUANTITY);
+ benefit = champagne.getPrice();
+ }
+ return benefit;
+ }
+
+ public Menu getBenefitGift() {
+ return benefitGift;
+ }
+
+ @Override
+ public int getBenefit() {
+ return benefit;
+ }
+
+ @Override
+ public String getEventName() {
+ return FREE_GIFT_EVENT_TITLE;
+ }
+
+} | Java | ์ ๋ ์ฆ์ ์ด๋ฒคํธ์ ํ ์ธ ์ด๋ฒคํธ๊ฐ ๊ฐ๋ ๊ฐ์ ์ ๋ณด๋ ๋ฌ๋ผ์ ๋ฐ๋ก ๋ถ๋ฆฌํ์ต๋๋ค.
๋ ๊ฐ์ฒด๋ฅผ ๊ด๋ฆฌํ๋ ๊ฐ์ฒด๋ฅผ ๋ง๋ค์ด ๊ด๋ฆฌํ์ต๋๋ค. |
@@ -0,0 +1,16 @@
+package christmas.message;
+
+public enum ErrorMessages {
+ INVALID_DATE_RANGE("[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."),
+ INVALID_ORDER_FORMAT("[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.");
+
+ private String message;
+
+ ErrorMessages(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ์ฌ๊ธฐ์ ๊ทธ๋ฅ Exception์ throw ํ๋ ๊ฒ๋ ์ข์ ๋ณด์
๋๋ค. |
@@ -0,0 +1,106 @@
+package christmas;
+
+import christmas.domain.badge.BadgeService;
+import christmas.domain.badge.model.Badge;
+import christmas.domain.benefit.BenefitService;
+import christmas.domain.benefit.model.Benefits;
+import christmas.domain.bills.Bills;
+import christmas.domain.date.DateService;
+import christmas.domain.date.model.PromotionDay;
+import christmas.domain.menu.MenuService;
+import christmas.domain.menu.model.collection.OrderSheet;
+import christmas.exception.handler.ExceptionHandler;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.List;
+import java.util.function.Supplier;
+
+public class Controller {
+ private final DateService dateService = new DateService();
+ private final MenuService menuService = new MenuService();
+ private final BenefitService benefitService = new BenefitService();
+ private final BadgeService badgeService = new BadgeService();
+
+ private final InputView inputView = new InputView();
+
+ private final OutputView outputView = new OutputView();
+ private final ExceptionHandler handler;
+
+ public Controller(ExceptionHandler handler) {
+ this.handler = handler;
+ }
+
+ public void run() {
+ printHello();
+
+ PromotionDay promotionDay = getPromotionDay();
+ OrderSheet orderSheet = getOrderSheet();
+ Benefits benefits = getBenefits(promotionDay, orderSheet);
+ Badge badge = getBadge(benefits);
+
+ printResult(Bills.builder()
+ .date(promotionDay.getDate())
+ .orderSheet(orderSheet)
+ .benefits(benefits)
+ .Badge(badge)
+ .build());
+ }
+
+ private void printHello() {
+ outputView.sayHello();
+ }
+
+ private PromotionDay getPromotionDay() {
+ return getResultUsingExceptionHandler(() -> {
+ int visitDate = inputView.getVisitDate();
+ return dateService.getPromotionDay(visitDate);
+ });
+ }
+
+ private OrderSheet getOrderSheet() {
+ return getResultUsingExceptionHandler(() -> {
+ List<String> orders = inputView.getOrders();
+ inputView.closeConsole();
+ return menuService.getOrderSheet(orders.toArray(String[]::new));
+ });
+ }
+
+ private <T> T getResultUsingExceptionHandler(Supplier<T> logic) {
+ return handler.get(logic, outputView::printException);
+ }
+
+ private Benefits getBenefits(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return benefitService.getBenefits(promotionDay, orderSheet);
+ }
+
+ private Badge getBadge(Benefits benefits) {
+ return badgeService.getBadge(benefits);
+ }
+
+ private void printResult(Bills bills) {
+ outputView.printBenefitTitle(bills.getDate());
+ printOrderSheeet(bills.getOrderSheet());
+ printBenefits(bills.getBenefits());
+ printDiscountedPrice(bills);
+ printBadge(bills.getBadge());
+ }
+
+ private void printOrderSheeet(OrderSheet orderSheet) {
+ outputView.printOrderMenu(orderSheet);
+ outputView.printTotalPriceNoDiscount(orderSheet);
+ }
+
+ private void printBenefits(Benefits benefits) {
+ outputView.printGifts(benefits);
+ outputView.printBenefits(benefits);
+ outputView.printTotalBenefitPrice(benefits);
+ }
+
+ private void printDiscountedPrice(Bills bills) {
+ outputView.printDiscountedPrice(bills.getDiscountedPrice());
+ }
+
+ private void printBadge(Badge badge) {
+ outputView.printBadge(badge);
+ }
+} | Java | ์ ๋ ํญ์ print๋ถ๋ถ์ด ์ง์ ๋ถํด์ ธ์ ์ด๋ป๊ฒ ์ฒ๋ฆฌํ ์ง ๊ณ ๋ฏผ์ ๋ง์ดํ๋๋ฐ, ์ค๋ ๋ณด๊ณ ๊ณต๋ถํด์ผ๊ฒ ์ต๋๋ค ใ
ใ
๐ |
@@ -0,0 +1,41 @@
+package christmas.domain.badge.model;
+
+import java.util.Arrays;
+
+public enum Badge {
+ NONE("์์", 0, 5_000),
+ STAR("๋ณ", 5_000, 10_000),
+ TREE("ํธ๋ฆฌ", 10_000, 20_000),
+ SANTA("์ฐํ", 20_000, Integer.MAX_VALUE);
+
+ private static final Badge[] badges = Badge.values();
+ private final String name;
+ private final int minPrice;
+ private final int maxPrice;
+
+ Badge(String name, int minPrice, int maxPrice) {
+ this.name = name;
+ this.minPrice = minPrice;
+ this.maxPrice = maxPrice;
+ }
+
+ public static Badge from(int price) {
+ return Arrays.stream(badges)
+ .filter(badge -> badge.match(price))
+ .findFirst()
+ .orElse(NONE);
+ }
+
+ private boolean match(int price) {
+ return betweenBadgePrice(price);
+ }
+
+ private boolean betweenBadgePrice(int price) {
+ int absPrice = Math.abs(price);
+ return absPrice >= minPrice && absPrice < maxPrice;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ์ ์ ์ ์ฌํ์ง๋ง ๊ฐ์ ๋ฒ์๋ฅผ ์ ํด์ฃผ์๊ณ ํ์ํ์
จ๊ตฐ์ ! |
@@ -0,0 +1,15 @@
+package christmas.domain.benefit.constance;
+
+public interface BenefitConst {
+ String GIFT_DESCRIPTION = "์ฆ์ ์ด๋ฒคํธ";
+
+ int D_DAY_INITIAL_PRICE = 1_000;
+ int D_DAY_INCREASE_PRICE = 100;
+ int WEEKDAY_DISCOUNT_PRICE = 2_023;
+ int WEEKEND_DISCOUNT_PRICE = 2_023;
+ int SPECIAL_DISCOUNT_PRICE = 1_000;
+
+ int MIN_PRICE_FOR_BENEFIT = 10_000;
+
+ int MIN_PRICE_FOR_CHAMPAGNE = 120_000;
+} | Java | ์ ๋ ๋ง์ ๊ณ ๋ฏผ์ ํ์๋ ๋ถ๋ถ์ธ๋ฐ, enum์ผ๋ก ๊ด๋ฆฌํ์ง ์๊ณ ์ธํฐํ์ด์ค ์์์ ์์๋ก ๊ด๋ฆฌํ์๋ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,32 @@
+package christmas.domain.benefit;
+
+import christmas.domain.benefit.constance.BenefitConst;
+import christmas.domain.benefit.model.Benefit;
+import christmas.domain.benefit.model.Benefits;
+import christmas.domain.benefit.model.discount.DiscountFactories;
+import christmas.domain.benefit.model.gift.GiftFactories;
+import christmas.domain.date.model.PromotionDay;
+import christmas.domain.menu.model.collection.OrderSheet;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitService {
+
+ public Benefits getBenefits(PromotionDay promotionDay, OrderSheet orderSheet) {
+ if (orderSheet.getTotalPrice() < BenefitConst.MIN_PRICE_FOR_BENEFIT) {
+ return new Benefits(List.of());
+ }
+ List<Benefit> benefits = new ArrayList<>();
+ benefits.addAll(getGifts(promotionDay, orderSheet));
+ benefits.addAll(getDiscounts(promotionDay, orderSheet));
+ return new Benefits(benefits);
+ }
+
+ private List<Benefit> getGifts(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return GiftFactories.of(promotionDay, orderSheet);
+ }
+
+ private List<Benefit> getDiscounts(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return DiscountFactories.of(promotionDay, orderSheet);
+ }
+} | Java | ์ฝ๋๊ฐ ์ธ์์ ์ด๋ค์ :) |
@@ -0,0 +1,11 @@
+package christmas.domain.benefit.model;
+
+import christmas.domain.date.model.PromotionDay;
+import christmas.domain.menu.model.collection.OrderSheet;
+
+public interface BenefitFactory {
+
+ boolean canApply(PromotionDay promotionDay, OrderSheet orderSheet);
+
+ Benefit generate(PromotionDay promotionDay, OrderSheet orderSheet);
+} | Java | generate๋ผ๋ ๋ค์ด๋ฐ์ ์ฃผ๋ก ์ด๋ค ์๋ฏธ๋ฅผ ์ ๋ฌํ๋ ค๊ณ ํ์ค ๋ ์ฌ์ฉํ์๋์? |
@@ -0,0 +1,44 @@
+package christmas.domain.benefit.model.discount;
+
+import christmas.domain.benefit.model.Benefit;
+import java.util.Objects;
+
+public class Discount implements Benefit {
+ private final DiscountType type;
+ private final int price;
+
+ Discount(DiscountType type, int price) {
+ this.type = type;
+ this.price = price;
+ }
+ @Override
+ public String getDescription() {
+ return type.getName();
+ }
+
+ @Override
+ public int getBenefitPrice() {
+ return -price;
+ }
+
+ DiscountType getType() {
+ return type;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ Discount discount = (Discount) o;
+ return price == discount.price && type == discount.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(type, price);
+ }
+} | Java | price๋ ๊ฐ์์ผ ํ ๊น์? |
@@ -0,0 +1,59 @@
+package christmas.domain.date.model;
+
+import christmas.domain.date.constance.DateConst;
+import christmas.exception.PromotionException;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.Set;
+
+public class PromotionDay {
+
+ private static final Set<DayOfWeek> weekend = Set.of(DayOfWeek.FRIDAY, DayOfWeek.SATURDAY);
+
+ private static final Set<Integer> specialDay = Set.of(3, 10, 17, 24, 25, 31);
+
+ private static final LocalDate christmas = LocalDate.of(DateConst.YEAR, DateConst.MONTH, 25);
+
+ private final LocalDate localDate;
+
+ private PromotionDay(LocalDate localDate) {
+ this.localDate = localDate;
+ }
+
+ public static PromotionDay from(int date) {
+ validateDate(date);
+ LocalDate localDate = LocalDate.of(DateConst.YEAR, DateConst.MONTH, date);
+ return new PromotionDay(localDate);
+ }
+
+ private static void validateDate(int date) {
+ if (date < DateConst.DECEMBER_DATE_START || date > DateConst.DECEMBER_DATE_END) {
+ throw PromotionException.INVALID_DATE.makeException();
+ }
+ }
+
+ public boolean isWeekend() {
+ return weekend.contains(localDate.getDayOfWeek());
+ }
+
+ public boolean isWeekDay() {
+ return !isWeekend();
+ }
+
+ public boolean isSpecialDay() {
+ int day = this.localDate.getDayOfMonth();
+ return specialDay.contains(day);
+ }
+
+ public int getDDayFromXMax() {
+ return christmas.compareTo(this.localDate);
+ }
+
+ public int getDayFromStart() {
+ return getDate() - 1;
+ }
+
+ public int getDate() {
+ return this.localDate.getDayOfMonth();
+ }
+} | Java | Start day๊ฐ ์๊ตฌ์ฌํญ์ ๋ฐ๋ผ ๋ณ๊ฒฝ๋ ์ ์๋ค๊ณ ์๊ฐํด์ 1์ ์์๋ก ๊ด๋ฆฌ ํด์คฌ์๋๋ฐ, ๋งค์ง ๋๋ฒ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ์์๋ก ๊ด๋ฆฌํ๋ ๊ฒ์ค ์ด๋๊ฒ์ด ๋ ๊ด์ฐฎ์๊น์?? |
@@ -0,0 +1,41 @@
+package christmas.domain.badge.model;
+
+import java.util.Arrays;
+
+public enum Badge {
+ NONE("์์", 0, 5_000),
+ STAR("๋ณ", 5_000, 10_000),
+ TREE("ํธ๋ฆฌ", 10_000, 20_000),
+ SANTA("์ฐํ", 20_000, Integer.MAX_VALUE);
+
+ private static final Badge[] badges = Badge.values();
+ private final String name;
+ private final int minPrice;
+ private final int maxPrice;
+
+ Badge(String name, int minPrice, int maxPrice) {
+ this.name = name;
+ this.minPrice = minPrice;
+ this.maxPrice = maxPrice;
+ }
+
+ public static Badge from(int price) {
+ return Arrays.stream(badges)
+ .filter(badge -> badge.match(price))
+ .findFirst()
+ .orElse(NONE);
+ }
+
+ private boolean match(int price) {
+ return betweenBadgePrice(price);
+ }
+
+ private boolean betweenBadgePrice(int price) {
+ int absPrice = Math.abs(price);
+ return absPrice >= minPrice && absPrice < maxPrice;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ์ด๊ฑฐํ ๊ฐ๋ค์ ์บ์ฑํด๋๋ ์ ๋ต์ด ์ ๋ง ์ข์ ๊ฒ ๊ฐ์ต๋๋ค :)
์ถ๊ฐ์ ์ผ๋ก `Badge[]`๋ก ๋ฐฐ์ง๋ค์ ์บ์ฑํด๋ ์ด์ ๋ ๊ถ๊ธํฉ๋๋ค!
์บ์ฑ์ ํ์ง๋ง ๋ฐฐ์ด์ด๊ธฐ ๋๋ฌธ์ ์ด์ฉ ์ ์์ด ์ํํ๋ ์์
์ด ํ์ํ๋ฐ, ์ด๋ค ์ ์ ์ผ๋ํด์ ์บ์ฑํ์ ๊ฑด์ง ๊ถ๊ธํด์!!
๋งค ๋ฒ `.values()`๋ฅผ ํธ์ถํ๋ ๊ฒ์ ๋นํจ์จ์ ์ด๋ผ ํ๋จํ์ ๊ฑธ๊น์?! |
@@ -0,0 +1,41 @@
+package christmas.domain.badge.model;
+
+import java.util.Arrays;
+
+public enum Badge {
+ NONE("์์", 0, 5_000),
+ STAR("๋ณ", 5_000, 10_000),
+ TREE("ํธ๋ฆฌ", 10_000, 20_000),
+ SANTA("์ฐํ", 20_000, Integer.MAX_VALUE);
+
+ private static final Badge[] badges = Badge.values();
+ private final String name;
+ private final int minPrice;
+ private final int maxPrice;
+
+ Badge(String name, int minPrice, int maxPrice) {
+ this.name = name;
+ this.minPrice = minPrice;
+ this.maxPrice = maxPrice;
+ }
+
+ public static Badge from(int price) {
+ return Arrays.stream(badges)
+ .filter(badge -> badge.match(price))
+ .findFirst()
+ .orElse(NONE);
+ }
+
+ private boolean match(int price) {
+ return betweenBadgePrice(price);
+ }
+
+ private boolean betweenBadgePrice(int price) {
+ int absPrice = Math.abs(price);
+ return absPrice >= minPrice && absPrice < maxPrice;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ๋ฐฐ์ง์ ์ต์๊ฐ๊ณผ ์ต๋๊ฐ์ ๋ฉค๋ฒ ๋ณ์๋ก ์ค์ ํด์ฃผ๊ณ , Predicate์ผ๋ก ์ฒ๋ฆฌํ๋ฉด ํ๋์ ๋ฉ์๋๋ก ์ฒ๋ฆฌํ ์ ์๋ค์..
์ ๋ง ์ข์ ์ฝ๋์ธ ๊ฒ ๊ฐ์์! ์ ๋ ์ต๋๊ฐ์ ์๊ฐ ๋ชปํด์ if ๋ถ๊ธฐ๋ฌธ์ด ์ฌ๋ฌ๊ฐ ๋ค์ด๊ฐ๋๋ฐ, ํ์๋ ์ฝ๋์ฒ๋ผ ๊ฐ์ ํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค ๐ |
@@ -0,0 +1,41 @@
+package christmas.domain.badge.model;
+
+import java.util.Arrays;
+
+public enum Badge {
+ NONE("์์", 0, 5_000),
+ STAR("๋ณ", 5_000, 10_000),
+ TREE("ํธ๋ฆฌ", 10_000, 20_000),
+ SANTA("์ฐํ", 20_000, Integer.MAX_VALUE);
+
+ private static final Badge[] badges = Badge.values();
+ private final String name;
+ private final int minPrice;
+ private final int maxPrice;
+
+ Badge(String name, int minPrice, int maxPrice) {
+ this.name = name;
+ this.minPrice = minPrice;
+ this.maxPrice = maxPrice;
+ }
+
+ public static Badge from(int price) {
+ return Arrays.stream(badges)
+ .filter(badge -> badge.match(price))
+ .findFirst()
+ .orElse(NONE);
+ }
+
+ private boolean match(int price) {
+ return betweenBadgePrice(price);
+ }
+
+ private boolean betweenBadgePrice(int price) {
+ int absPrice = Math.abs(price);
+ return absPrice >= minPrice && absPrice < maxPrice;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | NONE์ผ๋ก ์์ ์ฒ๋ฆฌํ์ ๊ฒ๋ ์ข์ ์ ๊ทผ ๋ฐฉ๋ฒ์ด๋ผ ์๊ฐํฉ๋๋ค :)
`Optional`๋ ๊ณ ๋ คํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์!
๊ทธ๋ ๊ฒ ๋๋ฉด from ๋ฉ์๋๊ฐ ์ด๋ฐ์์ผ๋ก ๋ฐ๋ ๊ฒ ๊ฐ์ต๋๋ค.
```java
public static Optional<Badge> from(int price) {
Optional<Badge> result = Arrays.stream(badges)
.filter(badge -> badge.match(price))
.findFirst();
if(result.isPresent()) {
return Optional.get();
}
return Optional.empty():
}
```
์ ํํ ์ด๋ ์ง์ ์์ Optional์ ์ฌ์ฉํด์ผ ํ๋์ง, Enum ๋ด๋ถ์์ Optional์ ์ฌ์ฉํด๋ ๊ด์ฐฎ์์ง ์ ๋ ์์ง ๋ช
ํํ ๊ธฐ์ค์ ์์ง๋ง **์์ ์๋ ์๋ค ๋ผ๋ ๋น์ฆ๋์ค ์๊ตฌ์ฌํญ์ ์ฝ๋๋ก ๋ช
์** ํ ์ ์๋ ์ธก๋ฉด์์ ์์ฃผ ๊ฐ๋ ฅํ ์ฅ์ ์ด ์๋ ๊ฒ ๊ฐ์์ :)
๊ทธ๋ฅ ์ฐธ๊ณ ์ ๋๋ง ํ์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ๐ |
@@ -0,0 +1,32 @@
+package christmas.domain.benefit;
+
+import christmas.domain.benefit.constance.BenefitConst;
+import christmas.domain.benefit.model.Benefit;
+import christmas.domain.benefit.model.Benefits;
+import christmas.domain.benefit.model.discount.DiscountFactories;
+import christmas.domain.benefit.model.gift.GiftFactories;
+import christmas.domain.date.model.PromotionDay;
+import christmas.domain.menu.model.collection.OrderSheet;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitService {
+
+ public Benefits getBenefits(PromotionDay promotionDay, OrderSheet orderSheet) {
+ if (orderSheet.getTotalPrice() < BenefitConst.MIN_PRICE_FOR_BENEFIT) {
+ return new Benefits(List.of());
+ }
+ List<Benefit> benefits = new ArrayList<>();
+ benefits.addAll(getGifts(promotionDay, orderSheet));
+ benefits.addAll(getDiscounts(promotionDay, orderSheet));
+ return new Benefits(benefits);
+ }
+
+ private List<Benefit> getGifts(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return GiftFactories.of(promotionDay, orderSheet);
+ }
+
+ private List<Benefit> getDiscounts(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return DiscountFactories.of(promotionDay, orderSheet);
+ }
+} | Java | if ์กฐ๊ฑด๋ฌธ์ ๊ฐ์ธ์ ์ผ๋ก ๋ฉ์๋ ๋ถ๋ฆฌํ๋ ๊ฒ๋ ๊ด์ฐฎ์ ๊ฒ ๊ฐ์ต๋๋ค!
๊ทธ ์ด์ ๋ 20, 21 line์์ ๋ฉ์๋ ํธ์ถ์ ํตํด ๋ก์ง์ ์ฒ๋ฆฌํ๊ณ ์๊ธฐ ๋๋ฌธ์, ๋์ผํ depth๋ก ํต์ผ์์ผ ์ฃผ์ ๋ค๋ฉด ์กฐ๊ธ ๋ ์ฝ๊ธฐ ์ข์ ์ฝ๋๊ฐ ๋ ์ ์์ ๊ฒ ๊ฐ์์ :) |
@@ -0,0 +1,19 @@
+package christmas.domain.benefit.model.discount;
+
+public enum DiscountType {
+ D_DAY("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"), //12์ 25์ผ์ ์ง๋์ง ์์ ๊ฒฝ์ฐ //๋ ์ง์ ๋ฐ๋ผ 100์์ฉ ์ฆ๊ฐ
+ WEEKDAY("ํ์ผ ํ ์ธ"), //ํ์ผ์ธ ๊ฒฝ์ฐ // ๋์ ํธ ๋ฉ๋ด * ๊ธ์ก
+ WEEKEND("์ฃผ๋ง ํ ์ธ"), //์ฃผ๋ง์ธ ๊ฒฝ์ฐ // ๋ฉ์ธ ๋ฉ๋ด * ๊ธ์ก
+ SPECIAL("ํน๋ณ ํ ์ธ") //์คํ์
๋ฐ์ด์ธ ๊ฒฝ์ฐ // ๋ฌด์กฐ๊ฑด 1000์
+ ;
+
+ private final String name;
+
+ DiscountType(String name) {
+ this.name = name;
+ }
+
+ String getName() {
+ return name;
+ }
+} | Java | ์ ๋ `ํ ์ธ ์ ํ(DiscountType)`, `ํ ์ธ ์ ํ์ ๋ํ ๋ ์ง`, `ํ ์ธ ์ ํ์ ๋ํ ํ ์ธ ๊ณ์ฐ ๋ก์ง`
์์ 3๊ฐ์ง๋ DiscountType Enum๊ณผ **์์ฃผ ๊ธด๋ฐํ๊ฒ ์ฐ๊ด๋์ด ์๋ ์์**๋ผ ์๊ฐ์ด ๋ค์์ต๋๋ค!
๊ทธ๋์ ์ด๋ฐ์์ผ๋ก DiscountType์ ๊ตฌํํ์ต๋๋ค.
```java
public enum DiscountType {
CHRISTMAS("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ", EventDayCalculator.christmasDay(), orderDay -> {
final int basicDiscountAmount = 1000;
final int discountAmountUnit = 100;
return (basicDiscountAmount + discountAmountUnit * (orderDay - 1)) * -1;
}),
WEEKDAY("ํ์ผ ํ ์ธ", EventDayCalculator.weekDay(), dessertCount -> {
final int discountAmountUnit = 2023;
return (discountAmountUnit * dessertCount) * -1;
}),
WEEKEND("์ฃผ๋ง ํ ์ธ", EventDayCalculator.weekEnd(), mainCourseCount -> {
final int discountAmountUnit = 2023;
return (discountAmountUnit * mainCourseCount) * -1;
}),
SPECIAL("ํน๋ณ ํ ์ธ", EventDayCalculator.specialDay(), anything -> {
return -1000;
});
// something
```
์ด๋ ๊ฒ ์ฒ๋ฆฌ๋ฅผ ํ๋ **ํ ์ธ ์ ํ์ด๋ผ๋ ์ํ** ์ **๊ณ์ฐ ๋ก์ง์ด๋ผ๋ ํ์** ๋ฅผ ๋ฐ์ง์ํฌ ์ ์๋ ์ฅ์ ์ด ์์์ต๋๋ค.
ํ ์ธ ์ ํ์ด๋ผ๋ ์ํ์ ๊ณ์ฐ์ด๋ผ๋ ํ์๊ฐ ์ฐ๊ฐ๋์ด ์์๋๋ฐ, ๋ฐ์ง์ํค๋ ๊ต์ฅํ ๊ด๋ฆฌํ๊ธฐ ํธํ๋ค๋ ์๊ฐ์ด ๋ค๋๋ผ๊ตฌ์.
์ด๋ฐ ๋ฐฉ๋ฒ์ผ๋ก ์งฑ์๋ ์ฝ๋๋ฅผ ๋ฆฌํฉํฐ๋ง ํ๋ค๋ฉด, `BenefitFactory`์ `isApply()`๋ฅผ `DiscountType`์ด ๋ด๋ถ์ ์ผ๋ก ์ฒ๋ฆฌํ ์ ์์ ๊ฒ ๊ฐ๊ณ , ํ ์ธ ๊ณ์ฐ์ ์ํํ๋ผ๋ ๋ช
๋ น ์ฒ๋ฆฌ ์ญํ ์ ๋ด๋นํ๋ ํด๋์ค๋ง ๊ตฌํํด์ฃผ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋ผ ์ฝ๋ ๋ณต์ก๋๊ฐ ์กฐ๊ธ ์ค์ด๋ค์ง ์์๊น..? ๋ผ๋ ๊ฐ์ธ ์๊ฐ์
๋๋ค ใ
ใ
ใ
์ด๋ฐ ๋ฐฉ๋ฒ์ ์ด๋ ์ ์ง ์งฑ์๋์ ์๊ฐ์ ์ฌ์ญ๊ณ ์ถ์ด์ :) |
@@ -0,0 +1,52 @@
+package christmas.domain.menu.model;
+
+import christmas.exception.PromotionException;
+import java.util.Arrays;
+
+public enum Menu {
+
+ MUSHROOM_SOUP(MenuType.APPETIZER, "์์ก์ด์ํ", 6_000),
+ TAPAS(MenuType.APPETIZER, "ํํ์ค", 5_500),
+ CAESAR_SALAD(MenuType.APPETIZER, "์์ ์๋ฌ๋", 8_000),
+
+ T_BONE_STEAK(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
+ BARBCUE_RIBS(MenuType.MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000),
+ SEAFOOD_PASTA(MenuType.MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000),
+ CHRISTMAS_PASTA(MenuType.MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000),
+
+ CHOCOLATE_CAKE(MenuType.DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000),
+ ICE_CREAM(MenuType.DESSERT, "์์ด์คํฌ๋ฆผ", 5_000),
+
+ ZERO_COKE(MenuType.DRINK, "์ ๋ก์ฝ๋ผ", 3_000),
+ RED_WINE(MenuType.DRINK, "๋ ๋์์ธ", 60_000),
+ CHAMPAGNE(MenuType.DRINK, "์ดํ์ธ", 25_000);
+
+ private final MenuType type;
+ private final String name;
+ private final int price;
+
+ Menu(MenuType type, String name, int price) {
+ this.type = type;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu from(String menuName) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.name.equals(menuName))
+ .findFirst()
+ .orElseThrow(PromotionException.INVALID_ORDER::makeException);
+ }
+
+ public boolean isTypeOf(MenuType type){
+ return this.type.equals(type);
+ }
+
+ String getName() {
+ return name;
+ }
+
+ int getPrice() {
+ return price;
+ }
+} | Java | Badge Enum์์ `.values()`๋ฅผ `๋ฐฐ์ด๋ก ์บ์ฑ`ํ์ ๊ฒ๊ณผ ๊ฐ์ ๋งฅ๋ฝ์ผ๋ก `HashMap์ผ๋ก ์บ์ฑ` ํด๋๋ ๋ฐฉ๋ฒ๋ ์ถ์ฒ๋๋ฆฝ๋๋ค.
Enum์์ static ๋ธ๋ก์ ์ถ๊ฐํ ์ ์๋๋ฐ์, ์๋ฐ์์ผ๋ก ๊ตฌํํ ์ ์์ต๋๋ค!
```java
public enum Menu {
// ์ด๊ฑฐํ ์์๋ค ...
private static final Map<String, Menu> cachedMenu;
static {
for (Menu menu : values()) {
cachedMenu.put(menu.getName(), menu);
}
}
}
```
์ด๋ ๊ฒ Map์ผ๋ก ์บ์ฑํด๋๋ฉด, ๋งค ๋ฒ ์ด๊ฑฐํ ์์๋ค์ ์ํํ์ง ์์๋ ๋๋ ์ฅ์ ์ด ์์ต๋๋ค :)
ํ์ง๋ง NPE๊ฐ ๋ฐ์ํ ์ํ์ด ์๊ธฐ ๋๋ฌธ์, Optional์ ์ฌ์ฉํด๋ณด์๋ ๊ฒ๋ ๊ณ ๋ คํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
๊ทธ๋ ๊ฒ ํ๋ฉด
```java
public static Optional<Menu> from(String menuName) {
return Optional.ofNullalbe(cachedMenu.get(menuName);
}
```
์์ ๊ฐ์ด ๋ฆฌํฉํฐ๋ง ํด๋ณผ ์ ์์ ๊ฒ ๊ฐ์์ :) |
@@ -0,0 +1,37 @@
+package christmas.domain.menu.model.collection;
+
+import christmas.domain.menu.model.MenuAndCount;
+import christmas.domain.menu.model.MenuType;
+import java.util.Collections;
+import java.util.List;
+
+/** ์ฃผ๋ฌธ ํ์ธ์ ์ํ ๋ถ๋ณ ์ผ๊ธ ์ปฌ๋ ์
์
๋๋ค. */
+public class OrderSheet {
+ private final List<MenuAndCount> orderSheet;
+
+ public OrderSheet(List<MenuAndCount> orderSheet) {
+ this.orderSheet = orderSheet;
+ }
+
+ public List<MenuAndCount> getOrderSheet() {
+ return Collections.unmodifiableList(orderSheet);
+ }
+
+ public int getTotalPrice() {
+ return orderSheet.stream()
+ .mapToInt(MenuAndCount::getTotalPrice)
+ .sum();
+ }
+
+ public boolean hasMenuOfType(MenuType type) {
+ return orderSheet.stream()
+ .anyMatch(menuAndCount -> menuAndCount.isTypeOf(type));
+ }
+
+ public int getCountOfMenuType(MenuType type) {
+ return orderSheet.stream()
+ .filter(menuAndCount -> menuAndCount.isTypeOf(type))
+ .mapToInt(MenuAndCount::getCount)
+ .sum();
+ }
+} | Java | `OrderSheet`์ `Orders`๋ฅผ ๋ถ๋ฆฌํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค ! |
@@ -0,0 +1,10 @@
+package christmas.domain.badge;
+
+import christmas.domain.badge.model.Badge;
+import christmas.domain.benefit.model.Benefits;
+
+public class BadgeService {
+ public Badge getBadge(Benefits benefits) {
+ return Badge.from(benefits.getTotalPrice());
+ }
+} | Java | ํจํค์ง ๊ตฌ์กฐ ์ ๋ฐ์ ๋ํ ์งฑ์๋์ ์๊ฒฌ์ด ๊ถ๊ธํด์ ์ง๋ฌธ ๋๋ ค์!
์งฑ์๋์ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ ๊ตฌ์กฐ๋ก ์งํํ์
จ๋๋ผ๊ตฌ์!
```
domain
ใด badge
ใด ๊ด๋ จ domain ๊ฐ์ฒด
ใด badgeService
ใด benefit
ใด ๊ด๋ จ domain ๊ฐ์ฒด
ใด benefitService
```
์ ๋ ์ด๋ฐ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋๋ฐ์!
```
domain
ใด badge
ใด ๊ด๋ จ domain ๊ฐ์ฒด
ใด benefit
ใด ๊ด๋ จ domain ๊ฐ์ฒด
service
ใด badgeService
ใด benefitService
```
์ฒ์ ์ ์๊ฐ์ `domain layer`๋ domain ๊ด๋ จ ๊ฐ์ฒด๋ค๋ง ๋ชจ์ ๋๋ ๊ณณ์ด๋ผ๊ณ ์๊ฐํ์ฌ ์์ ๊ฐ์ด ๊ตฌํํ์ต๋๋ค. `Service layer`๋ ์ ์ ํ domain์๊ฒ ๋ช
๋ น์ ์์ฒญํ๊ณ ๋ฐํํ๋ ๊ตฌ์กฐ์
๋๋ค.
ํ์ง๋ง ์งฑ์๋์ ํจํค์ง ๊ตฌ์กฐ๋ฅผ ๋ณด๋ `์์ง๋๊ฐ ๋ ๋์์ง ์ ์๊ฒ ๊ตฌ๋` ๋ผ๋ ์ฅ์ ์ด ์๋ ๊ฒ ๊ฐ์์!
ํ๋ก๋ํธ ์งํํ๋ฉฐ ํจํค์ง ๊ตฌ์กฐ๋ฅผ ์ ๊ธฐ์ ์ผ๋ก ๋ฐ๊พธ์ด ๋๊ฐ๋๊ฒ ์ค์ํ๋ค๋ ์๊ฐ์ด ์๋๋ฐ, ์งฑ์๋์ ์ด๋ค ๊ธฐ์ค์ผ๋ก ํจํค์ง ๊ตฌ์กฐ๋ฅผ ์์ ๊ฐ์ด ๊ตฌ์กฐํํ์ ๊ฑธ๊น์?! |
@@ -0,0 +1,59 @@
+package christmas.domain.date.model;
+
+import christmas.domain.date.constance.DateConst;
+import christmas.exception.PromotionException;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.Set;
+
+public class PromotionDay {
+
+ private static final Set<DayOfWeek> weekend = Set.of(DayOfWeek.FRIDAY, DayOfWeek.SATURDAY);
+
+ private static final Set<Integer> specialDay = Set.of(3, 10, 17, 24, 25, 31);
+
+ private static final LocalDate christmas = LocalDate.of(DateConst.YEAR, DateConst.MONTH, 25);
+
+ private final LocalDate localDate;
+
+ private PromotionDay(LocalDate localDate) {
+ this.localDate = localDate;
+ }
+
+ public static PromotionDay from(int date) {
+ validateDate(date);
+ LocalDate localDate = LocalDate.of(DateConst.YEAR, DateConst.MONTH, date);
+ return new PromotionDay(localDate);
+ }
+
+ private static void validateDate(int date) {
+ if (date < DateConst.DECEMBER_DATE_START || date > DateConst.DECEMBER_DATE_END) {
+ throw PromotionException.INVALID_DATE.makeException();
+ }
+ }
+
+ public boolean isWeekend() {
+ return weekend.contains(localDate.getDayOfWeek());
+ }
+
+ public boolean isWeekDay() {
+ return !isWeekend();
+ }
+
+ public boolean isSpecialDay() {
+ int day = this.localDate.getDayOfMonth();
+ return specialDay.contains(day);
+ }
+
+ public int getDDayFromXMax() {
+ return christmas.compareTo(this.localDate);
+ }
+
+ public int getDayFromStart() {
+ return getDate() - 1;
+ }
+
+ public int getDate() {
+ return this.localDate.getDayOfMonth();
+ }
+} | Java | ํ๋์ฝ๋ฉํ์ง ์๊ณ ๋ LocalDate๋ฅผ ํ์ฉํ๋ฉด ๋๋๊ตฐ์.. ๋ฐฐ์๊ฐ๋๋ค ๐๐ |
@@ -0,0 +1,106 @@
+package christmas;
+
+import christmas.domain.badge.BadgeService;
+import christmas.domain.badge.model.Badge;
+import christmas.domain.benefit.BenefitService;
+import christmas.domain.benefit.model.Benefits;
+import christmas.domain.bills.Bills;
+import christmas.domain.date.DateService;
+import christmas.domain.date.model.PromotionDay;
+import christmas.domain.menu.MenuService;
+import christmas.domain.menu.model.collection.OrderSheet;
+import christmas.exception.handler.ExceptionHandler;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.List;
+import java.util.function.Supplier;
+
+public class Controller {
+ private final DateService dateService = new DateService();
+ private final MenuService menuService = new MenuService();
+ private final BenefitService benefitService = new BenefitService();
+ private final BadgeService badgeService = new BadgeService();
+
+ private final InputView inputView = new InputView();
+
+ private final OutputView outputView = new OutputView();
+ private final ExceptionHandler handler;
+
+ public Controller(ExceptionHandler handler) {
+ this.handler = handler;
+ }
+
+ public void run() {
+ printHello();
+
+ PromotionDay promotionDay = getPromotionDay();
+ OrderSheet orderSheet = getOrderSheet();
+ Benefits benefits = getBenefits(promotionDay, orderSheet);
+ Badge badge = getBadge(benefits);
+
+ printResult(Bills.builder()
+ .date(promotionDay.getDate())
+ .orderSheet(orderSheet)
+ .benefits(benefits)
+ .Badge(badge)
+ .build());
+ }
+
+ private void printHello() {
+ outputView.sayHello();
+ }
+
+ private PromotionDay getPromotionDay() {
+ return getResultUsingExceptionHandler(() -> {
+ int visitDate = inputView.getVisitDate();
+ return dateService.getPromotionDay(visitDate);
+ });
+ }
+
+ private OrderSheet getOrderSheet() {
+ return getResultUsingExceptionHandler(() -> {
+ List<String> orders = inputView.getOrders();
+ inputView.closeConsole();
+ return menuService.getOrderSheet(orders.toArray(String[]::new));
+ });
+ }
+
+ private <T> T getResultUsingExceptionHandler(Supplier<T> logic) {
+ return handler.get(logic, outputView::printException);
+ }
+
+ private Benefits getBenefits(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return benefitService.getBenefits(promotionDay, orderSheet);
+ }
+
+ private Badge getBadge(Benefits benefits) {
+ return badgeService.getBadge(benefits);
+ }
+
+ private void printResult(Bills bills) {
+ outputView.printBenefitTitle(bills.getDate());
+ printOrderSheeet(bills.getOrderSheet());
+ printBenefits(bills.getBenefits());
+ printDiscountedPrice(bills);
+ printBadge(bills.getBadge());
+ }
+
+ private void printOrderSheeet(OrderSheet orderSheet) {
+ outputView.printOrderMenu(orderSheet);
+ outputView.printTotalPriceNoDiscount(orderSheet);
+ }
+
+ private void printBenefits(Benefits benefits) {
+ outputView.printGifts(benefits);
+ outputView.printBenefits(benefits);
+ outputView.printTotalBenefitPrice(benefits);
+ }
+
+ private void printDiscountedPrice(Bills bills) {
+ outputView.printDiscountedPrice(bills.getDiscountedPrice());
+ }
+
+ private void printBadge(Badge badge) {
+ outputView.printBadge(badge);
+ }
+} | Java | BIlls๋ผ๋ ๋ณ๋์ ํด๋์ค๋ฅผ ๋ง๋ค๊ณ , ๋น๋๋ฅผ ์ด์ฉํ๋ ์ถ๋ ฅ์ด ์ ๋ง ๊น๋ํด์ง๋ค์! ์ ๋ง ์ข์ ์์ด๋์ด ๊ฐ์ต๋๋ค |
@@ -0,0 +1,10 @@
+package christmas.domain.badge;
+
+import christmas.domain.badge.model.Badge;
+import christmas.domain.benefit.model.Benefits;
+
+public class BadgeService {
+ public Badge getBadge(Benefits benefits) {
+ return Badge.from(benefits.getTotalPrice());
+ }
+} | Java | ์ ๋ ์ด ๋ถ๋ถ์ด ๊ถ๊ธํด์ ์ปค๋ฉํธ ๋จ๊ธฐ๊ณ ๊ฐ๋๋ค! ์ ๋ june๋๊ณผ ๊ฐ์ด ๊ตฌํํ๋๋ฐ, ์ฝ๋ ์
์ฅ์์ ๋ณด๋ ๋๋ฉ์ธ ์ฝ๋๋ฅผ ์ฝ๊ณ ์๋น์ค ์ฝ๋๋ฅผ ์ฝ์ผ๋ ์ดํด๊ฐ ํจ์ฌ ์์ํ๋๋ผ๊ตฌ์! |
@@ -0,0 +1,41 @@
+package christmas.domain.badge.model;
+
+import java.util.Arrays;
+
+public enum Badge {
+ NONE("์์", 0, 5_000),
+ STAR("๋ณ", 5_000, 10_000),
+ TREE("ํธ๋ฆฌ", 10_000, 20_000),
+ SANTA("์ฐํ", 20_000, Integer.MAX_VALUE);
+
+ private static final Badge[] badges = Badge.values();
+ private final String name;
+ private final int minPrice;
+ private final int maxPrice;
+
+ Badge(String name, int minPrice, int maxPrice) {
+ this.name = name;
+ this.minPrice = minPrice;
+ this.maxPrice = maxPrice;
+ }
+
+ public static Badge from(int price) {
+ return Arrays.stream(badges)
+ .filter(badge -> badge.match(price))
+ .findFirst()
+ .orElse(NONE);
+ }
+
+ private boolean match(int price) {
+ return betweenBadgePrice(price);
+ }
+
+ private boolean betweenBadgePrice(int price) {
+ int absPrice = Math.abs(price);
+ return absPrice >= minPrice && absPrice < maxPrice;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | orElse์ ์์์ ๊ด๋ จ์๋ ๊ฐ์ด ๋ค์ด๊ฐ๋ ๊ฒฝ์ฐ๋ ๋ง์ด ๋ดค๋๋ฐ, ์ด ์ฝ๋์์ orElse๋ง์ ์ญํ ์ด ๋ถ๋ช
ํด์ ๋๋ฌด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,41 @@
+package christmas.domain.badge.model;
+
+import java.util.Arrays;
+
+public enum Badge {
+ NONE("์์", 0, 5_000),
+ STAR("๋ณ", 5_000, 10_000),
+ TREE("ํธ๋ฆฌ", 10_000, 20_000),
+ SANTA("์ฐํ", 20_000, Integer.MAX_VALUE);
+
+ private static final Badge[] badges = Badge.values();
+ private final String name;
+ private final int minPrice;
+ private final int maxPrice;
+
+ Badge(String name, int minPrice, int maxPrice) {
+ this.name = name;
+ this.minPrice = minPrice;
+ this.maxPrice = maxPrice;
+ }
+
+ public static Badge from(int price) {
+ return Arrays.stream(badges)
+ .filter(badge -> badge.match(price))
+ .findFirst()
+ .orElse(NONE);
+ }
+
+ private boolean match(int price) {
+ return betweenBadgePrice(price);
+ }
+
+ private boolean betweenBadgePrice(int price) {
+ int absPrice = Math.abs(price);
+ return absPrice >= minPrice && absPrice < maxPrice;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ์ฌ๊ธฐ์ ์ ๋๊ฐ์ ์ด์ฉํ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค!! |
@@ -0,0 +1,32 @@
+package christmas.domain.benefit;
+
+import christmas.domain.benefit.constance.BenefitConst;
+import christmas.domain.benefit.model.Benefit;
+import christmas.domain.benefit.model.Benefits;
+import christmas.domain.benefit.model.discount.DiscountFactories;
+import christmas.domain.benefit.model.gift.GiftFactories;
+import christmas.domain.date.model.PromotionDay;
+import christmas.domain.menu.model.collection.OrderSheet;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitService {
+
+ public Benefits getBenefits(PromotionDay promotionDay, OrderSheet orderSheet) {
+ if (orderSheet.getTotalPrice() < BenefitConst.MIN_PRICE_FOR_BENEFIT) {
+ return new Benefits(List.of());
+ }
+ List<Benefit> benefits = new ArrayList<>();
+ benefits.addAll(getGifts(promotionDay, orderSheet));
+ benefits.addAll(getDiscounts(promotionDay, orderSheet));
+ return new Benefits(benefits);
+ }
+
+ private List<Benefit> getGifts(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return GiftFactories.of(promotionDay, orderSheet);
+ }
+
+ private List<Benefit> getDiscounts(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return DiscountFactories.of(promotionDay, orderSheet);
+ }
+} | Java | ์ฝ๋๊ฐ ๊น๋ํด์ ์ดํดํ๊ธฐ ์ ๋ง ์ฝ์ง๋ง, if๋ฌธ ์์ ์กฐ๊ฑด์์ "ํ ์ธ์ด ๋ถ๊ฐ๋ฅํ๊ฒฝ์ฐ"๋ฅผ ์์ํ๋ ๋ณ๋์ ๋ฉ์๋๋ก ๋ถ๋ฆฌํ๋ฉด ๋๋์ฑ ์ฝ๊ธฐ ์ข์์ง ๊ฒ ๊ฐ์ต๋๋ค!! |
@@ -0,0 +1,15 @@
+package christmas.domain.benefit.constance;
+
+public interface BenefitConst {
+ String GIFT_DESCRIPTION = "์ฆ์ ์ด๋ฒคํธ";
+
+ int D_DAY_INITIAL_PRICE = 1_000;
+ int D_DAY_INCREASE_PRICE = 100;
+ int WEEKDAY_DISCOUNT_PRICE = 2_023;
+ int WEEKEND_DISCOUNT_PRICE = 2_023;
+ int SPECIAL_DISCOUNT_PRICE = 1_000;
+
+ int MIN_PRICE_FOR_BENEFIT = 10_000;
+
+ int MIN_PRICE_FOR_CHAMPAGNE = 120_000;
+} | Java | ์ ๋ ์ด ๋ถ๋ถ์ ๊ถ๊ธํด์ ๋๊ธ ๋จ๊ธฐ๊ณ ๊ฐ๋๋ค!! |
@@ -0,0 +1,40 @@
+package christmas.domain.benefit.model;
+
+import christmas.domain.benefit.model.discount.Discount;
+import christmas.domain.benefit.model.gift.Gifts;
+import christmas.domain.menu.model.MenuAndCount;
+import java.util.Collections;
+import java.util.List;
+
+public class Benefits {
+ private final List<Benefit> benefits;
+
+ public Benefits(List<Benefit> benefits) {
+ this.benefits = benefits;
+ }
+
+ public List<MenuAndCount> getGifts() {
+ return benefits.stream()
+ .filter(benefit -> benefit.getClass().equals(Gifts.class))
+ .map(gift -> ((Gifts) gift).getGifts())
+ .flatMap(List::stream)
+ .toList();
+ }
+
+ public List<Benefit> getBenefits() {
+ return Collections.unmodifiableList(benefits);
+ }
+
+ public int getTotalPrice() {
+ return benefits.stream()
+ .mapToInt(Benefit::getBenefitPrice)
+ .sum();
+ }
+
+ public int getDiscountPrice() {
+ return benefits.stream()
+ .filter(benefit -> benefit.getClass().equals(Discount.class))
+ .mapToInt(Benefit::getBenefitPrice)
+ .sum();
+ }
+} | Java | getClass ๋์ instanceOf๋ฅผ ์ฌ์ฉํ ์๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,40 @@
+package christmas.domain.benefit.model;
+
+import christmas.domain.benefit.model.discount.Discount;
+import christmas.domain.benefit.model.gift.Gifts;
+import christmas.domain.menu.model.MenuAndCount;
+import java.util.Collections;
+import java.util.List;
+
+public class Benefits {
+ private final List<Benefit> benefits;
+
+ public Benefits(List<Benefit> benefits) {
+ this.benefits = benefits;
+ }
+
+ public List<MenuAndCount> getGifts() {
+ return benefits.stream()
+ .filter(benefit -> benefit.getClass().equals(Gifts.class))
+ .map(gift -> ((Gifts) gift).getGifts())
+ .flatMap(List::stream)
+ .toList();
+ }
+
+ public List<Benefit> getBenefits() {
+ return Collections.unmodifiableList(benefits);
+ }
+
+ public int getTotalPrice() {
+ return benefits.stream()
+ .mapToInt(Benefit::getBenefitPrice)
+ .sum();
+ }
+
+ public int getDiscountPrice() {
+ return benefits.stream()
+ .filter(benefit -> benefit.getClass().equals(Discount.class))
+ .mapToInt(Benefit::getBenefitPrice)
+ .sum();
+ }
+} | Java | ์ด ๋ถ๋ถ์์ ์บ์คํ
๋ง๊ณ ๋ ์ข์ ๋ฐฉ๋ฒ์ด ์๋์ง ๋ค๋ฅธ ๋ฆฌ๋ทฐ์ด๋ถ๋ค์ ์๊ฒฌ์ด ๊ถ๊ธํฉ๋๋ค! ์ ๋ ๊ณ ๋ฏผํ๋๋ฐ ๋ต์ ๋ชป ๋ด๋ ธ๋ค์ |
@@ -0,0 +1,92 @@
+package christmas.domain.benefit.model.discount;
+
+import christmas.domain.benefit.constance.BenefitConst;
+import christmas.domain.benefit.model.Benefit;
+import christmas.domain.benefit.model.BenefitFactory;
+import christmas.domain.date.model.PromotionDay;
+import christmas.domain.menu.model.MenuType;
+import christmas.domain.menu.model.collection.OrderSheet;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Discount ๋ฅผ ์์ฑํ๋ ์ญํ ๋ค์ `enum` ์์๋ก ๊ด๋ฆฌ
+ */
+public enum DiscountFactories implements BenefitFactory {
+
+ D_DAY_FACTORY(DiscountType.D_DAY) {
+ @Override
+ public boolean canApply(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return promotionDay.getDDayFromXMax() >= 0;
+ }
+
+ @Override
+ int getDiscountPrice(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return BenefitConst.D_DAY_INITIAL_PRICE +
+ promotionDay.getDayFromStart() * BenefitConst.D_DAY_INCREASE_PRICE;
+ }
+ },
+ WEEKDAY_FACTORY(DiscountType.WEEKDAY) {
+ @Override
+ public boolean canApply(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return promotionDay.isWeekDay() &&
+ orderSheet.hasMenuOfType(MenuType.DESSERT);
+ }
+
+ @Override
+ int getDiscountPrice(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return orderSheet.getCountOfMenuType(MenuType.DESSERT) *
+ BenefitConst.WEEKDAY_DISCOUNT_PRICE;
+ }
+ },
+ WEEKEND_FACTORY(DiscountType.WEEKEND) {
+ @Override
+ public boolean canApply(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return promotionDay.isWeekend() &&
+ orderSheet.hasMenuOfType(MenuType.MAIN);
+ }
+
+ @Override
+ int getDiscountPrice(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return orderSheet.getCountOfMenuType(MenuType.MAIN) *
+ BenefitConst.WEEKEND_DISCOUNT_PRICE;
+ }
+ },
+ SPECIAL_FACTORY(DiscountType.SPECIAL) {
+ @Override
+ public boolean canApply(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return promotionDay.isSpecialDay();
+ }
+
+ @Override
+ int getDiscountPrice(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return BenefitConst.SPECIAL_DISCOUNT_PRICE;
+ }
+ };
+
+ private static final DiscountFactories[] discountFactories = DiscountFactories.values();
+
+ private final DiscountType type;
+
+ DiscountFactories(DiscountType type) {
+ this.type = type;
+ }
+
+ public static List<Benefit> of(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return Arrays.stream(discountFactories)
+ .filter(factory -> factory.canApply(promotionDay, orderSheet))
+ .map(factory -> factory.generate(promotionDay, orderSheet))
+ .toList();
+ }
+
+ abstract int getDiscountPrice(PromotionDay promotionDay, OrderSheet orderSheet);
+
+ @Override
+ public Benefit generate(PromotionDay promotionDay, OrderSheet orderSheet) {
+ return new Discount(this.getType(), getDiscountPrice(promotionDay, orderSheet));
+ }
+
+ private DiscountType getType() {
+ return type;
+ }
+} | Java | enum๊ณผ ํฉํ ๋ฆฌ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ์ฒ์ ๋ณด๋๋ฐ, ์ฝ๋์ ๋ถ๋์ด๋ ์ค๋ณต์ ๋ ๋์ ๊ฐ๋
์ฑ ๋ฉด์์๋ ์ ๋ง ํ๋ฅญํ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,19 @@
+package christmas.domain.benefit.model.discount;
+
+public enum DiscountType {
+ D_DAY("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"), //12์ 25์ผ์ ์ง๋์ง ์์ ๊ฒฝ์ฐ //๋ ์ง์ ๋ฐ๋ผ 100์์ฉ ์ฆ๊ฐ
+ WEEKDAY("ํ์ผ ํ ์ธ"), //ํ์ผ์ธ ๊ฒฝ์ฐ // ๋์ ํธ ๋ฉ๋ด * ๊ธ์ก
+ WEEKEND("์ฃผ๋ง ํ ์ธ"), //์ฃผ๋ง์ธ ๊ฒฝ์ฐ // ๋ฉ์ธ ๋ฉ๋ด * ๊ธ์ก
+ SPECIAL("ํน๋ณ ํ ์ธ") //์คํ์
๋ฐ์ด์ธ ๊ฒฝ์ฐ // ๋ฌด์กฐ๊ฑด 1000์
+ ;
+
+ private final String name;
+
+ DiscountType(String name) {
+ this.name = name;
+ }
+
+ String getName() {
+ return name;
+ }
+} | Java | ์ ๋ june๋์ ๋ฐฉ๋ฒ๋, zangsu๋์ ๋ฐฉ๋ฒ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค! Factory๋ฅผ ๋ณ๋๋ก ์ ์ํ๋ ์ฝ๋๋ ์์ฒด๋ ๋ง์์ง๊ธด ํ์ง๋ง, ๊ฐ ํ ์ธ ์์ฑ์ ๋ฐฉ๋ฒ์ด ๋ช
ํํ๊ฒ ๋ค์ด์ฌ ์ ์์๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,82 @@
+package christmas.controller;
+
+import java.util.Set;
+import java.util.function.Supplier;
+
+import christmas.domain.event.PresentEvent;
+import christmas.dto.result.PresentEventResult;
+import christmas.service.EventPlannerService;
+import christmas.domain.order.OrderSheet;
+import christmas.dto.order.OrderInput;
+import christmas.dto.order.VisitDate;
+import christmas.dto.result.EventResult;
+import christmas.exception.CommonIllegalArgumentException;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+public class EventPlannerController {
+ private final EventPlannerService eventPlannerService;
+
+ public EventPlannerController(EventPlannerService eventPlannerService) {
+ this.eventPlannerService = eventPlannerService;
+ }
+
+ public void run() {
+ OutputView.printGreeting();
+
+ OrderSheet orderSheet = getOrders();
+
+ OutputView.printStartEventPlanner(orderSheet.getVisitDate());
+
+ showOrders(orderSheet);
+ showEventBenefits(orderSheet);
+ }
+
+ private OrderSheet getOrders() {
+ VisitDate visitDate = tryUntilInputIsValid(this::getVisitDate);
+ OrderInput orderInput = tryUntilInputIsValid(this::getOrderInput);
+ return eventPlannerService.createOrderSheet(visitDate, orderInput);
+ }
+
+ private VisitDate getVisitDate() {
+ return new VisitDate(InputView.readVisitDate());
+ }
+
+ private OrderInput getOrderInput() {
+ return new OrderInput(InputView.readOrders());
+ }
+
+ private void showOrders(OrderSheet orderSheet) {
+ OutputView.printOrders(orderSheet.getOrders());
+ OutputView.printTotalPayment(orderSheet.getTotalPayment());
+ }
+
+ private void showEventBenefits(OrderSheet orderSheet) {
+ PresentEventResult presentEventResult = eventPlannerService.getSpecificEventResult(orderSheet, PresentEvent.class);
+ OutputView.printPresentEventResult(presentEventResult);
+
+ Set<EventResult> results = eventPlannerService.getEventResults(orderSheet);
+ OutputView.printEventResults(results);
+
+ int totalBenefits = eventPlannerService.getTotalBenefits(results);
+ OutputView.printEventBenefits(totalBenefits);
+
+ int expectedPayment = eventPlannerService.getExpectedPayment(orderSheet);
+ OutputView.printExpectedPayment(expectedPayment);
+
+ showBadge(totalBenefits);
+ }
+
+ private void showBadge(int totalBenefits) {
+ OutputView.printBadgeResult(eventPlannerService.getBadge(totalBenefits));
+ }
+
+ private <T> T tryUntilInputIsValid(Supplier<T> function) {
+ try {
+ return function.get();
+ } catch (CommonIllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ return tryUntilInputIsValid(function);
+ }
+ }
+} | Java | ๋ฐ๋ณต ๊ตฌํํ์ ๊ฑฐ ๋ฉ์ง๋๋ค! |
@@ -0,0 +1,29 @@
+package christmas.domain.badge;
+
+import java.util.Arrays;
+import java.util.function.Predicate;
+
+public enum Badge {
+ STAR("๋ณ", benefits -> (5_000 <= benefits && benefits < 10_000)),
+ TREE("ํธ๋ฆฌ", benefits -> (10_000 <= benefits && benefits < 20_000)),
+ SANTA("์ฐํ", benefits -> (20_000 <= benefits));
+
+ private String name;
+ private Predicate<Integer> condition;
+
+ Badge(String name, Predicate<Integer> condition) {
+ this.name = name;
+ this.condition = condition;
+ }
+
+ public static Badge of(int benefits) {
+ return Arrays.stream(Badge.values())
+ .filter(badge -> badge.condition.test(benefits))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | - ๊ฐ์ธ์ ์ผ๋ก๋ NOTHING์ด๋ผ๋ enum ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. (์ด๊ฑฐ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ ๋ null์ ๋ฐํํ ์ ๋ ์๋ค๋ ์ ์ ๊ฐ๊ณผํ ์ ์์ด์)
- ํน์ [Optional](https://mangkyu.tistory.com/70)์ ์ฌ์ฉํ์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,38 @@
+package christmas.domain.event;
+
+import java.time.LocalDate;
+
+import christmas.domain.order.OrderSheet;
+import christmas.dto.result.ChristmasDDayEventResult;
+import christmas.dto.result.EventResult;
+
+public class ChristmasDDayEvent extends Event implements Discountable{
+ private static final int baseDiscount = 1_000;
+ private static final int increment = 100;
+
+ public ChristmasDDayEvent(EventType eventType, LocalDate startDate, LocalDate endDate) {
+ super(eventType, startDate, endDate);
+ }
+
+ @Override
+ public boolean isNotSatisfiedBy(OrderSheet orderSheet) {
+ return isDayOfWeekNotInDuration(orderSheet.getVisitDate());
+ }
+
+ @Override
+ public EventResult getEventBenefits(OrderSheet orderSheet) {
+ if (isNotSatisfiedBy(orderSheet)) {
+ return null;
+ }
+
+ return new ChristmasDDayEventResult(eventType.getName(), calculateDiscount(orderSheet));
+ }
+
+ private int calculateDiscount(OrderSheet orderSheet) {
+ return (baseDiscount + (getDuration(orderSheet) * increment));
+ }
+
+ private int getDuration(OrderSheet orderSheet){
+ return orderSheet.getVisitDate().getDayOfMonth() - startDate.getDayOfMonth();
+ }
+} | Java | ์์์๋ ์ธ๊ธํ์ง๋ง null์ ๋ฐํํ์ค ๊ฒ์ด๋ผ๋ฉด Optional์ ์ฌ์ฉํ์๋ ๊ฒ์ ์ถ์ฒ๋๋ฆฝ๋๋ค. |
@@ -0,0 +1,41 @@
+package christmas.domain.event;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+
+import christmas.domain.menu.MenuType;
+import christmas.domain.order.OrderSheet;
+import christmas.dto.result.EventResult;
+import christmas.dto.result.WeekendEventResult;
+
+public class WeekdayEvent extends Event implements Discountable{
+ private static final MenuType applicableMenuType = MenuType.DESSERT;
+ private static final int discount = 2_023;
+
+ public WeekdayEvent(EventType eventType, LocalDate startDate, LocalDate endDate) {
+ super(eventType, startDate, endDate);
+ }
+
+ @Override
+ protected boolean isNotSatisfiedBy(OrderSheet orderSheet) {
+ return isDayOfWeekNotInDuration(orderSheet.getVisitDate()) || isNotWeekDay(orderSheet.getVisitDate());
+ }
+
+ @Override
+ public EventResult getEventBenefits(OrderSheet orderSheet) {
+ if (isNotSatisfiedBy(orderSheet)) {
+ return null;
+ }
+
+ int benefitSum = orderSheet.getOrders().entrySet().stream()
+ .filter(order -> order.getKey().getType().equals(applicableMenuType))
+ .mapToInt(order -> order.getValue() * discount)
+ .sum();
+
+ return new WeekendEventResult(eventType.getName(), benefitSum);
+ }
+
+ private boolean isNotWeekDay(LocalDate localDate) {
+ return localDate.getDayOfWeek().equals(DayOfWeek.SATURDAY) || localDate.getDayOfWeek().equals(DayOfWeek.FRIDAY);
+ }
+} | Java | order์์ get~().get~() ํ์์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ ๊ธฐ์ฐจ ์ถฉ๋์ด๋ผ๊ณ ํฉ๋๋ค. ๊ธฐ์ฐจ ์ถฉ๋์ ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ์์ ๋ง์ด ์ง์ํฉ๋๋ค. order์์ public method๋ก `boolean isType(Type type)` ๋ฅผ ์ ๊ณตํ๋ ๊ฒ์ด ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค.
- ์ฐธ๊ณ ์๋ฃ
- ํ๋ฆฌ์ฝ์ค 3์ฃผ์ฐจ ๊ณตํต ํผ๋๋ฐฑ "๊ฐ์ฒด๋ ๊ฐ์ฒด์ค๋ฝ๊ฒ ์ฌ์ฉํ๋ค"
- https://hyesun03.github.io/2019/04/01/method-chain-vs-train-wrek/ |
@@ -0,0 +1,41 @@
+package christmas.domain.event;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+
+import christmas.domain.menu.MenuType;
+import christmas.domain.order.OrderSheet;
+import christmas.dto.result.EventResult;
+import christmas.dto.result.WeekendEventResult;
+
+public class WeekdayEvent extends Event implements Discountable{
+ private static final MenuType applicableMenuType = MenuType.DESSERT;
+ private static final int discount = 2_023;
+
+ public WeekdayEvent(EventType eventType, LocalDate startDate, LocalDate endDate) {
+ super(eventType, startDate, endDate);
+ }
+
+ @Override
+ protected boolean isNotSatisfiedBy(OrderSheet orderSheet) {
+ return isDayOfWeekNotInDuration(orderSheet.getVisitDate()) || isNotWeekDay(orderSheet.getVisitDate());
+ }
+
+ @Override
+ public EventResult getEventBenefits(OrderSheet orderSheet) {
+ if (isNotSatisfiedBy(orderSheet)) {
+ return null;
+ }
+
+ int benefitSum = orderSheet.getOrders().entrySet().stream()
+ .filter(order -> order.getKey().getType().equals(applicableMenuType))
+ .mapToInt(order -> order.getValue() * discount)
+ .sum();
+
+ return new WeekendEventResult(eventType.getName(), benefitSum);
+ }
+
+ private boolean isNotWeekDay(LocalDate localDate) {
+ return localDate.getDayOfWeek().equals(DayOfWeek.SATURDAY) || localDate.getDayOfWeek().equals(DayOfWeek.FRIDAY);
+ }
+} | Java | ๋ฉ์๋ ์ด๋ฆ์ `isWeekend()`๋ก ํ์๋ฉด ๋ ์ฝ๊ธฐ ์ฌ์์ง๋๋ค.
> notFound, nonDone, notSuccessful ๊ณผ ๊ฐ์ ์ด๋ฆ์ ๋ณ์์ ๊ฐ์ด ๋ถ์ ์ด ๋์ ๋ ์ฝ๊ธฐ ์ด๋ ต๋ค.
์ฐธ๊ณ ์๋ฃ : https://tecoble.techcourse.co.kr/post/2020-04-24-variable_naming/ |
@@ -0,0 +1,28 @@
+package christmas.dto.order;
+
+import java.time.DateTimeException;
+import java.time.LocalDate;
+import java.time.YearMonth;
+
+import christmas.exception.IllegalDateException;
+
+public class VisitDate {
+ private final YearMonth visitYearMonth = YearMonth.of(2023, 12);
+ private final LocalDate visitDate;
+
+ public VisitDate(int input) {
+ this.visitDate = convertBy(input);
+ }
+
+ public LocalDate getVisitDate() {
+ return this.visitDate;
+ }
+
+ private LocalDate convertBy(int input) {
+ try {
+ return visitYearMonth.atDay(input);
+ } catch (DateTimeException e) {
+ throw new IllegalDateException();
+ }
+ }
+} | Java | ์ค! ์ด๋ฐ๊ฒ ์๋ ์ค ๋ชฐ๋๋ค์! ๋ฐฐ์๊ฐ๋๋ค! |
@@ -1,7 +1,11 @@
package christmas;
+import christmas.controller.EventPlannerController;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ AppConfig appConfig = new AppConfig();
+ EventPlannerController controller = new EventPlannerController(appConfig.createEventPlanner());
+ controller.run();
}
} | Java | ํด๋น ํ์ผ์์๋ง ๋ค์ฌ์ฐ๊ธฐ๊ฐ 4์นธ์ด๊ณ ๋ค๋ฅธ ํ์ผ์์๋ 8์นธ์ด๋ค์.
- ์ฐธ๊ณ ์๋ฃ : [Java ์ฝ๋ ์ปจ๋ฒค์
](https://github.com/woowacourse/woowacourse-docs/tree/master/styleguide/java)
> 4.2 ๋ธ๋ญ ๋ค์ฌ์ฐ๊ธฐ: +4 ์คํ์ด์ค
์ ๋ธ๋ก ๋๋ ๋ธ๋ก๊ณผ ์ ์ฌํ ๊ตฌ์กฐ(block-like construct)๊ฐ ์ด๋ฆด ๋๋ง๋ค ๋ค์ฌ์ฐ๊ธฐ๊ฐ ๋ค ์นธ์ฉ ์ฆ๊ฐํฉ๋๋ค. ๋ธ๋ก์ด ๋๋๋ฉด ๋ค์ฌ์ฐ๊ธฐ๋ ์ด์ ๋ค์ฌ์ฐ๊ธฐ ๋จ๊ณ๋ก ๋์๊ฐ๋๋ค. ๋ค์ฌ์ฐ๊ธฐ ๋จ๊ณ๋ ๋ธ๋ก ์ ์ฒด์ ์ฝ๋์ ์ฃผ์ ๋ชจ๋์ ์ ์ฉ๋ฉ๋๋ค. |
@@ -0,0 +1,29 @@
+package christmas.domain.badge;
+
+import java.util.Arrays;
+import java.util.function.Predicate;
+
+public enum Badge {
+ STAR("๋ณ", benefits -> (5_000 <= benefits && benefits < 10_000)),
+ TREE("ํธ๋ฆฌ", benefits -> (10_000 <= benefits && benefits < 20_000)),
+ SANTA("์ฐํ", benefits -> (20_000 <= benefits));
+
+ private String name;
+ private Predicate<Integer> condition;
+
+ Badge(String name, Predicate<Integer> condition) {
+ this.name = name;
+ this.condition = condition;
+ }
+
+ public static Badge of(int benefits) {
+ return Arrays.stream(Badge.values())
+ .filter(badge -> badge.condition.test(benefits))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | null ์ฒ๋ฆฌ๊ฐ ๊ณ ๋ฏผ์ด์๋๋ฐ NOTHING์ ๋ฐํํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ๊ฐ์์ ๐ |
@@ -0,0 +1,41 @@
+package christmas.domain.event;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+
+import christmas.domain.menu.MenuType;
+import christmas.domain.order.OrderSheet;
+import christmas.dto.result.EventResult;
+import christmas.dto.result.WeekendEventResult;
+
+public class WeekdayEvent extends Event implements Discountable{
+ private static final MenuType applicableMenuType = MenuType.DESSERT;
+ private static final int discount = 2_023;
+
+ public WeekdayEvent(EventType eventType, LocalDate startDate, LocalDate endDate) {
+ super(eventType, startDate, endDate);
+ }
+
+ @Override
+ protected boolean isNotSatisfiedBy(OrderSheet orderSheet) {
+ return isDayOfWeekNotInDuration(orderSheet.getVisitDate()) || isNotWeekDay(orderSheet.getVisitDate());
+ }
+
+ @Override
+ public EventResult getEventBenefits(OrderSheet orderSheet) {
+ if (isNotSatisfiedBy(orderSheet)) {
+ return null;
+ }
+
+ int benefitSum = orderSheet.getOrders().entrySet().stream()
+ .filter(order -> order.getKey().getType().equals(applicableMenuType))
+ .mapToInt(order -> order.getValue() * discount)
+ .sum();
+
+ return new WeekendEventResult(eventType.getName(), benefitSum);
+ }
+
+ private boolean isNotWeekDay(LocalDate localDate) {
+ return localDate.getDayOfWeek().equals(DayOfWeek.SATURDAY) || localDate.getDayOfWeek().equals(DayOfWeek.FRIDAY);
+ }
+} | Java | ์ค,, ์ด๋ถ๋ถ๋ ๊ตฌํํ๋ฉด์ ๋ง์กฑ์ค๋ฝ์ง ์์์ ๊ณ ๋ฏผ์ด ๋ง์๋๋ฐ ์กฐ์ธํด์ฃผ์ ๋ฐฉ๋ฒ๋๋ก Order ๋ด๋ถ์์ ํ์ธํ๋๊ฒ ๋ ์ข์์ ๊ฒ ๊ฐ๋ค์. |
@@ -1,7 +1,11 @@
package christmas;
+import christmas.controller.EventPlannerController;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ AppConfig appConfig = new AppConfig();
+ EventPlannerController controller = new EventPlannerController(appConfig.createEventPlanner());
+ controller.run();
}
} | Java | ๋ถ๋ช
4์นธ์ผ๋ก ์ค์ ํ๋๋ฐ ์ ์ด๋ ๊ฒ ๋์ง ๋ชจ๋ฅด๊ฒ ๋ค์ ๐ญ |
@@ -0,0 +1,29 @@
+package christmas.domain.badge;
+
+import java.util.Arrays;
+import java.util.function.Predicate;
+
+public enum Badge {
+ STAR("๋ณ", benefits -> (5_000 <= benefits && benefits < 10_000)),
+ TREE("ํธ๋ฆฌ", benefits -> (10_000 <= benefits && benefits < 20_000)),
+ SANTA("์ฐํ", benefits -> (20_000 <= benefits));
+
+ private String name;
+ private Predicate<Integer> condition;
+
+ Badge(String name, Predicate<Integer> condition) {
+ this.name = name;
+ this.condition = condition;
+ }
+
+ public static Badge of(int benefits) {
+ return Arrays.stream(Badge.values())
+ .filter(badge -> badge.condition.test(benefits))
+ .findFirst()
+ .orElse(null);
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | Predicate๋ก ๊ตฌํํ๋ ํจ์ฌ ๊น๋ํ๋ค์! |
@@ -0,0 +1,26 @@
+package christmas.domain.event;
+
+import java.time.LocalDate;
+
+import christmas.domain.order.OrderSheet;
+import christmas.dto.result.EventResult;
+
+public abstract class Event {
+ EventType eventType;
+ LocalDate startDate;
+ LocalDate endDate;
+
+ public Event(EventType eventType, LocalDate startDate, LocalDate endDate) {
+ this.eventType = eventType;
+ this.startDate = startDate;
+ this.endDate = endDate;
+ }
+
+ protected boolean isDayOfWeekNotInDuration(LocalDate localDate) {
+ return localDate.isBefore(startDate) || localDate.isAfter(endDate);
+ }
+
+ protected abstract boolean isNotSatisfiedBy(OrderSheet orderSheet);
+
+ public abstract EventResult getEventBenefits(OrderSheet orderSheet);
+} | Java | ์ถ์ ํด๋์ค์ ์ธํฐํ์ด์ค ํ์ฉ์ด ๋ฉ์ง๋ค์! ๋ฐฐ์๊ฐ๋๋ค |
@@ -0,0 +1,9 @@
+package christmas.exception;
+
+public class CommonIllegalArgumentException extends IllegalArgumentException {
+ public static final String EXCEPTION_PREFIX = "[ERROR] %s";
+
+ public CommonIllegalArgumentException(String message) {
+ super(String.format(EXCEPTION_PREFIX, message));
+ }
+} | Java | EXCEPTION_PREFIX, INVALID_ORDER_MESSAGE ๋ฑ์ ์์ธ ๋ฉ์์ง๋ ์ฌ๋ฌ ํด๋์ค์์ ์ฌ์ฉ๋๋๋ฐ Enum์ผ๋ก ๊ตฌํํ์ง ์์ผ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,9 @@
+package christmas.exception;
+
+public class CommonIllegalArgumentException extends IllegalArgumentException {
+ public static final String EXCEPTION_PREFIX = "[ERROR] %s";
+
+ public CommonIllegalArgumentException(String message) {
+ super(String.format(EXCEPTION_PREFIX, message));
+ }
+} | Java | ์์๋ค์ ๋ฌด์กฐ๊ฑด ENUM ์ผ๋ก ๊ด๋ฆฌํ๊ธฐ๋ณด๋ค๋ ํ์ํ ํด๋์ค ๋ด๋ถ์ ์์น์ํค๋๊ฒ ๋ง๋ค๊ณ ์๊ฐํด์ ENUM์ผ๋ก ๊ตฌํํ์ง ์์์ต๋๋ค.
์ ๋ ์ด ๋ถ๋ถ์ ๋ค์ ๋ณด๋ฉด์ ๊ณ ๋ฏผ์ด ๋ง์๋๋ฐ, ๊ณตํต๋ ์ถ๋ ฅ ํ์์ด ์๋ค๋ฉด ENUM์ผ๋ก ๊ด๋ฆฌํ์ด๋ ๊ด์ฐฎ์์ ๊ฒ ๊ฐ๋ค์ ! |
@@ -0,0 +1,57 @@
+package christmas.domain.menu;
+
+import java.util.Arrays;
+
+import christmas.exception.MenuNotFoundException;
+
+public enum Menu {
+ MUSHROOM_SOUP(MenuType.APPETIZER, "์์ก์ด์ํ", 6_000),
+ TAPAS(MenuType.APPETIZER, "ํํ์ค", 5_500),
+ CAESAR_SALAD(MenuType.APPETIZER, "์์ ์๋ฌ๋", 8_000),
+ T_BONE_STEAK(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
+ BARBECUE_RIB(MenuType.MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000),
+ SEAFOOD_PASTA(MenuType.MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000),
+ CHRISTMAS_PASTA(MenuType.MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000),
+ CHOCOLATE_CAKE(MenuType.DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000),
+ ICECREAM(MenuType.DESSERT, "์์ด์คํฌ๋ฆผ", 5_000),
+ ZERO_COKE(MenuType.DRINK, "์ ๋ก์ฝ๋ผ", 3_000),
+ RED_WINE(MenuType.DRINK, "๋ ๋์์ธ", 60_000),
+ CHAMPAGNE(MenuType.DRINK, "์ดํ์ธ", 25_000);
+ private MenuType type;
+ private String name;
+ private int price;
+
+ Menu(MenuType type, String name, int price) {
+ this.type = type;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu from(String input) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.name.equals(input))
+ .findFirst()
+ .orElseThrow(MenuNotFoundException::new);
+ }
+
+ public MenuType getType() {
+ return this.type;
+ }
+
+ public String getMenuName() {
+ return this.name;
+ }
+
+ public int getPrice() {
+ return this.price;
+ }
+
+ public int getPayment(int quantity) {
+ return (this.price * quantity);
+ }
+
+ public static boolean isMatchTo(String input, MenuType type) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(menu -> menu.name.equals(input) && menu.type.equals(type));
+ }
+} | Java | enum ์์๋ค์ด ์ธ๋ถ ์นดํ
๊ณ ๋ฆฌํ ๋ ์ ์์ ๋๋ ๊ฐํ์ ํตํด ๊ตฌ๋ถ์์ผ ์ฃผ๋ฉด ๊ฐ๋
์ฑ์ด ํจ์ฌ ์ข์์ง๋๋ค!
```suggestion
CAESAR_SALAD(MenuType.APPETIZER, "์์ ์๋ฌ๋", 8_000),
T_BONE_STEAK(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
``` |
@@ -0,0 +1,57 @@
+package christmas.domain.menu;
+
+import java.util.Arrays;
+
+import christmas.exception.MenuNotFoundException;
+
+public enum Menu {
+ MUSHROOM_SOUP(MenuType.APPETIZER, "์์ก์ด์ํ", 6_000),
+ TAPAS(MenuType.APPETIZER, "ํํ์ค", 5_500),
+ CAESAR_SALAD(MenuType.APPETIZER, "์์ ์๋ฌ๋", 8_000),
+ T_BONE_STEAK(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
+ BARBECUE_RIB(MenuType.MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000),
+ SEAFOOD_PASTA(MenuType.MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000),
+ CHRISTMAS_PASTA(MenuType.MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000),
+ CHOCOLATE_CAKE(MenuType.DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000),
+ ICECREAM(MenuType.DESSERT, "์์ด์คํฌ๋ฆผ", 5_000),
+ ZERO_COKE(MenuType.DRINK, "์ ๋ก์ฝ๋ผ", 3_000),
+ RED_WINE(MenuType.DRINK, "๋ ๋์์ธ", 60_000),
+ CHAMPAGNE(MenuType.DRINK, "์ดํ์ธ", 25_000);
+ private MenuType type;
+ private String name;
+ private int price;
+
+ Menu(MenuType type, String name, int price) {
+ this.type = type;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu from(String input) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.name.equals(input))
+ .findFirst()
+ .orElseThrow(MenuNotFoundException::new);
+ }
+
+ public MenuType getType() {
+ return this.type;
+ }
+
+ public String getMenuName() {
+ return this.name;
+ }
+
+ public int getPrice() {
+ return this.price;
+ }
+
+ public int getPayment(int quantity) {
+ return (this.price * quantity);
+ }
+
+ public static boolean isMatchTo(String input, MenuType type) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(menu -> menu.name.equals(input) && menu.type.equals(type));
+ }
+} | Java | ์ ๋ฌ ๋ฐ๋ ๋ฐ์ดํฐ๊ฐ ๋ฉ๋ด ์ด๋ฆ์ด๋ผ๋ ๊ฒ ์ ๋๋ ์ต์ํ์ผ๋ก ์ ๋ณด๋ฅผ ์ ๊ณตํด ์ค๋ค๋ฉด ํด๋น ๋ฉ์๋์ ์ ์๋ถ๋ง ๋ณด๊ณ ๋ ๋ฉ์๋์ ํ๋์ ์ถ๋ก ํ๊ธฐ ๋ ์ฌ์์ง๋๋ค!
```suggestion
public static Menu from(String name) {
``` |
@@ -0,0 +1,57 @@
+package christmas.domain.menu;
+
+import java.util.Arrays;
+
+import christmas.exception.MenuNotFoundException;
+
+public enum Menu {
+ MUSHROOM_SOUP(MenuType.APPETIZER, "์์ก์ด์ํ", 6_000),
+ TAPAS(MenuType.APPETIZER, "ํํ์ค", 5_500),
+ CAESAR_SALAD(MenuType.APPETIZER, "์์ ์๋ฌ๋", 8_000),
+ T_BONE_STEAK(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
+ BARBECUE_RIB(MenuType.MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000),
+ SEAFOOD_PASTA(MenuType.MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000),
+ CHRISTMAS_PASTA(MenuType.MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000),
+ CHOCOLATE_CAKE(MenuType.DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000),
+ ICECREAM(MenuType.DESSERT, "์์ด์คํฌ๋ฆผ", 5_000),
+ ZERO_COKE(MenuType.DRINK, "์ ๋ก์ฝ๋ผ", 3_000),
+ RED_WINE(MenuType.DRINK, "๋ ๋์์ธ", 60_000),
+ CHAMPAGNE(MenuType.DRINK, "์ดํ์ธ", 25_000);
+ private MenuType type;
+ private String name;
+ private int price;
+
+ Menu(MenuType type, String name, int price) {
+ this.type = type;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu from(String input) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.name.equals(input))
+ .findFirst()
+ .orElseThrow(MenuNotFoundException::new);
+ }
+
+ public MenuType getType() {
+ return this.type;
+ }
+
+ public String getMenuName() {
+ return this.name;
+ }
+
+ public int getPrice() {
+ return this.price;
+ }
+
+ public int getPayment(int quantity) {
+ return (this.price * quantity);
+ }
+
+ public static boolean isMatchTo(String input, MenuType type) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(menu -> menu.name.equals(input) && menu.type.equals(type));
+ }
+} | Java | ๋ฉ๋ด๊ฐ ์ด๋ค ํ์
์ธ์ง ํ๋จํ๋ ๊ฒ์ ๋ฉ๋ด ํด๋์ค์ ์ฑ
์์ด๋ผ๊ณ ์๊ฐํด์.
getter๋ฅผ ๋ง๋๋ ๋์ `boolean isTypeOf(MenuType expectedType)` ๊ณผ ๊ฐ์ ๋ฉ์๋๋ฅผ ๊ตฌํํด ๋ณด๋ ๊ฑด ์ด๋จ๊น์?
ํด๋น ํด๋์ค์ ์บก์ํ๊ฐ ๋ ์ ์ ๊ณต๋ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,36 @@
+package christmas.domain.event;
+
+import java.time.LocalDate;
+
+import christmas.domain.menu.Menu;
+import christmas.domain.order.OrderSheet;
+import christmas.dto.result.EventResult;
+import christmas.dto.result.PresentEventResult;
+
+public class PresentEvent extends Event{
+ private final Menu present = Menu.CHAMPAGNE;
+ private static final int presentQuantity = 1;
+ private static final int requiredPayment = 120_000;
+
+ public PresentEvent(EventType eventType, LocalDate startDate, LocalDate endDate) {
+ super(eventType, startDate, endDate);
+ }
+
+ @Override
+ protected boolean isNotSatisfiedBy(OrderSheet orderSheet) {
+ return isDayOfWeekNotInDuration(orderSheet.getVisitDate()) || isLessThanRequiredPayment(orderSheet.getTotalPayment());
+ }
+
+ @Override
+ public EventResult getEventBenefits(OrderSheet orderSheet) {
+ if (isNotSatisfiedBy(orderSheet)) {
+ return null;
+ }
+
+ return new PresentEventResult(eventType.getName(), present.getPrice(), Menu.CHAMPAGNE, presentQuantity);
+ }
+
+ private boolean isLessThanRequiredPayment(int totalPayment) {
+ return totalPayment < requiredPayment;
+ }
+} | Java | ํ ์ค์์ ์ฝ๋๊ฐ ๋๋ฌด ๊ธธ์ด์ง๋ค๋ฉด ์ ์ ํ ๊ฐํ์ ํด ์ฃผ์ด ๊ฐ๋
์ฑ์ ๋์ฌ์ค ์ ์๋๋ฐ์
๋ณดํต ๋
ผ๋ฆฌ์ฐ์ฐ์๋ก ์ฝ๋๊ฐ ์ฐ๊ฒฐ๋์ด ์๋ค๋ฉด ๋
ผ๋ฆฌ์ฐ์ฐ์ ์์์ ๊ฐํ์ ์์ผ์ฃผ๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด๋ผ ํฉ๋๋ค!
[๋ค์ด๋ฒ ์บ ํผ์ค ํต๋ฐ์ด ์ปจ๋ฒค์
](https://naver.github.io/hackday-conventions-java/)
```suggestion
return isDayOfWeekNotInDuration(orderSheet.getVisitDate())
|| isLessThanRequiredPayment(orderSheet.getTotalPayment());
``` |
@@ -0,0 +1,28 @@
+package christmas.dto.order;
+
+import java.time.DateTimeException;
+import java.time.LocalDate;
+import java.time.YearMonth;
+
+import christmas.exception.IllegalDateException;
+
+public class VisitDate {
+ private final YearMonth visitYearMonth = YearMonth.of(2023, 12);
+ private final LocalDate visitDate;
+
+ public VisitDate(int input) {
+ this.visitDate = convertBy(input);
+ }
+
+ public LocalDate getVisitDate() {
+ return this.visitDate;
+ }
+
+ private LocalDate convertBy(int input) {
+ try {
+ return visitYearMonth.atDay(input);
+ } catch (DateTimeException e) {
+ throw new IllegalDateException();
+ }
+ }
+} | Java | ํด๋น ํด๋์ค๊ฐ ๋ ์ง์ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ ๋งํผ ์ด ํด๋์ค๋ DTO์ ์ญํ ๋ง ์ํํ๊ธฐ ๋ณด๋จ, ํด๋น ๋ ์ง๊ฐ ์ฃผ๋ง์ธ์ง ๋ฑ์ ์ ๋ณด๋ฅผ ์ ๊ณตํ๋ ๋ฉ์๋๋ค์ด ๊ตฌํ๋์ด ์๋ ๊ฒ์ด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค.
์ฝ๋์ ์์ง๋๊ฐ ๋์์ง ์ ์์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,36 @@
+package christmas.domain.event;
+
+import java.time.LocalDate;
+
+import christmas.domain.menu.Menu;
+import christmas.domain.order.OrderSheet;
+import christmas.dto.result.EventResult;
+import christmas.dto.result.PresentEventResult;
+
+public class PresentEvent extends Event{
+ private final Menu present = Menu.CHAMPAGNE;
+ private static final int presentQuantity = 1;
+ private static final int requiredPayment = 120_000;
+
+ public PresentEvent(EventType eventType, LocalDate startDate, LocalDate endDate) {
+ super(eventType, startDate, endDate);
+ }
+
+ @Override
+ protected boolean isNotSatisfiedBy(OrderSheet orderSheet) {
+ return isDayOfWeekNotInDuration(orderSheet.getVisitDate()) || isLessThanRequiredPayment(orderSheet.getTotalPayment());
+ }
+
+ @Override
+ public EventResult getEventBenefits(OrderSheet orderSheet) {
+ if (isNotSatisfiedBy(orderSheet)) {
+ return null;
+ }
+
+ return new PresentEventResult(eventType.getName(), present.getPrice(), Menu.CHAMPAGNE, presentQuantity);
+ }
+
+ private boolean isLessThanRequiredPayment(int totalPayment) {
+ return totalPayment < requiredPayment;
+ }
+} | Java | ํจ์ฌ ๊น๋ํด์ง ๊ฒ ๊ฐ๋ค์ :) ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,57 @@
+package christmas.domain.menu;
+
+import java.util.Arrays;
+
+import christmas.exception.MenuNotFoundException;
+
+public enum Menu {
+ MUSHROOM_SOUP(MenuType.APPETIZER, "์์ก์ด์ํ", 6_000),
+ TAPAS(MenuType.APPETIZER, "ํํ์ค", 5_500),
+ CAESAR_SALAD(MenuType.APPETIZER, "์์ ์๋ฌ๋", 8_000),
+ T_BONE_STEAK(MenuType.MAIN, "ํฐ๋ณธ์คํ
์ดํฌ", 55_000),
+ BARBECUE_RIB(MenuType.MAIN, "๋ฐ๋นํ๋ฆฝ", 54_000),
+ SEAFOOD_PASTA(MenuType.MAIN, "ํด์ฐ๋ฌผํ์คํ", 35_000),
+ CHRISTMAS_PASTA(MenuType.MAIN, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25_000),
+ CHOCOLATE_CAKE(MenuType.DESSERT, "์ด์ฝ์ผ์ดํฌ", 15_000),
+ ICECREAM(MenuType.DESSERT, "์์ด์คํฌ๋ฆผ", 5_000),
+ ZERO_COKE(MenuType.DRINK, "์ ๋ก์ฝ๋ผ", 3_000),
+ RED_WINE(MenuType.DRINK, "๋ ๋์์ธ", 60_000),
+ CHAMPAGNE(MenuType.DRINK, "์ดํ์ธ", 25_000);
+ private MenuType type;
+ private String name;
+ private int price;
+
+ Menu(MenuType type, String name, int price) {
+ this.type = type;
+ this.name = name;
+ this.price = price;
+ }
+
+ public static Menu from(String input) {
+ return Arrays.stream(Menu.values())
+ .filter(menu -> menu.name.equals(input))
+ .findFirst()
+ .orElseThrow(MenuNotFoundException::new);
+ }
+
+ public MenuType getType() {
+ return this.type;
+ }
+
+ public String getMenuName() {
+ return this.name;
+ }
+
+ public int getPrice() {
+ return this.price;
+ }
+
+ public int getPayment(int quantity) {
+ return (this.price * quantity);
+ }
+
+ public static boolean isMatchTo(String input, MenuType type) {
+ return Arrays.stream(Menu.values())
+ .anyMatch(menu -> menu.name.equals(input) && menu.type.equals(type));
+ }
+} | Java | ํ์คํ ์์ ๊ฐ์ด ๊ตฌํํ๋๊ฒ ์บก์ํ ์ธก๋ฉด์์ ๋ ์ข์ ๊ฒ ๊ฐ๋ค์ ๊ผผ๊ผผํ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค ๐ |
@@ -0,0 +1,28 @@
+package christmas.dto.order;
+
+import java.time.DateTimeException;
+import java.time.LocalDate;
+import java.time.YearMonth;
+
+import christmas.exception.IllegalDateException;
+
+public class VisitDate {
+ private final YearMonth visitYearMonth = YearMonth.of(2023, 12);
+ private final LocalDate visitDate;
+
+ public VisitDate(int input) {
+ this.visitDate = convertBy(input);
+ }
+
+ public LocalDate getVisitDate() {
+ return this.visitDate;
+ }
+
+ private LocalDate convertBy(int input) {
+ try {
+ return visitYearMonth.atDay(input);
+ } catch (DateTimeException e) {
+ throw new IllegalDateException();
+ }
+ }
+} | Java | VisitDate ๋ด๋ถ์์ ์ฃผ๋ง์ธ์ง ํ์ธํ๋ ๋ฉ์๋๊ฐ ์์๋ค๋ฉด Event ๊ฐ์ฒด ๋ด๋ถ์์ getter๋ฅผ ์ฌ์ฉํ์ง ์์๋ ๋์๊ฒ ๋ค์ ๐ |
@@ -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,21 @@
+package christmas.controller;
+
+import christmas.dto.MenuCount;
+import java.util.Arrays;
+import java.util.List;
+
+public class Parser {
+
+ public static int parseDate(String input) {
+ return Integer.parseInt(input);
+ }
+
+ public static List<String> parseMenus(String input, String delimiter) {
+ return Arrays.stream(input.split(delimiter)).toList();
+ }
+
+ public static MenuCount parseMenu(String input, String delimiter) {
+ String[] split = input.split(delimiter);
+ return new MenuCount(split[0], Integer.parseInt(split[1]));
+ }
+} | Java | ์ ๋ Parsing ์์ฒด๋ฅผ InputView์์ ํ๋๋ฐ, ์ด๊ฑธ Parser๋ก ๋ถ๋ฆฌํ์ ์ด์ ๊ฐ ์์ผ์ค๊น์? |
@@ -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 | Meun ์์ฑ์์ ์ธ์๋ก ๋ฐ๋ ๊ฒ์ด ๋ง๋ค๊ณ ๋์ addํ๋๊ฒ ๋ณด๋ค ์ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค.
Menu๊ฐ add๋๊ธฐ ์ ๊น์ง๋ ๋น ๋ฉ๋ด์ธ ์ํ๊ฐ ์ ์ง๋๋๊น์. ๊ทธ๋ฆฌ๊ณ ๋ถ๋ณ ๊ฐ์ฒด ๋ฌธ์ ๋ ์๊ฒ ๋ค์.
- ์ฐธ๊ณ : [๋ธ๋ก๊ทธ ๊ธ](https://velog.io/@conatuseus/Java-Immutable-Object%EB%B6%88%EB%B3%80%EA%B0%9D%EC%B2%B4#immutable-object%EC%9D%98-%EC%9E%A5%EB%8B%A8%EC%A0%90)
- ๊ตณ์ด ๊ฐ๋ณ๊ฐ์ฒด๋ก ๋ง๋ค ์ด์ ๋ ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -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 | ๊ฒ์ฆ ๊ณผ์ ์ ๊ฐ ๋ฉ์๋๋ณ๋ก ๋๋์ ๊ฒ์ด ์ธ์๊น์ต๋๋ค! |
@@ -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 | ํด๋น ๊ฒ์ฆ ๊ณผ์ ์ Menus์์ ํ๋๊ฒ ์ด๋จ๊น์? Menu ์์ฒด๊ฐ ์์ฑ๋์ง ์๋๋ก ํ๋ ํธ์ด ๊ฐ์ธ์ ์ผ๋ก ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -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,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 | `private static final DATE_REQUEST_MESSAGE = "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)"`
์ด๋ ๊ฒ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ ์ข๋ค๊ณ ์๊ฐํฉ๋๋ค! |
@@ -0,0 +1,74 @@
+package christmas.domain;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.time.DayOfWeek;
+import java.util.List;
+import java.util.stream.IntStream;
+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;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class DateTest {
+
+ @DisplayName("๋ ์ง ๋๋ฉ์ธ ์์ฑ ํ
์คํธ")
+ @Test
+ void create() {
+ IntStream.range(1, 32)
+ .forEach(date -> assertDoesNotThrow(() -> new Date(date)));
+ }
+
+ @DisplayName("๋ ์ง ๋๋ฉ์ธ_๋ฒ์ ๋ฐ์ ๋ ์ง๋ฉด ์์ธ ๋ฐ์")
+ @ParameterizedTest
+ @ValueSource(ints = {0, 32})
+ void createOutRange(int date) {
+ assertThatThrownBy(() -> new Date(date))
+ .isInstanceOf(PromotionException.class)
+ .hasMessage(ErrorMessage.INVALID_DATE_MESSAGE.message());
+ }
+
+ @DisplayName("๋ ์ง -> ์์ผ ํ
์คํธ")
+ @ParameterizedTest
+ @CsvSource({"1,FRIDAY", "25,MONDAY", "31,SUNDAY"})
+ void dayOfWeek(int date, String expected) {
+ DayOfWeek dayOfWeek = new Date(date).dayOfWeek();
+
+ assertThat(dayOfWeek.name()).isEqualTo(expected);
+ }
+
+ @DisplayName("ํน์ ๋ ๋ค์ ํด๋น ๋ ์ง๊ฐ ํฌํจ๋๋์ง ํ
์คํธ")
+ @ParameterizedTest
+ @CsvSource({"1,true", "25,false"})
+ void isIncluded(int dateSource, boolean expected) {
+ Date date = new Date(dateSource);
+ List<Integer> dates = List.of(1, 2);
+
+ assertThat(date.isIncluded(dates)).isEqualTo(expected);
+ }
+
+ @DisplayName("ํน์ ๊ธฐ๊ฐ์ ํด๋น๋ ์ง๊ฐ ํฌํจ๋๋์ง ํ
์คํธ")
+ @ParameterizedTest
+ @CsvSource({"1,true", "26,false"})
+ void isInRange(int dateSource, boolean expected) {
+ Date date = new Date(dateSource);
+
+ assertThat(date.isInRange(1, 25))
+ .isEqualTo(expected);
+ }
+
+ @DisplayName("ํด๋น ๋ ์ง๊ฐ ํน์ ๋ ๋ก๋ถํฐ ๋ช๋ฒ์งธ ๋ ์ธ์ง ๊ตฌํ๋ ๊ธฐ๋ฅ ํ
์คํธ")
+ @ParameterizedTest
+ @CsvSource({"1,1,0", "31,25,6"})
+ void isInRange(int dateSource, int from, int expectedDay) {
+ Date date = new Date(dateSource);
+
+ assertThat(date.dayFromDate(from))
+ .isEqualTo(expectedDay);
+ }
+} | Java | ์ ๋ฐ์ ์ผ๋ก ํ
์คํธ๋ฅผ ์ฐธ ๊น๋ํ๊ฒ ์์ฑํ์
จ๋ค์! ์ ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค! |
@@ -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 | ๋ฐฉ๋ฌธ ๋ ์ง์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ดํ ๋๋ฉ์ธ์ด ์ปจํธ๋กค๋ฌ์ ๋
ธ์ถ๋์ด์๋ค๊ณ ์๊ฐํฉ๋๋ค.
๋น์ฆ๋์ค ๋ก์ง์ ์ฒ๋ฆฌํ๋ ์๋น์ค ๋ ์ด์ด๋ฅผ ๋ง๋ค์ง ์์ ์ด์ ๊ฐ ์์ผ์ ์ง ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,46 @@
+package christmas.domain;
+
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.List;
+
+public class Date {
+ public static final int EVENT_YEAR = 2023;
+ public static final int EVENT_MONTH = 12;
+ public static final int MIN_DATE = 1;
+ public static final int MAX_DATE = 31;
+ private final int date;
+
+ public Date(int date) {
+ validate(date);
+ this.date = date;
+ }
+
+ public int getDate() {
+ return date;
+ }
+
+ private void validate(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw new PromotionException(ErrorMessage.INVALID_DATE_MESSAGE);
+ }
+ }
+
+ public int dayFromDate(int other) {
+ return date - other;
+ }
+
+ public DayOfWeek dayOfWeek() {
+ return LocalDate.of(EVENT_YEAR, EVENT_MONTH, date).getDayOfWeek();
+ }
+
+ public boolean isIncluded(List<Integer> dates) {
+ return dates.contains(date);
+ }
+
+ public boolean isInRange(int startInclusive, int endInclusive) {
+ return startInclusive <= date && date <= endInclusive;
+ }
+} | Java | ๋ ์ง๋ฅผ int ํ์
์ผ๋ก ํ์
์ 1์ผ๊ณผ 31์ผ ๋ฒ์์ ๋ํ ๊ฒ์ฆ ๋ก์ง์ ์์ฑํ์
จ๋ค์. ์๋ฌด๋๋ ๋ช
๋ฐฑํ ๋ ์ง๋ฅผ ๊ด๋ฆฌํ๋ ํด๋์ค๋ค๋ณด๋ LocalDate๋ฅผ ์ฌ์ฉํ์ฌ ๋ ์ง๋ฅผ ๊ด๋ฆฌํ๋ฉด ์์ฑ์ ์๋ชป๋ ๋ ์ง์ธ ๊ฒฝ์ฐ์ DateTimeException์ด ๋ฐ์ํ๊ณ ์ด ์๋ฌ๋ฅผ ์ก์์ ์ฒ๋ฆฌํ์ฌ ๊ฒ์ฆํ๋ ๋ฐฉ๋ฒ๋ ์ ์ฉํด๋ณด์๋ฉด ์ข ๋ ๋ฒ์ฉ์ ์ธ ๋ ์ง๋ฅผ ๊ด๋ฆฌํ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,32 @@
+package christmas.domain.event;
+
+import christmas.domain.Date;
+import christmas.domain.Menus;
+
+public enum Event {
+ D_DAY_DISCOUNT(new DDayDiscount(), "ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"),
+ WEEKDAY_DISCOUNT(new WeekdayDiscount(), "ํ์ผ ํ ์ธ"),
+ WEEKEND_DISCOUNT(new WeekendDiscount(), "์ฃผ๋ง ํ ์ธ"),
+ SPECIAL_DISCOUNT(new SpecialDiscount(), "ํน๋ณ ํ ์ธ"),
+ GIVEAWAY(new Giveaway(), "์ฆ์ ์ด๋ฒคํธ");
+
+ private final EventPolicy policy;
+ private final String description;
+
+ Event(EventPolicy policy, String description) {
+ this.policy = policy;
+ this.description = description;
+ }
+
+ public String description() {
+ return description;
+ }
+
+ public EventPolicy policy() {
+ return policy;
+ }
+
+ public int benefitAmount(Date date, Menus menus) {
+ return policy.amount(date, menus);
+ }
+} | Java | ์ด๋ฒคํธ๋ฅผ enum์ ์์ฑํด์ ๊ด๋ฆฌํ์
จ๋ค์ ์ ๋ ์ด๋ฐ ์๊ฐ์ ๋ชปํ๋๋ฐ ์๋ก ๋ฐฐ์ฐ๊ฒ ๋๋ค์ ๊ฐ์ฌํฉ๋๋ค. |
@@ -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 | ๊ฐ ๋ฉ๋ด์ ์นดํ
๊ณ ๋ฆฌ๋ enum์ผ๋ก ๋ง๋ค์ด์ ๊ด๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์ด๋จ๊น ํ๋ค์. |
@@ -0,0 +1,21 @@
+package christmas.controller;
+
+import christmas.dto.MenuCount;
+import java.util.Arrays;
+import java.util.List;
+
+public class Parser {
+
+ public static int parseDate(String input) {
+ return Integer.parseInt(input);
+ }
+
+ public static List<String> parseMenus(String input, String delimiter) {
+ return Arrays.stream(input.split(delimiter)).toList();
+ }
+
+ public static MenuCount parseMenu(String input, String delimiter) {
+ String[] split = input.split(delimiter);
+ return new MenuCount(split[0], Integer.parseInt(split[1]));
+ }
+} | Java | InputView์ ๋ฐํ ํ์
์ ๋ชจ๋ String์ผ๋ก ์ ์ ํ ํ๋ณํ์ ์ปจํธ๋กค๋ฌ์์ ํ์ ๋ผ๊ณ ์๊ฐํด์ Parser๋ฅผ ๋ถ๋ฆฌํ์ต๋๋ค. (์ง๊ธ ๋ณด๋ date๋ InputView์์ ํ์ฑ์ ํด๋์ ์์ฝ๋ค์) |
@@ -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 | ์ ๋ฒ ์ฃผ์ฐจ์ ์๋น์ค ๋ ์ด์ด๋ ์ต๋ํ ์๊ฒ ๋ง๋๋ ๊ฒ์ด ์ข๋ค๋ ๋ฆฌ๋ทฐ๊ฐ ์์๊ณ ๊ทธ์ ๋์ํด์ ์ด๋ฒ์ฃผ์ฐจ๋ ์๋น์ค ๋ ์ด์ด ์์ด ๋๋ฉ์ธ์ ์ต๋ํ ๋ก์ง์ ๋ด์๋ฅผ ๋ชฉํ๋ก ๊ตฌํํ์ต๋๋ค! |
@@ -0,0 +1,46 @@
+package christmas.domain;
+
+import christmas.exception.ErrorMessage;
+import christmas.exception.PromotionException;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.util.List;
+
+public class Date {
+ public static final int EVENT_YEAR = 2023;
+ public static final int EVENT_MONTH = 12;
+ public static final int MIN_DATE = 1;
+ public static final int MAX_DATE = 31;
+ private final int date;
+
+ public Date(int date) {
+ validate(date);
+ this.date = date;
+ }
+
+ public int getDate() {
+ return date;
+ }
+
+ private void validate(int date) {
+ if (date < MIN_DATE || date > MAX_DATE) {
+ throw new PromotionException(ErrorMessage.INVALID_DATE_MESSAGE);
+ }
+ }
+
+ public int dayFromDate(int other) {
+ return date - other;
+ }
+
+ public DayOfWeek dayOfWeek() {
+ return LocalDate.of(EVENT_YEAR, EVENT_MONTH, date).getDayOfWeek();
+ }
+
+ public boolean isIncluded(List<Integer> dates) {
+ return dates.contains(date);
+ }
+
+ public boolean isInRange(int startInclusive, int endInclusive) {
+ return startInclusive <= date && date <= endInclusive;
+ }
+} | Java | ๋ต ๋ง์ฝ ๋ค๋ฅธ ๋ฌ๋ ์์๋ค๋ฉด LocalDate ์์ฒด๋ฅผ ์ฌ์ฉํด๋ ์ข์์ ๊ฒ ๊ฐ์ต๋๋ค! ํ์ง๋ง ์ด๋ฒ ๋ฏธ์
์ ๊ฒฝ์ฐ ์ด๋ฒคํธ ๋ฌ์ธ 2023๋
12์์ ํ์ ๋๊ธฐ ๋๋ฌธ์ int๋ง ๊ฐ์ธ์ ์ฌ์ฉํ์ต๋๋ค. |
@@ -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 | ์ฝ๋ฉํธ ์ ๋ง ๊ฐ์ฌํฉ๋๋ค. ์ฌ์ฉ์์์ ํ๋ณ์ ํ ์ง ์ด๋ฒคํธ์์ ํ๋ณ์ ํ ์ง ๋ง์ ๊ณ ๋ฏผ์ ํ๋ ๋ถ๋ถ์ธ๋ฐ ๋ค์ํ๋ฒ ์๊ฐํด๋ณด๊ฒ ์ต๋๋ค!
๋ถ๋ฆฌ๊ฐ ๋ง๋๊ฒ ๊ฐ๋ค์
๊ฐ์ฌํฉ๋๋ค |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.