Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[크리스마스 프로모션] 이승현 미션 제출합니다. #8

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
기능 목록
1. 엔티티 정의 및 의존관계 정리
2. 주문 클래스 및 주문 생성 클래스 정의
3. 입력 검증 및 잘못된 입력 처리
4. 혜택 클래스 정의
5. 도메인 로직에서 할인혜택 적용 기능 구현
6. 출력 view 구현
7. 도메인 로직에 테스트 작성
5 changes: 4 additions & 1 deletion src/main/java/christmas/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package christmas;

import christmas.controller.ChristmasController;

public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
ChristmasController christmasController = new ChristmasController();
christmasController.start();
}
}
53 changes: 53 additions & 0 deletions src/main/java/christmas/controller/ChristmasController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package christmas.controller;

import christmas.domain.util.DayUtil;
import christmas.domain.entity.Order;
import christmas.domain.generators.OrderGenerator;
import christmas.domain.services.BenefitService;
import christmas.domain.util.Printer;
import christmas.domain.view.InputView;
import christmas.domain.view.OutputView;


public class ChristmasController {

OutputView outputView = new OutputView(new Printer());
InputView inputView = new InputView(new Printer());
Printer printer = new Printer();
OrderGenerator orderGenerator = new OrderGenerator();

public void start() {

outputView.printPreface();

int visitDate;

while (true) {
try {
visitDate = inputView.readDate();
DayUtil.validateIsDate(visitDate);
break;
} catch (IllegalArgumentException e) {
printer.println(e.getMessage());
}
}

String orderString;
Order order;
while (true){
try {
orderString = inputView.readMenu();
order = orderGenerator.generateOrder(orderString, visitDate);
break;
} catch (IllegalArgumentException e){
Order.emptyMap();
printer.println(e.getMessage());
}
}

outputView.printMenu(order);
BenefitService benefitService = new BenefitService(order);
benefitService.benefitApplication();
outputView.printBenefit();
}
}
20 changes: 20 additions & 0 deletions src/main/java/christmas/domain/constants/DateEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package christmas.domain.constants;

public class DateEnum {
public enum Date{
PRESENT_YEAR(2023),
DECEMBER(12),
DATE_OF_CHRISTMAS(25),
LAST_DAY_OF_MONTH(31);

private final int value;

Date(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}
}
41 changes: 41 additions & 0 deletions src/main/java/christmas/domain/constants/DiscountPolicyEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package christmas.domain.constants;

public class DiscountPolicyEnum {
public enum Discount{
D_DAY_START_DISCOUNTING_AMOUNT(900),
D_DAY_DAILY_DISCOUNTING_AMOUNT(100),
WEEKLY_DISCOUNTING_AMOUNT(2023),
SPECIAL_DISCOUNTING_AMOUNT(1000),
APPLIED_DISCOUNT_AMOUNT_GET_SANTA(20000),
APPLIED_DISCOUNT_AMOUNT_GET_TREE(10000),
APPLIED_DISCOUNT_AMOUNT_GET_STAR(5000),
APPLIED_AMOUNT_GET_GIFT(120000),
MINIMUM_AMOUNT_TO_DISCOUNT(10000);

private final int value;

Discount(int value) {
this.value = value;
}

public int getValue() {
return value;
}
}

public enum Badge{
SANTA_BADGE("산타"),
TREE_BADGE("트리"),
STAR_BADGE("별");

private final String name;

Badge(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
}
11 changes: 11 additions & 0 deletions src/main/java/christmas/domain/constants/MenuCategoryEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package christmas.domain.constants;

public class MenuCategoryEnum {
public enum MenuCategory{
APPETIZER,
MAIN,
DESSERT,
BEVERAGE
}

}
41 changes: 41 additions & 0 deletions src/main/java/christmas/domain/constants/MenuEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package christmas.domain.constants;

public class MenuEnum {
public enum Menus{
MUSHROOM_SOUP("양송이수프", MenuCategoryEnum.MenuCategory.APPETIZER, 6000),
TAPAS("타파스", MenuCategoryEnum.MenuCategory.APPETIZER, 5500),
CAESAR_SALAD("시저샐러드", MenuCategoryEnum.MenuCategory.APPETIZER, 8000),
TBONE_STEAK("티본스테이크", MenuCategoryEnum.MenuCategory.MAIN, 55000),
BARBCUE_RIBS("바비큐립", MenuCategoryEnum.MenuCategory.MAIN, 54000),
SEA_PASTA("해산물파스타", MenuCategoryEnum.MenuCategory.MAIN, 35000),
CHRISTMAS_PASTA("크리스마스파스타", MenuCategoryEnum.MenuCategory.MAIN, 25000),
CHOCOCAKE("초코케이크", MenuCategoryEnum.MenuCategory.DESSERT, 15000),
ICECREAM("아이스크림", MenuCategoryEnum.MenuCategory.DESSERT, 5000),
ZERO_COKE("제로콜라", MenuCategoryEnum.MenuCategory.BEVERAGE, 3000),
REDWINE("레드와인", MenuCategoryEnum.MenuCategory.BEVERAGE, 60000),
CHAMPAGNE("샴페인", MenuCategoryEnum.MenuCategory.BEVERAGE, 25000);

private final String name;
private final MenuCategoryEnum.MenuCategory category;
private final int price;

Menus(String name, MenuCategoryEnum.MenuCategory category, int price) {
this.name = name;
this.category = category;
this.price = price;
}

public String getName() {
return name;
}

public MenuCategoryEnum.MenuCategory getCategory() {
return category;
}

public int getPrice() {
return price;
}
}

}
119 changes: 119 additions & 0 deletions src/main/java/christmas/domain/entity/Benefits.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package christmas.domain.entity;

public class Benefits {

private static int totalAmountBeforeDiscount;

public static int getTotalAmountBeforeDiscount() {
return totalAmountBeforeDiscount;
}

public static void setTotalAmountBeforeDiscount(int totalAmountBeforeDiscount) {
Benefits.totalAmountBeforeDiscount = totalAmountBeforeDiscount;
}

public static String getGiftMenu() {
return giftMenu;
}

public static void setGiftMenu(String giftMenu) {
Benefits.giftMenu = giftMenu;
}

public static int getdDayDiscountAmount() {
return dDayDiscountAmount;
}

public static void setdDayDiscountAmount(int dDayDiscountAmount) {
Benefits.dDayDiscountAmount = dDayDiscountAmount;
}

public static int getWeekdayDiscountAmount() {
return weekdayDiscountAmount;
}

public static void setWeekdayDiscountAmount(int weekdayDiscountAmount) {
Benefits.weekdayDiscountAmount = weekdayDiscountAmount;
}

public static int getWeekendDiscountAmount() {
return weekendDiscountAmount;
}

public static void setWeekendDiscountAmount(int weekendDiscountAmount) {
Benefits.weekendDiscountAmount = weekendDiscountAmount;
}

public static int getSpecialDayDiscountAmount() {
return specialDayDiscountAmount;
}

public static void setSpecialDayDiscountAmount(int specialDayDiscountAmount) {
Benefits.specialDayDiscountAmount = specialDayDiscountAmount;
}

public static int getGiftEventBenefitAmount() {
return giftEventBenefitAmount;
}

public static void setGiftEventBenefitAmount(int giftEventBenefitAmount) {
Benefits.giftEventBenefitAmount = giftEventBenefitAmount;
}

public static int getTotalBenefitAmount() {
return totalBenefitAmount;
}

public static void setTotalBenefitAmount(int totalDiscountAmount) {
Benefits.totalBenefitAmount = totalDiscountAmount;
}

public static int getTotalAmountAfterDiscount() {
return totalAmountAfterDiscount;
}

public static void setTotalAmountAfterDiscount(int totalAmountAfterDiscount) {
Benefits.totalAmountAfterDiscount = totalAmountAfterDiscount;
}

public static String getDecemberEventBadge() {
return DecemberEventBadge;
}

public static void setDecemberEventBadge(String decemberEventBadge) {
DecemberEventBadge = decemberEventBadge;
}

private static String giftMenu;

private static int dDayDiscountAmount;
private static int weekdayDiscountAmount;
private static int weekendDiscountAmount;
private static int specialDayDiscountAmount;
private static int giftEventBenefitAmount;

private static int totalBenefitAmount;

private static int totalAmountAfterDiscount;

private static String DecemberEventBadge;

public static int accountTotalBenefit(){
totalBenefitAmount =
dDayDiscountAmount
+ weekdayDiscountAmount
+ weekendDiscountAmount
+ specialDayDiscountAmount
+ giftEventBenefitAmount;
return totalBenefitAmount;
}

public static int accountTotalAmountAfterDiscount(){
totalAmountAfterDiscount =
totalAmountBeforeDiscount
- totalBenefitAmount
+ giftEventBenefitAmount;
return totalAmountAfterDiscount;
}

}
76 changes: 76 additions & 0 deletions src/main/java/christmas/domain/entity/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package christmas.domain.entity;

import christmas.domain.constants.MenuCategoryEnum;
import christmas.domain.entity.menu.Menu;
import christmas.domain.entity.menu.MenuBoard;


import java.util.HashMap;
import java.util.Map;

public class Order {


private final int visitDate;
private static Map<Menu, Integer> orderMap = new HashMap<>();

public Map<Menu, Integer> getOrderMap(){
return orderMap;
}

public Order(int visitDate) {
this.visitDate = visitDate;
}

public int getVisitDate() {
return visitDate;
}

public static void emptyMap(){
orderMap.clear();
}

public void putOrderMap(String stringMenu, Integer count){
validateMenuIsExist(stringMenu);
validateMenuIsDuplicated(stringMenu);
validateCount(count);
Menu menu = MenuBoard.getMenus().get(stringMenu);
orderMap.put(menu, count);
}

public static int getTotalOrderAmount(){
int totalPrice = 0;
for(Menu menu : orderMap.keySet()){
totalPrice += (menu.getPrice() * orderMap.get(menu));
}
return totalPrice;
}

public void validateNotOnlyBeverage(){
for(Menu menu : orderMap.keySet()){
if(!(menu.getMenuCategory().equals(MenuCategoryEnum.MenuCategory.BEVERAGE))){
return;
}
}
throw new IllegalArgumentException("[ERROR] 음료만 주문할 시, 주문할 수 없습니다.");
}

private void validateMenuIsExist(String stringMenu){
if(MenuBoard.getMenus().get(stringMenu)==null){
throw new IllegalArgumentException("[ERROR] 유효하지 않은 주문입니다. 다시 입력해 주세요.");
}
}

private void validateMenuIsDuplicated(String stringMenu){
Menu menu = MenuBoard.getMenus().get(stringMenu);
if(orderMap.get(menu)!=null){
throw new IllegalArgumentException("[ERROR] 유효하지 않은 주문입니다. 다시 입력해 주세요.");
}
}

private void validateCount(Integer count){
if(count<=0){
throw new IllegalArgumentException("[ERROR] 유효하지 않은 주문입니다. 다시 입력해 주세요.");
}
}
}
Loading