code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -21,7 +21,9 @@
<body>
<div class="create-account">
<h1 class="heading xl3">Create <br />Account</h1>
- <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ <div class="file-wrapper">
+ <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ </div>
<div class="account-info">
<input type="email" class="input md" placeholder="Email">
<div class="password">
@@ -43,7 +45,6 @@ <h1 class="heading xl3">Create <br />Account</h1>
<button class="btn lg3 blue radius-16 btn-done" onclick="goCreate()">Done</button>
<p class="text md3 btn-cancel" onclick="goCancel()">Cancel</p>
</div>
- <!-- <script type="module" src="./js/common.js" defer></script> -->
<script defer>
//์๋ก์ด ํ์ด์ง ์ด๋ํ๊ธฐ
const goCreate = () => { | Unknown | ๊ฐ์ธ์ฐจ๊ฐ ์๊ฒ ์ง๋ง, ์ ๊ฐ์ธ์ ์ผ๋ก ์ด๋ฒคํธ๋ js์์ ๋ชจ๋ ์ฒ๋ฆฌํ๋ํธ์
๋๋ค..
react๋ฉด ์ปดํผ๋ํธ๋ก ๊ด๋ฆฌ๋๊ธฐ๋๋ฌธ์ ๋ฌด๊ดํ์ง๋ง.. html์์ ๋์ค์ ๋ชจ๋ ํ์ด์ง ์ฐพ์๊ฐ๋ฉด์ ํด๋น ํจ์๋ฅผ ์ ๊ฑฐ ๋๋ ์ถ๊ฐํด์ผ๋ ๊ฒฝ์ฐ๊ฐ ์๊ฑฐ๋ ์. |
@@ -21,7 +21,9 @@
<body>
<div class="create-account">
<h1 class="heading xl3">Create <br />Account</h1>
- <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ <div class="file-wrapper">
+ <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ </div>
<div class="account-info">
<input type="email" class="input md" placeholder="Email">
<div class="password">
@@ -43,7 +45,6 @@ <h1 class="heading xl3">Create <br />Account</h1>
<button class="btn lg3 blue radius-16 btn-done" onclick="goCreate()">Done</button>
<p class="text md3 btn-cancel" onclick="goCancel()">Cancel</p>
</div>
- <!-- <script type="module" src="./js/common.js" defer></script> -->
<script defer>
//์๋ก์ด ํ์ด์ง ์ด๋ํ๊ธฐ
const goCreate = () => { | Unknown | ๋ชจ๋ ์จ๋ผ์ธ์์์๋ title๋๋ label์ด ์์ด์ผ ํฉ๋๋ค. |
@@ -21,7 +21,9 @@
<body>
<div class="create-account">
<h1 class="heading xl3">Create <br />Account</h1>
- <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ <div class="file-wrapper">
+ <input type="file" id="file_1" class="a11y-hidden" ><label for="file_1" class="input-file"></label>
+ </div>
<div class="account-info">
<input type="email" class="input md" placeholder="Email">
<div class="password">
@@ -43,7 +45,6 @@ <h1 class="heading xl3">Create <br />Account</h1>
<button class="btn lg3 blue radius-16 btn-done" onclick="goCreate()">Done</button>
<p class="text md3 btn-cancel" onclick="goCancel()">Cancel</p>
</div>
- <!-- <script type="module" src="./js/common.js" defer></script> -->
<script defer>
//์๋ก์ด ํ์ด์ง ์ด๋ํ๊ธฐ
const goCreate = () => { | Unknown | ์คํฌ๋ฆฝํธ๋ ์ธ๋ถํ์ผ๋ก..
alert๋ณด๋จ dialog๋ฅผ ์ด์ฉํด์ ๊ฒฝ๊ณ ์ฐฝ์ ๊พธ๋ฉฐ๋ณด๋๊ฒ๋ ๋์๋ฉ๋๋ค.
๊ธฐ๋ฅ๋ณ๋ก ํจ์๋ก ๊ตฌํํ์
์ moduleํ ํ๋ก๊ทธ๋๋ฐ์ ์๋ํด๋ณด์ธ์~ |
@@ -1,11 +1,32 @@
-import { useState } from "react";
+import '@styles/App.css';
+import '@styles/reset.css';
+import '@styles/global.css';
+import { Header, Layout, PageRequestError } from '@components/index';
+import { lazy, Suspense } from 'react';
+import { ErrorBoundary } from 'react-error-boundary';
+
+import { CartItemsContext } from './contexts';
+import { useCartItemIds } from './hooks';
+import ProductListPageSkeleton from './pages/ProductListPage/Skeleton/ProductListPageSkeleton/index.';
+
+const ProductListPage = lazy(() => import('@pages/ProductListPage'));
function App() {
- const [count, setCount] = useState(0);
+ const { cartItemIds, refreshCartItemIds, error: cartItemsFetchError } = useCartItemIds();
+ const cartItemsLength = cartItemIds ? Array.from(cartItemIds).length : 0;
return (
<>
- <h1>React Shopping Products</h1>
+ <Header cartItemsLength={cartItemsLength} cartItemsFetchError={cartItemsFetchError} />
+ <Layout>
+ <ErrorBoundary FallbackComponent={({ error }) => <PageRequestError error={error} />}>
+ <CartItemsContext.Provider value={{ cartItemIds, refreshCartItemIds }}>
+ <Suspense fallback={<ProductListPageSkeleton />}>
+ <ProductListPage />
+ </Suspense>
+ </CartItemsContext.Provider>
+ </ErrorBoundary>
+ </Layout>
</>
);
} | Unknown | ์ํ์ ์ฅ๋ฐ๊ตฌ๋ ๋ด๊ธฐ/๋นผ๊ธฐ ํด๋ฆญ ์ api์์ฒญ ํ ๊ฒฐ๊ณผ์ ๋ง์ถ์ด Header ์ ์ฅ๋ฐ๊ตฌ๋ ์์ด์ฝ์ ์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก ์๋์ด ์
๋ฐ์ดํธ ๋์ด์ผํด์
์ฅ๋ฐ๊ตฌ๋ ๋ด๊ธฐ/๋นผ๊ธฐ + ์ฅ๋ฐ๊ตฌ๋ ๋ชฉ๋ก ์ํ๋ฅผ ์
๋ฐ์ดํธํด์ฃผ๋ handleCartActionํจ์๋ฅผ context api๋ก ๋ด๋ ค์ฃผ๊ณ ์์ด์.
ํฌ๋ฃจ๋ ํด๋น ๊ธฐ๋ฅ์ ์ด๋ป๊ฒ ๊ตฌํํ์
จ๋์? |
@@ -1,11 +1,32 @@
-import { useState } from "react";
+import '@styles/App.css';
+import '@styles/reset.css';
+import '@styles/global.css';
+import { Header, Layout, PageRequestError } from '@components/index';
+import { lazy, Suspense } from 'react';
+import { ErrorBoundary } from 'react-error-boundary';
+
+import { CartItemsContext } from './contexts';
+import { useCartItemIds } from './hooks';
+import ProductListPageSkeleton from './pages/ProductListPage/Skeleton/ProductListPageSkeleton/index.';
+
+const ProductListPage = lazy(() => import('@pages/ProductListPage'));
function App() {
- const [count, setCount] = useState(0);
+ const { cartItemIds, refreshCartItemIds, error: cartItemsFetchError } = useCartItemIds();
+ const cartItemsLength = cartItemIds ? Array.from(cartItemIds).length : 0;
return (
<>
- <h1>React Shopping Products</h1>
+ <Header cartItemsLength={cartItemsLength} cartItemsFetchError={cartItemsFetchError} />
+ <Layout>
+ <ErrorBoundary FallbackComponent={({ error }) => <PageRequestError error={error} />}>
+ <CartItemsContext.Provider value={{ cartItemIds, refreshCartItemIds }}>
+ <Suspense fallback={<ProductListPageSkeleton />}>
+ <ProductListPage />
+ </Suspense>
+ </CartItemsContext.Provider>
+ </ErrorBoundary>
+ </Layout>
</>
);
} | Unknown | ์ ํฌ๋ ์ฅ๋ฐ๊ตฌ๋ api์ธ cart-tiems์ ๋ฐ์ดํฐ๋ context๋ก ๊ด๋ฆฌํ๊ณ ์์ต๋๋ค! |
@@ -0,0 +1,39 @@
+import { Filtering, Product, ApiResponse } from '@appTypes/index';
+import { LOAD_MORE_PRODUCTS_AMOUNT } from '@constants/index';
+import { fetchWithToken } from '@utils/index';
+
+import { END_POINTS } from './endPoints';
+
+interface FetchProductParameter {
+ filtering: Filtering;
+ page?: number;
+}
+
+const getSearchParams = ({ filtering, page }: FetchProductParameter): URLSearchParams => {
+ const searchParams = new URLSearchParams();
+
+ if (filtering.category !== '') {
+ searchParams.append('category', filtering.category);
+ }
+
+ searchParams.append('sort', filtering.sort);
+ searchParams.append('page', String(page));
+
+ if (page !== 0) {
+ searchParams.append('size', LOAD_MORE_PRODUCTS_AMOUNT.toString());
+ }
+
+ return searchParams;
+};
+
+export async function fetchProduct(params: FetchProductParameter): Promise<{ products: Product[]; isLast: boolean }> {
+ const searchParams = '?' + getSearchParams({ ...params, page: params.page ?? 0 }).toString();
+
+ const data = await fetchWithToken({
+ url: END_POINTS.products + searchParams,
+ method: 'GET',
+ });
+ const result = (await data.json()) as ApiResponse<Product[]>;
+
+ return { products: result.content, isLast: result.last };
+} | TypeScript | page์ ํ์
์ด number์ฌ์ string์ผ๋ก ๋ง๋ค์ด ์ฃผ์ ๊ฒ ๊ฐ์๋ฐ, ์ ๊ฐ ์๊ธฐ๋ก๋ ๊ทธ๋ฅ ์ซ์๋ฅผ ๋ฃ์ด๋ ๋๋ค๊ณ ์๊ณ ์์ต๋๋ค..! ํน์ string์ผ๋ก ๋ณํํ์ฌ ๋ฃ์ ๊ฒ์ ๋ํด ์๋ฏธ๊ฐ ์๋ ๊ฑธ ๊น์??
(๊ทผ๋ฐ ํ์คํ์ง ์์์ง.. ํ๋ฆฌ๋จผ ์ค๋ฃจ ํด์ฃผ์ญ์ผ..)
https://developer.mozilla.org/ko/docs/Web/API/URLSearchParams/get |
@@ -0,0 +1,15 @@
+export type Category = '' | 'fashion' | 'beverage' | 'electronics' | 'kitchen' | 'fitness' | 'books';
+export type PriceSort = 'price,asc' | 'price,desc';
+
+export interface Product {
+ id: number;
+ name: string;
+ price: number;
+ imageUrl: string;
+ category: Category;
+}
+
+export interface Filtering {
+ category: Category;
+ sort: PriceSort;
+} | TypeScript | ๋น ๋ฌธ์์ด์ด **์ ์ฒด** ๋๋ฌธ์ ์๋ ๊ฒ์ผ๋ก ๋ณด์ด๋๋ฐ,
Category๋ฅผ ์ฌ์ฉํ๋ ๊ณณ์์ `Category | undefined`์ ๊ฐ์ ํํ๊ฐ ์๋ ๋น ๋ฌธ์์ด๋ก ๋ฃ์ด์ค ์ด์ ๊ฐ ์์๊น์?? |
@@ -0,0 +1,32 @@
+/**
+ * ์๋ฒ ์๋ต์ ๊ณตํต ๊ตฌ์กฐ๋ฅผ ์ ์ํ๋ ์ธํฐํ์ด์ค
+ * @template T - response์ contentํ์
+ */
+export interface ApiResponse<T> {
+ totalPages: number;
+ totalElements: number;
+ sort: {
+ sorted: boolean;
+ unsorted: boolean;
+ empty: boolean;
+ };
+ first: boolean;
+ last: boolean;
+ pageable: {
+ sort: {
+ sorted: boolean;
+ unsorted: boolean;
+ empty: boolean;
+ };
+ pageNumber: number;
+ pageSize: number;
+ paged: boolean;
+ unpaged: boolean;
+ offset: number;
+ };
+ number: number;
+ numberOfElements: number;
+ size: number;
+ content: T;
+ empty: boolean;
+} | TypeScript | ์ค.. ์ด๋ ๊ฒ ๋ฐ๋ก ๋ถ๋ฆฌํ๋ ๊ฒ๋ ์ข๋ค์~! |
@@ -0,0 +1,30 @@
+import { DropdownOption } from '@appTypes/dropdown';
+
+import style from './style.module.css';
+
+interface DropdownProps extends Omit<React.HTMLProps<HTMLSelectElement>, 'onChange'> {
+ options: DropdownOption[];
+ onChange: (event: React.ChangeEvent<HTMLSelectElement>) => void;
+ label: string;
+}
+
+function Dropdown({ options, label, onChange, name, ...rest }: DropdownProps) {
+ const selectId = `select-${label}`;
+
+ return (
+ <>
+ <label className="scr-only" htmlFor={selectId}>
+ {label}
+ </label>
+ <select id={selectId} name={name} className={style.select} onChange={onChange} {...rest}>
+ {options.map((item) => (
+ <option key={item.value} value={item.value}>
+ {item.label}
+ </option>
+ ))}
+ </select>
+ </>
+ );
+}
+
+export default Dropdown; | Unknown | ํ๋ฃจ๊ฐ ๋๋ฌด ์ข์ ํ ๊ฒ ๊ฐ์! |
@@ -0,0 +1,15 @@
+export type Category = '' | 'fashion' | 'beverage' | 'electronics' | 'kitchen' | 'fitness' | 'books';
+export type PriceSort = 'price,asc' | 'price,desc';
+
+export interface Product {
+ id: number;
+ name: string;
+ price: number;
+ imageUrl: string;
+ category: Category;
+}
+
+export interface Filtering {
+ category: Category;
+ sort: PriceSort;
+} | TypeScript | api ์์ฒญ ๋ณด๋ด๋ ๊ฒ๊ณผ ํ์
์ ๋ง์ถ์์ด์.
์ง๊ธ๋ณด๋, ''๋ฅผ ALL์ด๋ผ๋ ์์๋ฅผ ๋ฐ๋๋ ๊ฒ์ด ์ ์ธ์ ์ผ๋ก ๋ ์ข์ ๊ฒ ๊ฐ๋ค์. |
@@ -0,0 +1,102 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
+
+์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.25
+ - 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+ - ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+ - (e.g. ์์์ผ์ธ 12์ 1์ผ์ 1,000์, 2์ผ์ 1,100์, ..., 25์ผ์ 3,400์ ํ ์ธ)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+
+```
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+```
+
+
+## ๊ธฐ๋ฅ ๋ชฉ๋ก
+- [x] ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ `getDate()`
+ - ์ซ์๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+- [x] ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ (์๋ฃ๋ง ์ฃผ๋ฌธ ํ ์ ์์, ์ต๋ 20๊ฐ๊น์ง ์ฃผ๋ฌธ) `getOrder()`
+ - e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1
+- [x] ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printMenu(List<String> menus)`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `calculateTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 120,000์ ์ด์์ ์ดํ์ธ์ ์ฆ์ ํ๋ ๊ธฐ๋ฅ `calculateGiftMenu(int totalOrderAmount, int totalDiscount)`
+ - 120,000์ ๋ฏธ๋ง์ "์์" ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค ๋ง์ค ๋๋ฐ์ด ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `ddayDiscount(int date)`
+ - 1์ผ ~ 25์ผ ํฌ๋ฆฌ์ค๋ง์ค์ ๋ค๊ฐ์ฌ์๋ก 1,000์ ์์ 100์์ฉ ์ฆ๊ฐ
+- [x] ํ์ผ ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (์ฃผ๋ง ์ ์ธ) `weekDayDiscount(int date, List<String> menus)`
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ์ฃผ๋ง ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (1,2,8,9,15,16,22,23,29,30) `weekendDayDiscount(int date, List<String> menus)`
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ํน๋ณ ํ ์ธ์ด ๊ฐ๋ฅํ ๋ ์ธ์ง ํ์ธ ํ๋ ๊ธฐ๋ฅ (3,10,17,24,25,31) `starDayDiscount(int date)`
+ - 1,000์ ํ ์ธ
+- [x] ํํ ๋ด์ญ์ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printDiscountAmount(int date, List<String> menus, int totalOrderAmount)`
+ - ๋ฐ์ ํํ์ด ์๋ค๋ฉด "์์" ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ์ดํ์ธ์ ๊ฐ๊ฒฉ) `calculateTotalDiscount(int date)`
+ - ํํ ๊ธ์ก์ด ์์ ์ "0์" ์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ(ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก - ํ ์ธ ๊ธ์ก) `calculatePayment(int totalOrderAmount, int totalDiscount)`
+- [x] ์ด ํํ ๊ธ์ก์ ๋ฐ๋ผ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `calculateBadge(int totalBenefits)`
+ - 5์ฒ ์ ๋ฏธ๋ง: ์์
+ - 5์ฒ ์ ์ด์: ๋ณ
+ - 1๋ง ์ ์ด์: ํธ๋ฆฌ
+ - 2๋ง ์ ์ด์: ์ฐํ
+
+
+## ํ์ผ ๋ชฉ๋ก
+#### `EventPlanner.java` : ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์คํํ๋ ํด๋์ค
+#### `EventProcessor.java` : ์ด๋ฒคํธ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `NoEventProcessor.java` : ์ด๋ฒคํธ๊ฐ ์์ ๋ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `Badge.java` : ์ด๋ฒคํธ ๋ฐฐ์ง ์ด๊ฑฐํ ํด๋์ค
+#### `DateDiscount.java` : ๋ ์ง์ ๋ฐ๋ฅธ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `Menu.java` : ์์ ๋ฉ๋ด ์ด๊ฑฐํ ํด๋์ค
+#### `Order.java` : ์ฃผ๋ฌธ์ ๋ํ๋ด๋ ํด๋์ค
+#### `OrderItem.java` : ์ฃผ๋ฌธ ํญ๋ชฉ์ ๋ํ๋ด๋ ํด๋์ค
+#### `StarDiscount.java` : ๋ณ์ด ํ์๋ ๋ ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `TotalDiscountCalculator.java` : ์ด ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `WeekendWeekdayDiscount.java` : ์ฃผ๋ง๊ณผ ํ์ผ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `ErrorMessage.java` : ์ค๋ฅ ๋ฉ์์ง ์ด๊ฑฐํ ํด๋์ค
+#### `OrderValidator.java` : ์ฃผ๋ฌธ์ ์ ํจ์ฑ์ ๊ฒ์ฆํ๋ ํด๋์ค
+#### `DiscountOutputPrinter.java` : ํ ์ธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `InputView.java` : ์ฌ์ฉ์ ์
๋ ฅ์ ๋ฐ๋ ํด๋์ค
+#### `OrderOutputPrinter.java` : ์ฃผ๋ฌธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `OutputView.java` : ์ถ๋ ฅ ๊ด๋ จ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํด๋์ค
+#### `Application.java` : ํ๋ก๊ทธ๋จ์ ์์์ ์ด ๋๋ ํด๋์ค
+
+
+## ํ๋ก๊ทธ๋จ ์ฌ์ฉ๋ฒ
+1. Application ํด๋์ค๋ฅผ ์คํํ์ฌ ํ๋ก๊ทธ๋จ์ ์์ํฉ๋๋ค.
+2. ํ๋ก๊ทธ๋จ์ ์ฌ์ฉ์์๊ฒ ๋ฐฉ๋ฌธ ๋ ์ง์ ์ฃผ๋ฌธ์ ์
๋ ฅํ๋๋ก ์๋ดํฉ๋๋ค.
+3. ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ซ์๋ก ์
๋ ฅํ๋ฉฐ, ์ ํจํ ๋ ์ง์ฌ์ผ ํฉ๋๋ค (1 ~ 31).
+4. ์ฃผ๋ฌธ์ ๋ฉ๋ด์ ์๋์ ์
๋ ฅํ๋ ํ์์ผ๋ก ์ด๋ฃจ์ด์ง๋๋ค (e.g., ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1).
+5. ํ๋ก๊ทธ๋จ์ ์
๋ ฅ๋ ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์ถ๋ ฅํฉ๋๋ค.
+6. ํ ์ธ ๋ด์ญ, ์ฃผ๋ฌธ ๋ฉ๋ด, ์ด ์ฃผ๋ฌธ ๊ธ์ก, ์ด ํํ ๊ธ์ก, ์์ ๊ฒฐ์ ๊ธ์ก, ์ด๋ฒคํธ ๋ฐฐ์ง ๋ฑ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
+
+
+## ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ
+- ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+- ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000 ์ด์๋ถํฐ ์ด๋ฒคํธ ์ ์ฉ
+- ์๋ฃ๋ง ์ฃผ๋ฌธ์, ์ฃผ๋ฌธํ ์ ์๋ค.
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธ ํ ์ ์๋ค.
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ : 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ (2023.12.1 ~ 2023.12.31)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000)
+- ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+- ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ถ์ฌ (๋ณ, ํธ๋ฆฌ, ์ฐํ) | Unknown | ๊ธฐ๋ฅ ๋ช
์ธ ๊ผผ๊ผผํ๊ฒ ์์ฑํด์ฃผ์
จ๋ค์ ๐๐๐ |
@@ -0,0 +1,32 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.view.OrderOutputPrinter;
+import christmas.view.OutputView;
+
+public class EventPlanner {
+ private static final int MIN_TOTAL_ORDER_AMOUNT_FOR_EVENTS = 10000;
+
+ public static void planEvent(Order order, int date) {
+ int totalOrderAmount = order.calculateTotalOrderAmount();
+
+ printOrderDetails(order, totalOrderAmount);
+
+ processEventBasedOnTotalAmount(order, date, totalOrderAmount);
+ }
+
+ private static void printOrderDetails(Order order, int totalOrderAmount) {
+ OrderOutputPrinter.printMenu(order.getMenus());
+ OutputView.printTotalOrderAmount(totalOrderAmount);
+ }
+
+ private static void processEventBasedOnTotalAmount(Order order, int date, int totalOrderAmount) {
+ if (totalOrderAmount >= MIN_TOTAL_ORDER_AMOUNT_FOR_EVENTS) {
+ EventProcessor.processEvent(order, date, totalOrderAmount);
+ }
+
+ if (totalOrderAmount < MIN_TOTAL_ORDER_AMOUNT_FOR_EVENTS) {
+ NoEventProcessor.processNoEvent(order, date, totalOrderAmount);
+ }
+ }
+} | Java | ํด๋น ๋ฉ์๋ ๋ฐ EventProcessor๋ค์ controller๊ฐ ์๋ ๋น์ฆ๋์ค ๋ก์ง์ ์์ด์ผ ํ ๊ฒ ๊ฐ์ต๋๋ค.
controller์ ์ญํ ์ view์ ๊ฐ์ model์๊ฒ ๊ฑด๋ค์ฃผ๊ฑฐ๋, model์ ๊ฐ์ view์๊ฒ ๊ฑด๋ค์ฃผ๋ ์ญํ ๋ก ์ถฉ๋ถํฉ๋๋ค. |
@@ -0,0 +1,43 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.OrderItem;
+import christmas.model.TotalDiscountCalculator;
+import christmas.view.DiscountOutputPrinter;
+import christmas.view.OrderOutputPrinter;
+import christmas.view.OutputView;
+import java.util.Set;
+
+public class EventProcessor {
+ public static void processEvent(Order order, int date, int totalOrderAmount) {
+ int totalDiscount = calculateTotalDiscount(order, date);
+ int totalBenefits = TotalDiscountCalculator.calculateGiftMenu(totalOrderAmount, totalDiscount);
+ int totalPayment = TotalDiscountCalculator.calculatePayment(totalOrderAmount, totalDiscount);
+ String giftMenu = OrderOutputPrinter.printGiftMenuMessage(totalOrderAmount);
+
+ OutputView.printGiftMenuPhrase(giftMenu);
+ printDiscountAmount(date, order.getMenus(), totalOrderAmount);
+ printBenefits(totalBenefits);
+ printPayment(totalPayment);
+
+ String badge = TotalDiscountCalculator.calculateBadge(totalOrderAmount, totalDiscount);
+ OutputView.printBadge(badge);
+ }
+
+ public static int calculateTotalDiscount(Order order, int date) {
+ return order.calculateTotalDiscount(date);
+ }
+
+ public static void printDiscountAmount(int date, Set<OrderItem> menus, int totalOrderAmount) {
+ DiscountOutputPrinter.printDiscountAmount(date, menus, totalOrderAmount);
+ }
+
+ public static void printBenefits(int totalBenefits) {
+ DiscountOutputPrinter.printBenefits(totalBenefits);
+ }
+
+ public static void printPayment(int totalPayment) {
+ OutputView.printPayment(totalPayment);
+ }
+
+} | Java | ํด๋น ๋ฉ์๋๋ค ์ ๋ง ๋ถ๋ฆฌํ ํ์๊ฐ ์์์๊น์? |
@@ -0,0 +1,19 @@
+package christmas.controller;
+
+import christmas.model.Badge;
+import christmas.model.Order;
+import christmas.view.OutputView;
+
+public class NoEventProcessor {
+ public static void processNoEvent(Order order, int date, int totalOrderAmount) {
+ int totalDiscount = 0;
+ int totalBenefits = 0;
+ int totalPayment = totalOrderAmount - totalDiscount;
+
+ EventProcessor.printDiscountAmount(date, order.getMenus(), totalDiscount);
+ EventProcessor.printBenefits(totalBenefits);
+ EventProcessor.printPayment(totalPayment);
+
+ OutputView.printBadge(Badge.NONE.getName());
+ }
+} | Java | ํด๋น ๊ฐ ์ญ์ model์ ์ํด ๊ฒฐ์ ๋์ด์ผํฉ๋๋ค.
๊ทธ๋ ๊ฒ ๋ฐ๊พผ๋ค๋ฉด Processor ๊ฐ์ฒด๋ค์ด ํ์๊ฐ ์์ด์ง๊ฒ ๋ค์ |
@@ -0,0 +1,53 @@
+package christmas.model;
+
+import java.util.Arrays;
+
+public enum Menu {
+ ์์ก์ด์ํ(6_000),
+ ํํ์ค(5_500),
+ ์์ ์๋ฌ๋(8_000),
+ ํฐ๋ณธ์คํ
์ดํฌ(55_000),
+ ๋ฐ๋นํ๋ฆฝ(54_000),
+ ํด์ฐ๋ฌผํ์คํ(35_000),
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25_000),
+ ์ด์ฝ์ผ์ดํฌ(15_000),
+ ์์ด์คํฌ๋ฆผ(5_000),
+ ์ ๋ก์ฝ๋ผ(3_000),
+ ๋ ๋์์ธ(60_000),
+ ์ดํ์ธ(25_000);
+
+ private final int price;
+
+ Menu(int price) {
+ this.price = price;
+ }
+
+ public static int getChampagnePrice() {
+ return ์ดํ์ธ.getPrice();
+ }
+
+ public static int getPriceByMenuName(String menuName) {
+ return Menu.valueOf(menuName).getPrice();
+ }
+
+ public static boolean containsMenu(String menuName) {
+ return Arrays.stream(values()).anyMatch(menu -> menu.name().equals(menuName));
+ }
+
+ public int getPrice() {
+ return price;
+ }
+
+ public boolean containsBeverageMenu(String menuName) {
+ return Arrays.asList(์ ๋ก์ฝ๋ผ.name(), ๋ ๋์์ธ.name(), ์ดํ์ธ.name()).contains(menuName);
+ }
+
+ public boolean containsMainMenu(String menuName) {
+ return Arrays.asList(ํฐ๋ณธ์คํ
์ดํฌ.name(), ๋ฐ๋นํ๋ฆฝ.name(), ํด์ฐ๋ฌผํ์คํ.name(), ํฌ๋ฆฌ์ค๋ง์คํ์คํ.name()).contains(menuName);
+ }
+
+ public boolean containsDessertMenu(String menuName) {
+ return Arrays.asList(์ด์ฝ์ผ์ดํฌ.name(), ์์ด์คํฌ๋ฆผ.name()).contains(menuName);
+ }
+
+} | Java | [๊ฐ์ฒด์งํฅ์ํ์ฒด์กฐ ์์น4. ํ ์ค์ ์ ์ ํ๋๋ง ์ฐ๋๋ค.](https://hudi.blog/thoughtworks-anthology-object-calisthenics/)์ ๋ํด ์์๋ณผ๊น์? |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | MVC ํจํด์ ๋น์ฆ๋์ค ๋ก์ง(model)๊ณผ ๋ทฐ ๋ก์ง์ ๋ถ๋ฆฌํ๊ธฐ ์ํด ์ฌ์ฉ๋ฉ๋๋ค.
model ๋ด๋ถ์์ view๊ฐ ์ฌ์ฉ๋๋ค๋ฉด mvc ํจํด์ ์๋ชป ์ฌ์ฉํ๊ณ ์๋ค๋ ์ ํธ์
๋๋ค |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | ๋งค์ง๋๋ฒ ์์ํ ๐๐๐ |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | `"-"` ํด๋น ๊ฐ๋ ์์ํ ํด์ฃผ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,23 @@
+package christmas.model;
+
+public class OrderItem {
+ private final String menuName;
+ private final int quantity;
+
+ public OrderItem(String menuName, int quantity) {
+ this.menuName = menuName;
+ this.quantity = quantity;
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public int calculateMenuAmount() {
+ return quantity * Menu.getPriceByMenuName(menuName);
+ }
+} | Java | ๋ณดํต getter ๋ฉ์๋๋ ์๋ฐ ์ปจ๋ฒค์
์ ๊ฐ์ฅ ์๋์ชฝ์ ์์นํฉ๋๋ค |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | Discount ๊ด๋ จ ๊ฐ์ฒด๋ค์ด ๋ชจ๋ ์ ํธ์ฑ ํด๋์ค๋ค์.
์ง๋์น๊ฒ ๋จ์ฉ๋๋ค๋ ์๊ฐ์ด ๋ญ๋๋ค.
์ด๋ค ๋ฐฉ๋ฒ์ ์ฐ๋ฉด static ๋ฉ์๋ ์์ด ์ข ๋ ๊ฐ์ฒด์งํฅ์ ์ผ๋ก ์์ฑ์ด ๊ฐ๋ฅํ ๊น์? |
@@ -0,0 +1,139 @@
+package christmas.validator;
+
+import christmas.model.Menu;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.function.Predicate;
+
+public class OrderValidator {
+
+ private static final int MAX_MENU_COUNT = 20;
+ private static final String MENU_REGEX = "^[๊ฐ-ํฃ]+-[1-9]\\d*$";
+ private static final String ENGLISH_REGEX = ".*[a-zA-Z]+.*";
+
+ public static String validateAndGetOrder(String order) {
+ validateOrder(order);
+ return order;
+ }
+
+ private static void validateOrder(String order) {
+ validateOrderCommaFormat(order);
+ validateInvalidMenuInOrder(order);
+ validateOrderFormat(order);
+ validateNoEnglishCharacters(order);
+ validateNoBeverageOnlyOrder(order);
+ validateMenusExist(order);
+ }
+
+ private static void validateNoBeverageOnlyOrder(String order) {
+ if (containsBeverageOnly(order)) {
+ throw new IllegalArgumentException(ErrorMessage.BEVERAGE_ONLY_ORDER.getMessage());
+ }
+ }
+
+ private static void validateInvalidMenuInOrder(String order) {
+ if (isInvalidMenuInOrder(order)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static boolean isInvalidMenuInOrder(String order) {
+ return allMatch(order, menuInfo -> {
+ String menuName = menuInfo.split("-")[0].trim();
+ return !Menu.containsMenu(menuName);
+ });
+ }
+
+ private static boolean containsBeverageOnly(String order) {
+ return allMatch(order, menuInfo -> isBeverageMenu(menuInfo.split("-")[0].trim()));
+ }
+
+ private static boolean isBeverageMenu(String menuName) {
+ return Menu.valueOf(menuName).containsBeverageMenu(menuName);
+ }
+
+ private static void validateOrderFormat(String order) {
+ if (!allMatch(order, OrderValidator::isValidMenuEntryFormat)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static void validateOrderCommaFormat(String order) {
+ if (order.startsWith(",") || order.endsWith(",")) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static boolean allMatch(String order, Predicate<String> predicate) {
+ return Arrays.stream(order.split(",")).allMatch(predicate);
+ }
+
+ private static boolean isValidMenuEntryFormat(String menuEntry) {
+ return menuEntry.matches(MENU_REGEX);
+ }
+
+ private static void validateNoEnglishCharacters(String order) {
+ if (containsEnglish(order)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+
+ private static boolean containsEnglish(String order) {
+ return order.matches(ENGLISH_REGEX);
+ }
+
+ private static void validateMenusExist(String order) {
+ Set<String> uniqueMenus = checkForDuplicateMenus(order);
+ validateTotalMenuCount(order, uniqueMenus.size());
+ }
+
+ private static Set<String> checkForDuplicateMenus(String order) {
+ Set<String> uniqueMenus = new HashSet<>();
+
+ allMatch(order, menuInfo -> {
+ String menuName = menuInfo.split("-")[0].trim();
+ if (!uniqueMenus.add(menuName)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ return true;
+ });
+
+ return uniqueMenus;
+ }
+
+ private static void validateTotalMenuCount(String order, int uniqueMenuCount) {
+ int totalMenuCount = Arrays.stream(order.split(","))
+ .mapToInt(OrderValidator::validateAndGetQuantity)
+ .sum();
+
+ if (totalMenuCount > MAX_MENU_COUNT || uniqueMenuCount > MAX_MENU_COUNT) {
+ throw new IllegalArgumentException(ErrorMessage.MAX_MENU_EXCEEDED.getMessage());
+ }
+ }
+
+ private static int validateAndGetQuantity(String menuInfo) {
+ String[] menuDetails = menuInfo.split("-");
+ validateMenu(menuDetails);
+ return Integer.parseInt(menuDetails[1].trim());
+ }
+
+ private static void validateMenu(String[] menuDetails) {
+ String menuName = menuDetails[0].trim();
+ if (!isValidMenu(menuName)) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ validateQuantity(menuDetails[1].trim());
+ }
+
+ private static boolean isValidMenu(String menuName) {
+ return Arrays.stream(Menu.values()).anyMatch(menu -> menu.name().equals(menuName));
+ }
+
+ private static void validateQuantity(String quantityStr) {
+ int quantity = Integer.parseInt(quantityStr);
+ if (quantity < 1) {
+ throw new IllegalArgumentException(ErrorMessage.INVALID_ORDER.getMessage());
+ }
+ }
+} | Java | Validator๋ค ์์ View์ ์์ด์ผํ ๋ก์ง๋ค๊ณผ model์ ์์ด์ผํ ๋ก์ง๋ค์ด ํผ์ฌ๋์ด ์๋ค์.
View์์ ์ฌ์ฉํ Validator์ model์ ์ฌ์ฉํ Validator๋ก ๋ถ๋ฆฌํ๊ณ
๊ฐ๊ฐ์ ํจํค์ง์ ์์น์์ผ๋ณผ๊น์? |
@@ -0,0 +1,28 @@
+package christmas.view;
+
+import christmas.model.OrderItem;
+import java.util.Set;
+
+public class OrderOutputPrinter {
+ private static final String GIFT_MENU_MESSAGE = "์ดํ์ธ 1๊ฐ";
+ private static final String NONE_BENEFIT_MESSAGE = "์์";
+
+ public static void printMenu(Set<OrderItem> menus) {
+ OutputView.printMessage("<์ฃผ๋ฌธ ๋ฉ๋ด>");
+ menus.forEach(OrderOutputPrinter::printMenuItem);
+ OutputView.printEmptyLine();
+ }
+
+ private static void printMenuItem(OrderItem orderItem) {
+ String menuName = orderItem.getMenuName();
+ int quantity = orderItem.getQuantity();
+ OutputView.printMessage(menuName + " " + quantity + "๊ฐ");
+ }
+
+ public static String printGiftMenuMessage(int totalOrderAmount) {
+ if (totalOrderAmount >= 120000) {
+ return GIFT_MENU_MESSAGE;
+ }
+ return NONE_BENEFIT_MESSAGE;
+ }
+} | Java | ์ฃผ๋ฌธ๊ธ์ก์ด 120000์ ๋์ผ๋ฉด ์ดํ์ธ์ ์ฆ์ ํ๋ค๋ ๋น์ฆ๋์ค ๋ก์ง ์๋๊น์? |
@@ -0,0 +1,102 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
+
+์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.25
+ - 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ
+ - ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+ - (e.g. ์์์ผ์ธ 12์ 1์ผ์ 1,000์, 2์ผ์ 1,100์, ..., 25์ผ์ 3,400์ ํ ์ธ)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+
+```
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+```
+
+
+## ๊ธฐ๋ฅ ๋ชฉ๋ก
+- [x] ๋ฐฉ๋ฌธ ๋ ์ง๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ `getDate()`
+ - ์ซ์๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+- [x] ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๊ธฐ๋ฅ (์๋ฃ๋ง ์ฃผ๋ฌธ ํ ์ ์์, ์ต๋ 20๊ฐ๊น์ง ์ฃผ๋ฌธ) `getOrder()`
+ - e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1
+- [x] ์ฃผ๋ฌธ ๋ฉ๋ด๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printMenu(List<String> menus)`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `calculateTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printTotalOrderAmount()`
+- [x] ํ ์ธ ์ ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 120,000์ ์ด์์ ์ดํ์ธ์ ์ฆ์ ํ๋ ๊ธฐ๋ฅ `calculateGiftMenu(int totalOrderAmount, int totalDiscount)`
+ - 120,000์ ๋ฏธ๋ง์ "์์" ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค ๋ง์ค ๋๋ฐ์ด ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ `ddayDiscount(int date)`
+ - 1์ผ ~ 25์ผ ํฌ๋ฆฌ์ค๋ง์ค์ ๋ค๊ฐ์ฌ์๋ก 1,000์ ์์ 100์์ฉ ์ฆ๊ฐ
+- [x] ํ์ผ ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (์ฃผ๋ง ์ ์ธ) `weekDayDiscount(int date, List<String> menus)`
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ์ฃผ๋ง ํ ์ธ์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (1,2,8,9,15,16,22,23,29,30) `weekendDayDiscount(int date, List<String> menus)`
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- [x] ํน๋ณ ํ ์ธ์ด ๊ฐ๋ฅํ ๋ ์ธ์ง ํ์ธ ํ๋ ๊ธฐ๋ฅ (3,10,17,24,25,31) `starDayDiscount(int date)`
+ - 1,000์ ํ ์ธ
+- [x] ํํ ๋ด์ญ์ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `printDiscountAmount(int date, List<String> menus, int totalOrderAmount)`
+ - ๋ฐ์ ํํ์ด ์๋ค๋ฉด "์์" ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก์ ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ (ํ ์ธ ๊ธ์ก์ ํฉ๊ณ + ์ฆ์ ์ดํ์ธ์ ๊ฐ๊ฒฉ) `calculateTotalDiscount(int date)`
+ - ํํ ๊ธ์ก์ด ์์ ์ "0์" ์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ๊ณ์ฐ ํ๋ ๊ธฐ๋ฅ(ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก - ํ ์ธ ๊ธ์ก) `calculatePayment(int totalOrderAmount, int totalDiscount)`
+- [x] ์ด ํํ ๊ธ์ก์ ๋ฐ๋ผ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅ ํ๋ ๊ธฐ๋ฅ `calculateBadge(int totalBenefits)`
+ - 5์ฒ ์ ๋ฏธ๋ง: ์์
+ - 5์ฒ ์ ์ด์: ๋ณ
+ - 1๋ง ์ ์ด์: ํธ๋ฆฌ
+ - 2๋ง ์ ์ด์: ์ฐํ
+
+
+## ํ์ผ ๋ชฉ๋ก
+#### `EventPlanner.java` : ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์คํํ๋ ํด๋์ค
+#### `EventProcessor.java` : ์ด๋ฒคํธ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `NoEventProcessor.java` : ์ด๋ฒคํธ๊ฐ ์์ ๋ ์ฒ๋ฆฌ๋ฅผ ๋ด๋นํ๋ ํด๋์ค
+#### `Badge.java` : ์ด๋ฒคํธ ๋ฐฐ์ง ์ด๊ฑฐํ ํด๋์ค
+#### `DateDiscount.java` : ๋ ์ง์ ๋ฐ๋ฅธ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `Menu.java` : ์์ ๋ฉ๋ด ์ด๊ฑฐํ ํด๋์ค
+#### `Order.java` : ์ฃผ๋ฌธ์ ๋ํ๋ด๋ ํด๋์ค
+#### `OrderItem.java` : ์ฃผ๋ฌธ ํญ๋ชฉ์ ๋ํ๋ด๋ ํด๋์ค
+#### `StarDiscount.java` : ๋ณ์ด ํ์๋ ๋ ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `TotalDiscountCalculator.java` : ์ด ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `WeekendWeekdayDiscount.java` : ์ฃผ๋ง๊ณผ ํ์ผ์ ๋ํ ํ ์ธ์ ๊ณ์ฐํ๋ ํด๋์ค
+#### `ErrorMessage.java` : ์ค๋ฅ ๋ฉ์์ง ์ด๊ฑฐํ ํด๋์ค
+#### `OrderValidator.java` : ์ฃผ๋ฌธ์ ์ ํจ์ฑ์ ๊ฒ์ฆํ๋ ํด๋์ค
+#### `DiscountOutputPrinter.java` : ํ ์ธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `InputView.java` : ์ฌ์ฉ์ ์
๋ ฅ์ ๋ฐ๋ ํด๋์ค
+#### `OrderOutputPrinter.java` : ์ฃผ๋ฌธ ๋ด์ญ์ ์ถ๋ ฅํ๋ ํด๋์ค
+#### `OutputView.java` : ์ถ๋ ฅ ๊ด๋ จ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ ํด๋์ค
+#### `Application.java` : ํ๋ก๊ทธ๋จ์ ์์์ ์ด ๋๋ ํด๋์ค
+
+
+## ํ๋ก๊ทธ๋จ ์ฌ์ฉ๋ฒ
+1. Application ํด๋์ค๋ฅผ ์คํํ์ฌ ํ๋ก๊ทธ๋จ์ ์์ํฉ๋๋ค.
+2. ํ๋ก๊ทธ๋จ์ ์ฌ์ฉ์์๊ฒ ๋ฐฉ๋ฌธ ๋ ์ง์ ์ฃผ๋ฌธ์ ์
๋ ฅํ๋๋ก ์๋ดํฉ๋๋ค.
+3. ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ซ์๋ก ์
๋ ฅํ๋ฉฐ, ์ ํจํ ๋ ์ง์ฌ์ผ ํฉ๋๋ค (1 ~ 31).
+4. ์ฃผ๋ฌธ์ ๋ฉ๋ด์ ์๋์ ์
๋ ฅํ๋ ํ์์ผ๋ก ์ด๋ฃจ์ด์ง๋๋ค (e.g., ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1).
+5. ํ๋ก๊ทธ๋จ์ ์
๋ ฅ๋ ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ด๋ฒคํธ๋ฅผ ๊ณํํ๊ณ ์ถ๋ ฅํฉ๋๋ค.
+6. ํ ์ธ ๋ด์ญ, ์ฃผ๋ฌธ ๋ฉ๋ด, ์ด ์ฃผ๋ฌธ ๊ธ์ก, ์ด ํํ ๊ธ์ก, ์์ ๊ฒฐ์ ๊ธ์ก, ์ด๋ฒคํธ ๋ฐฐ์ง ๋ฑ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
+
+
+## ๊ธฐ๋ฅ ์๊ตฌ์ฌํญ
+- ์ด๋ฒคํธ ๊ธฐ๊ฐ: 2023.12.1 ~ 2023.12.31
+- ์ด์ฃผ๋ฌธ ๊ธ์ก 10,000 ์ด์๋ถํฐ ์ด๋ฒคํธ ์ ์ฉ
+- ์๋ฃ๋ง ์ฃผ๋ฌธ์, ์ฃผ๋ฌธํ ์ ์๋ค.
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ๊น์ง๋ง ์ฃผ๋ฌธ ํ ์ ์๋ค.
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ : 1,000์์ผ๋ก ์์ํ์ฌ ํฌ๋ฆฌ์ค๋ง์ค๊ฐ ๋ค๊ฐ์ฌ์๋ก ๋ ๋ง๋ค ํ ์ธ ๊ธ์ก์ด 100์์ฉ ์ฆ๊ฐ (2023.12.1 ~ 2023.12.31)
+- ํ์ผ ํ ์ธ(์ผ์์ผ~๋ชฉ์์ผ): ํ์ผ์๋ ๋์ ํธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ(๊ธ์์ผ, ํ ์์ผ): ์ฃผ๋ง์๋ ๋ฉ์ธ ๋ฉ๋ด๋ฅผ ๋ฉ๋ด 1๊ฐ๋น 2,023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ: ์ด๋ฒคํธ ๋ฌ๋ ฅ์ ๋ณ์ด ์์ผ๋ฉด ์ด์ฃผ๋ฌธ ๊ธ์ก์์ 1,000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ: ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง ์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์ (25,000)
+- ์ด์ฃผ๋ฌธ ๊ธ์ก์์ ํด๋น ๊ธ์ก๋งํผ ํ ์ธ
+- ์ดํํ ๊ธ์ก์ ๋ฐ๋ผ ๋ค๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง๋ฅผ ๋ถ์ฌ (๋ณ, ํธ๋ฆฌ, ์ฐํ) | Unknown | ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,23 @@
+package christmas.model;
+
+public class OrderItem {
+ private final String menuName;
+ private final int quantity;
+
+ public OrderItem(String menuName, int quantity) {
+ this.menuName = menuName;
+ this.quantity = quantity;
+ }
+
+ public String getMenuName() {
+ return menuName;
+ }
+
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public int calculateMenuAmount() {
+ return quantity * Menu.getPriceByMenuName(menuName);
+ }
+} | Java | ํ์ธํ๋ค๊ณ ํ๋๋ฐ ๋์น ๋ถ๋ถ์ด ์์๋ค์ ใ
ใ
์์ ํ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | ์ ์ ์์ํ ๊ณต๋ถ์ค ๋ธ๋ก๊ทธ ๊ธ์์ ","(comma)๋ฅผ ์์ํ ํ๋๊ฒ ์๋ฏธ์๋ ์์ํ๋ผ๋ ๊ธ์ ๋ณธ ์ ์ด ์์ต๋๋ค.
"-" ํด๋น ๊ฐ๋ ์์ํ ํด์ฃผ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ๋ค๊ณ ๋ง์ํด ์ฃผ์
จ๋๋ฐ ํน์ ","(comma)์ ๋ค๋ฅธ ์ด์ ๊ฐ ์๋์ง ์ฌ์ญค๋ณด๊ณ ์ถ์ต๋๋ค. |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | TotalDiscountCalculator ํด๋์ค๋ฅผ ๊ฐ์ฒด๋ก ๋ณ๊ฒฝํ๊ณ ํ์ํ Discount ๊ณ์ฐ ๋ก์ง์ ์ฌ๋ฌ ์ธ์คํด์ค ๋ฉ์๋๋ก ๋ถํ ํ๋ค๋ฉด static ๋ฉ์๋ ์์ด ์ข ๋ ๊ฐ์ฒด์งํฅ์ ์ผ๋ก ๋ณ๊ฒฝํ ์ ์์๊ฒ ๊ฐ์๋ฐ ์ ๊ฐ ์๊ฐํ ๋ฐฉ๋ฒ์ด ๋ง์์ง ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | ์ ๊ฐ ์ฝ๋๋ฅผ ์๋ชป ์์ฑํ๋ค์..
๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,57 @@
+package christmas.model;
+
+import christmas.view.OutputView;
+import java.util.HashSet;
+import java.util.Set;
+
+public class Order {
+ private static final int MENU_NAME_INDEX = 0;
+ private static final int QUANTITY_INDEX = 1;
+
+ private final Set<OrderItem> menus;
+
+
+ private Order(Set<OrderItem> menus) {
+ this.menus = menus;
+ }
+
+ public static Order createOrder(int date, String orderInput) {
+ Set<OrderItem> menus = createOrderItems(orderInput);
+ OutputView.printOrderPreview(date);
+ return new Order(menus);
+ }
+
+ private static Set<OrderItem> createOrderItems(String orderInput) {
+ Set<OrderItem> menus = new HashSet<>();
+ String[] orderItems = orderInput.split(",");
+ for (String orderItem : orderItems) {
+ String[] menuInfo = getMenuInfo(orderItem.trim());
+ String menuName = menuInfo[MENU_NAME_INDEX];
+ int quantity = Integer.parseInt(menuInfo[QUANTITY_INDEX]);
+ menus.add(new OrderItem(menuName, quantity));
+ }
+ return menus;
+ }
+
+ private static String[] getMenuInfo(String menu) {
+ return menu.split("-");
+ }
+
+ public Set<OrderItem> getMenus() {
+ return menus;
+ }
+
+ public int calculateTotalOrderAmount() {
+ int totalOrderAmount = 0;
+ for (OrderItem orderItem : menus) {
+ totalOrderAmount += orderItem.calculateMenuAmount();
+ }
+ return totalOrderAmount;
+ }
+
+ public int calculateTotalDiscount(int date) {
+ int dateDiscount = TotalDiscountCalculator.calculateDateDiscount(date, menus);
+ int starDiscount = TotalDiscountCalculator.calculateStarDiscount(date);
+ return dateDiscount + starDiscount;
+ }
+} | Java | ์์ํ๋ฅผ ํ๋ ๋ชฉ์ ์ ๋ฌด์์ผ๊น์?
๊ฐ์ฅ ํฐ ์ด์ ๋ ํด๋น ๊ฐ์ด ์ฝ๋์ ๋งฅ๋ฝ์
`์ด๋ค ์ญํ `์ ํ๋์ง ๋ํ๋ด๊ธฐ ์ํด ์ ์ ํ ์ด๋ฆ์ ๋ถ์ด๋ ๊ฒ์
๋๋ค.
`","`๋ฅผ `comma`๋ผ๊ณ ๋ค์ด๋ฐํ๋ ๊ฒ์ ์ ์๋ฏธ ์๋ ์์ํ์ผ๊น์?
1. comma๋ผ๋ ์ด๋ฆ์ ํด๋น ๋ฌธ์ฅ ๋ถํธ์ ์ด๋ฆ์ด์ง, ์ฝ๋์์ ํด๋น ๋ฌธ์ฅ ๋ถํธ์ ์ญํ ์ ๋ํด ํํํ ์ด๋ฆ์ด ์๋๋๋ค.
2. menu๋ผ๋ String์ ํ์์ด ๋ฐ๋์ด ๋ฉ๋ด ์ด๋ฆ๊ณผ ์๋์ ๊ตฌ๋ถํ๋ ๊ตฌ๋ถ์๊ฐ `","`์์ `"-"`๋ก ๋ณํํ๋ค๋ฉด
์์์ ๋ค์ด๋ฐ๋ `comma`์์ `hyphen`์ผ๋ก ๋ณ๊ฒฝํด์ค์ผํฉ๋๋ค.
๊ตฌ๋ถ์๊ฐ ๋ฐ๋๋๋ง๋ค ์์์ ์ด๋ฆ์ ๋ฐ๊พธ๊ณ ํด๋น ์์๋ฅผ ์ฌ์ฉํ๋ ๋ชจ๋ ๊ณณ์์ ์ฝ๋๋ฅผ ๋ณ๊ฒฝํด์ผํ๋ค๋ฉด
์์ํ๋ฅผ ํ๋ ๋ชฉ์ ์ ๋ฌ์ฑํ๋ค๊ณ ๋ณด๊ธฐ ํ๋ค๊ฒ ์ฃ .
๊ทธ๋ฐ ์ด์ ์์ ","(comma)๋ฅผ ์์ํ ํ๋๊ฒ ์๋ฏธ์๋ ์์ํ๋ผ๊ณ ํํํ ๊ฒ์
๋๋ค.
์ด ์๋ฏธ๋ ๋งค์ง ๋ฆฌํฐ๋ด์ ์์ํํ์ง ๋ง๋ผ๋ ์๋ฏธ๊ฐ ์๋, ์ ์๋ฏธํ ๋ค์ด๋ฐ์ผ๋ก ์์ํํ๋ผ๋ ์๋ฏธ์
๋๋ค. |
@@ -0,0 +1,48 @@
+package christmas.model;
+
+import java.util.Set;
+
+public class TotalDiscountCalculator {
+
+ private static final int GIFT_MENU_ORDER_AMOUNT_THRESHOLD = 120000;
+ private static final int DEFAULT_DISCOUNT = 0;
+
+ public static int calculateDateDiscount(int date, Set<OrderItem> menus) {
+ int dateDiscount = DateDiscount.ddayDiscount(date);
+ int weekDayDiscount = WeekendWeekdayDiscount.weekDayDiscount(date, menus);
+ int weekendDayDiscount = WeekendWeekdayDiscount.weekendDayDiscount(date, menus);
+ return dateDiscount + weekDayDiscount + weekendDayDiscount;
+ }
+
+ public static int calculateStarDiscount(int date) {
+ return StarDiscount.starDayDiscount(date);
+ }
+
+ public static int calculateGiftMenu(int totalOrderAmount, int totalDiscount) {
+ int totalBenefits = totalDiscount;
+ if (totalOrderAmount >= GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ totalBenefits += getGiftMenuPrice();
+ }
+ return totalBenefits;
+ }
+
+ public static int printGiftMenuPrice(int totalOrderAmount) {
+ if (totalOrderAmount < GIFT_MENU_ORDER_AMOUNT_THRESHOLD) {
+ return DEFAULT_DISCOUNT;
+ }
+ return getGiftMenuPrice();
+ }
+
+ public static String calculateBadge(int totalOrderAmount, int calculateTotalDiscount) {
+ int totalBenefits = calculateGiftMenu(totalOrderAmount, calculateTotalDiscount);
+ return Badge.calculateBadge(totalBenefits);
+ }
+
+ public static int calculatePayment(int totalOrderAmount, int totalDiscount) {
+ return totalOrderAmount - totalDiscount;
+ }
+
+ private static int getGiftMenuPrice() {
+ return Menu.getChampagnePrice();
+ }
+} | Java | ๊ฐ์ฒด์งํฅ์์ ๊ฐ์ฒด๋ ๋ฌด์์ผ๊น์?
์ผ๋ฐ์ ์ผ๋ก ๊ฐ์ฒด๋ `์ํ(State)` ์ `ํ๋(Behavior)` ์ ๊ฐ์ง๋ ๊ฒ์ ๋งํฉ๋๋ค.
์ฝ๋์ ์ผ๋ก๋ ์๊ณ ์๋ ๊ฒ๋ค(์ํ)๋ฅผ ์ธ์คํด์ค ๋ณ์๋ก ๋ํ๋ด๊ณ ,
ํ ์ ์๋ ๊ฒ๋ค(ํ๋)์ ๋ฉ์๋๋ก ๋ํ๋ด๋ ๊ฒ์ ์๋ฏธํ๊ฒ ์ฃ .
์ด๋ฌํ ๊ด์ ์์ ์ ์ฒด์ ์ธ ์ค๊ณ๋ฅผ ์ฌ๊ฒํ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค ใ
ใ
|
@@ -0,0 +1,22 @@
+package christmas.constant;
+
+public enum ResultMessage {
+ BENEFIT_PREVIEW("12์ 3์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ ORDER_MENU("\n<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ ALL_ORDER_PRICE_WITHOUT_DISCOUNT("\n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIVE_MENU("\n<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT("\n<ํํ ๋ด์ญ>"),
+ ALL_BENEFIT_AMOUNT("\n<์ดํํ ๊ธ์ก>"),
+ PAYMENT_PRICE("\n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ BADGE("\n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+
+ private String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ๊ฐ์ธ์ ์ผ๋ก ๋ฌธ์์ด์ ๊ฐํ์ด ๋ค์ด๊ฐ ์์ผ๋ฉด ๋์ค์ ๋๋ฒ๊น
์ด ์ฝ์ง ์๋๊ตฐ์.. |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์ถ๋ ฅ๋ถ๋ฌธ์ด ์๋น์ค์ ๊ฒฐํฉ๋์ด ์๋๊ฒ ๋ง์ ๊ฒ ๊ฐ์๋ฐ, ์์ ์๋น์ค ์์์ ์ฒ๋ฆฌํ๋ ๊ฒ๋ ์ข์๋ณด์
๋๋ค! |
@@ -0,0 +1,55 @@
+package christmas.domain.customer;
+
+import christmas.constant.NumConstant;
+import christmas.validator.DateValidator;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+
+public class VisitDate {
+ private final int visitDate;
+
+ private VisitDate(int visitDate) {
+ DateValidator.validateVisitDateBound(visitDate);
+ this.visitDate = visitDate;
+ }
+
+ public static VisitDate from(int visitDate) {
+ return new VisitDate(visitDate);
+ }
+
+ public DayOfWeek getDayOfWeek() {
+ LocalDate date = LocalDate.of(
+ NumConstant.THIS_YEAR.getValue(),
+ NumConstant.THIS_MONTH.getValue(),
+ visitDate
+ );
+ return date.getDayOfWeek();
+ }
+
+ public boolean isVisitDateWeekend() {
+ DayOfWeek dayOfWeek = getDayOfWeek();
+ if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isOverChristmas() {
+ if(visitDate > NumConstant.CHRISTMAS_DAY.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public int calculateDdayEventApplyDay() {
+ return visitDate - 1;
+ }
+
+ public boolean isSpecialDay() {
+ if (visitDate == NumConstant.CHRISTMAS_DAY.getValue() || getDayOfWeek() == DayOfWeek.SUNDAY) {
+ return true;
+ }
+ return false;
+ }
+} | Java | ์ด๋ค ๊ฑธ ์๋ํ์
จ๋์ง ์ฌ์ญค๋ด๋ ๋ ๊น์? |
@@ -0,0 +1,68 @@
+package christmas.service;
+
+import christmas.constant.Badge;
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.event.EventStatus;
+import christmas.handler.EventHandler;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class EventService {
+ private final EventHandler eventHandler;
+ private final CustomerInfo customerInfo;
+
+ private EventService(CustomerInfo customerInfo) {
+ eventHandler = EventHandler.from(EventStatus.createInstance());
+ this.customerInfo = customerInfo;
+ }
+
+ public static EventService of(CustomerInfo customerInfo) {
+ return new EventService(customerInfo);
+ }
+
+ public void applyDiscount() {
+ eventHandler.applyDiscount(customerInfo);
+ }
+
+ public int getTotalBenefitAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalBenefitAmount();
+ }
+ return 0;
+ }
+
+ public Map<String, Integer> getBenefits() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getBenefits();
+ }
+ return Collections.emptyMap();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return customerInfo.getOrderList();
+ }
+
+ public String getGiveaway() {
+ if (customerInfo.isApplyGiveawayEvent()) {
+ return "์ดํ์ธ 1๊ฐ";
+ }
+ return "์์";
+ }
+
+ public int getTotalOrderAmount() {
+ return customerInfo.getTotalOrderAmount();
+ }
+
+ public int getTotalDiscountAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalDiscountAmount();
+ }
+ return 0;
+ }
+
+ public String getBadge() {
+ return Badge.getBadge(eventHandler.getTotalBenefitAmount());
+ }
+
+} | Java | ๋ฌธ์์ด์ ๋ฐํํ๊ธฐ๋ณด๋ค ์ฆ์ ํ์ ๋ํ ๊ฐ์ฒด๊ฐ ์์ด์ ๊ทธ ์ ๋ณด๋ฅผ ๋ฐํํ๋ ๊ฒ์ด ์ด๋จ๊น์? |
@@ -0,0 +1,31 @@
+package christmas.constant;
+
+public enum Badge {
+ MISS("์์"),
+ STAR("๋ณ"),
+ TREE("ํธ๋ฆฌ"),
+ SANTA("์ฐํ");
+ private String name;
+
+ Badge(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static String getBadge(int totalBenefitAmount) {
+ totalBenefitAmount = Math.abs(totalBenefitAmount);
+ if(totalBenefitAmount >= NumConstant.STAR_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.TREE_BADGE_AMOUNT.getValue()) {
+ return STAR.name;
+ }
+ if(totalBenefitAmount >= NumConstant.TREE_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return TREE.name;
+ }
+ if(totalBenefitAmount >= NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return SANTA.name;
+ }
+ return MISS.name;
+ }
+} | Java | ์ ๋ ๋๊ฐ์ด ๋ฐ์๋ ํผ๋๋ฐฑ์ธ๋ฐ,
```
SANTA("์ฐํ, 25_000");
public static String getBadge(final int totalBenefitAmount) {
for(Badge b : Badge.values()){
if(totalBenefitAmount>=b.getValue()){
return b.name;
}
}
return "์์";
}
```
๋ก ๊ณ ์ณ๋ณด๋ฉด ์ด๋จ๊น์?
๋ ๊ฐ๋จํด ์ง ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์! ์ธ์คํด์ค ํ๋๋ฅผ ์ ์ ํ๊ฒ ์ ์ค์ธ๊ฒ ๊ฐ์์ ์์ฒญ ์ข๋ค์!! |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์ด ๋ถ๋ถ์
- ์
๋ ฅ๊ฐ์ ๋ฐ์์จ๋ค
- ์๋น์ค ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค
๋ผ๋ ๋ก์ง์ ๋์์ ์ฒ๋ฆฌํ๊ณ ์์ด ๋ถ๋ฆฌ๊ฐ ํ์ฉํด ๋ณด์
๋๋ค! |
@@ -0,0 +1,63 @@
+package christmas.domain.customer;
+
+import christmas.constant.MenuType;
+import christmas.constant.NumConstant;
+import christmas.domain.order.Orders;
+
+import java.util.Map;
+
+public class CustomerInfo {
+ private final VisitDate visitDate;
+ private final Orders orders;
+
+ private CustomerInfo(VisitDate visitDate, Orders orders) {
+ this.visitDate = visitDate;
+ this.orders = orders;
+ }
+
+ public static CustomerInfo of(VisitDate visitDate, Orders orders) {
+ return new CustomerInfo(visitDate, orders);
+ }
+
+ public boolean isOverMinAmount() {
+ if (getTotalOrderAmount() > NumConstant.MIN_EVENT_APPLY_AMOUNT.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isVisitDateWeekend() {
+ return visitDate.isVisitDateWeekend();
+ }
+
+ public boolean isOverChristmas() {
+ return visitDate.isOverChristmas();
+ }
+
+ public int getTotalOrderAmount() {
+ return orders.getTotalOrderAmount();
+ }
+
+ public int getDdayEventApplyDay() {
+ return visitDate.calculateDdayEventApplyDay();
+ }
+
+ public int getOrderNumByMenuType(MenuType menuType) {
+ return orders.getOrderNumByMenuType(menuType);
+ }
+
+ public boolean isApplyGiveawayEvent() {
+ if (orders.getTotalOrderAmount() >= NumConstant.MIN_GIVEAWAY_AMOUNT.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isSpecialDay() {
+ return visitDate.isSpecialDay();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return orders.getOrderList();
+ }
+} | Java | ์ฝ๋ ์ปจ๋ฒค์
์์์ ๋ง์ถฐ ๋น์ง๋์ค ๋ก์ง๋ณด๋ค getter๋ฅผ ์๋์ ๋๋ ๊ฒ์ด ๊น๋ํด๋ณด์
๋๋ค! |
@@ -0,0 +1,38 @@
+package christmas.domain.order;
+
+import christmas.constant.MenuType;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Orders {
+ private final List<Order> orders;
+
+ private Orders(List<Order> orders) {
+ this.orders = orders;
+ }
+
+ public static Orders from(List<Order> orders) {
+ return new Orders(orders);
+ }
+
+ public int getTotalOrderAmount() {
+ return orders.stream()
+ .map(Order::getOrderAmount)
+ .reduce(0, Integer::sum);
+ }
+
+ public int getOrderNumByMenuType(MenuType menuType) {
+ return orders.stream()
+ .filter(order -> order.isMatchMenuType(menuType))
+ .mapToInt(Order::getMenuNum)
+ .sum();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return orders.stream()
+ .collect(Collectors.toMap(Order::getMenuName, Order::getMenuNum));
+ }
+} | Java | list๋ผ๋ ์๋ฃ๊ตฌ์กฐ์ ๊ทธ๋๋ก๋ค์ด๋ฐ์ผ๋ก ์ฌ์ฉํ๋ ๊ฒ์ ์ง์ํ๋ผ๊ณ ํผ๋๋ฐฑ์ ๋์์์์ต๋๋ค!
๋, getter๋ก list์๋ฐํ์์ list์ ๋ณ๊ฒฝ๊ฐ๋ฅ์ฑ์ด ์์ผ๋ฏ๋ก Collections.unmodifi...๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ ์ ํด๋ณด์ด๋ค์! |
@@ -0,0 +1,48 @@
+package christmas.domain.menu;
+
+import christmas.constant.MenuType;
+
+import java.util.*;
+
+public class Menus {
+ private final List<Menu> menus;
+ private static Menus instance;
+
+ private Menus(List<Menu> menus) {
+ this.menus = menus;
+ }
+
+ public static Menus getInstance() {
+ if(instance == null) {
+ instance = new Menus(initialMenus());
+ }
+ return instance;
+ }
+
+ private static List<Menu> initialMenus() {
+ List<Menu> initialMenus = new ArrayList<>();
+
+ initialMenus.add(Menu.of("์์ก์ด์ํ", 6000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํํ์ค", 5500, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("์์ ์๋ฌ๋", 8000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, MenuType.MAIN));
+ initialMenus.add(Menu.of("๋ฐ๋นํ๋ฆฝ", 54000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํด์ฐ๋ฌผํ์คํ", 35000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000, MenuType.MAIN));
+ initialMenus.add(Menu.of("์ด์ฝ์ผ์ดํฌ", 15000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์์ด์คํฌ๋ฆผ", 5000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์ ๋ก์ฝ๋ผ", 3000, MenuType.DRINK));
+ initialMenus.add(Menu.of("๋ ๋์์ธ", 60000, MenuType.DRINK));
+ initialMenus.add(Menu.of("์ดํ์ธ", 25000, MenuType.DRINK));
+
+ return initialMenus;
+ }
+
+ public Optional<Menu> getMenuByMenuName(String menuName) {
+ return menus.stream()
+ .filter(menu -> menu.getMenuName().equals(menuName))
+ .findFirst();
+
+ }
+
+} | Java | ์ด๋ ๊ฒ ์ฑ๊ธํค ๋ฐฉ์์ผ๋ก ์ ์ธํ์ ์ด์ ๊ฐ ์์๊น์? enum์ ์ฌ์ฉํด๋ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,22 @@
+package christmas.constant;
+
+public enum ResultMessage {
+ BENEFIT_PREVIEW("12์ 3์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!"),
+ ORDER_MENU("\n<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ ALL_ORDER_PRICE_WITHOUT_DISCOUNT("\n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIVE_MENU("\n<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT("\n<ํํ ๋ด์ญ>"),
+ ALL_BENEFIT_AMOUNT("\n<์ดํํ ๊ธ์ก>"),
+ PAYMENT_PRICE("\n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ BADGE("\n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+
+ private String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+} | Java | ์... ๊ทธ๋ฐ ๋ฌธ์ ๊ฐ ์ข ์์๊ตฐ์ ๐ฑ |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ํ๋ก๊ทธ๋จ์ ์ ์ฒด ํ๋ฆ์ ๋ํ๋ด๋ ๋ฉ์๋์ธ๋ฐ ์ด๋ค ์์ผ๋ก ๋ถ๋ฆฌํ๋๊ฒ ์ข์๊น์....?
์ ๋ ์ผ๋จ ํ๋ก๊ทธ๋จ์ด ๋์๊ฐ๊ธด ํด์ผํ๋ ํ๋์ ๋ฉ์๋์์ ํ๋ก๊ทธ๋จ ์ ์ฒด์ ํ๋ฆ์ ๋ํด ๋ค๋ค์ผ ํ๋ค๊ณ ์๊ฐํ๊ฑฐ๋ ์!
์ง๊ธ ๋ณด๋ EventService๊ฐ์ฒด์ ์์ฑ์ ๋ฉ์๋๋ก ๋ฐ๋ก ๋นผ๋๊ฒ๋ ์ข์์๊ฑฐ๊ฐ๋ค์ |
@@ -0,0 +1,126 @@
+package christmas.controller;
+
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.customer.VisitDate;
+import christmas.domain.order.Orders;
+import christmas.service.EventService;
+import christmas.service.RestaurantService;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+
+import java.util.Collections;
+
+public class RestaurantController {
+ private final InputView inputView;
+ private final OutputView outputView;
+ private final RestaurantService restaurantService;
+ private EventService eventService;
+
+ private RestaurantController(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ this.restaurantService = restaurantService;
+ }
+
+ public static RestaurantController of(InputView inputView, OutputView outputView, RestaurantService restaurantService) {
+ return new RestaurantController(inputView, outputView, restaurantService);
+ }
+
+ public void run() {
+ inputView.printInitialMessage();
+ createCustomerInfo();
+ eventService = EventService.of(
+ getCustomerInfoFromRestaurantService()
+ );
+ applyDiscount();
+ printApplyEvent();
+ }
+
+ public void createCustomerInfo() {
+ restaurantService.createCustomerInfo(createVisitDate(), createOrdersFromMenuAndNum());
+ }
+
+ private VisitDate createVisitDate() {
+ while (true) {
+ try {
+ return restaurantService.createVisitDate(Integer.parseInt(inputView.readVisitDate()));
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private Orders createOrdersFromMenuAndNum() {
+ while (true) {
+ try {
+ String inputMenuAndNum = inputView.readMenuAndNum();
+ return restaurantService.processCreateOrders(inputMenuAndNum);
+ } catch (IllegalArgumentException e) {
+ outputView.printErrorMessage(e);
+ }
+ }
+ }
+
+ private CustomerInfo getCustomerInfoFromRestaurantService() {
+ return restaurantService.getCustomerInfo();
+ }
+
+ public void applyDiscount() {
+ eventService.applyDiscount();
+ }
+
+ public void printApplyEvent() {
+ printPreviewMessage();
+ printOrders();
+ printTotalOrderAmountWithoutDiscount();
+ printGiveawayMenu();
+ printBenefits();
+ printTotalBenefitAmount();
+ printExpectedPaymentAmount();
+ printEventBadge();
+ }
+
+ private void printPreviewMessage() {
+ outputView.printBenefitPreview();
+ }
+
+ private void printOrders() {
+ outputView.printOrders(eventService.getOrderList());
+ }
+
+ private void printTotalOrderAmountWithoutDiscount() {
+ outputView.printTotalOrderAmountWithoutDiscount(eventService.getTotalOrderAmount());
+ }
+
+ private void printGiveawayMenu() {
+ outputView.printGiveawayMenu(eventService.getGiveaway());
+ }
+
+ private void printTotalBenefitAmount() {
+ outputView.printTotalBenefitAmount(eventService.getTotalBenefitAmount());
+ }
+
+ private void printBenefits() {
+ if (eventService.getBenefits().size() == 0) {
+ outputView.printBenefits(Collections.emptyMap());
+ return;
+ }
+ outputView.printBenefits(eventService.getBenefits());
+ }
+
+ private void printExpectedPaymentAmount() {
+ outputView.printExpectedPaymentAmount(
+ expectedPaymentAmount(
+ eventService.getTotalOrderAmount(),
+ eventService.getTotalDiscountAmount()
+ ));
+ }
+
+ private int expectedPaymentAmount(int orderAmount, int benefitAmount) {
+ return orderAmount + benefitAmount;
+ }
+
+ private void printEventBadge() {
+ outputView.printEventBadge(eventService.getBadge());
+ }
+} | Java | ์ ํ๋ก๊ทธ๋จ ๊ตฌ์กฐ์ ๊ฒฝ์ฐ
view->controller -> service ์ธ ๊ฒฝ์ฐ๋ผ controller์์ ์ฒ๋ฆฌํด์ฃผ๊ธด ํ์ต๋๋ค
<- <- |
@@ -0,0 +1,55 @@
+package christmas.domain.customer;
+
+import christmas.constant.NumConstant;
+import christmas.validator.DateValidator;
+
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+
+public class VisitDate {
+ private final int visitDate;
+
+ private VisitDate(int visitDate) {
+ DateValidator.validateVisitDateBound(visitDate);
+ this.visitDate = visitDate;
+ }
+
+ public static VisitDate from(int visitDate) {
+ return new VisitDate(visitDate);
+ }
+
+ public DayOfWeek getDayOfWeek() {
+ LocalDate date = LocalDate.of(
+ NumConstant.THIS_YEAR.getValue(),
+ NumConstant.THIS_MONTH.getValue(),
+ visitDate
+ );
+ return date.getDayOfWeek();
+ }
+
+ public boolean isVisitDateWeekend() {
+ DayOfWeek dayOfWeek = getDayOfWeek();
+ if (dayOfWeek == DayOfWeek.FRIDAY || dayOfWeek == DayOfWeek.SATURDAY) {
+ return true;
+ }
+ return false;
+ }
+
+ public boolean isOverChristmas() {
+ if(visitDate > NumConstant.CHRISTMAS_DAY.getValue()) {
+ return true;
+ }
+ return false;
+ }
+
+ public int calculateDdayEventApplyDay() {
+ return visitDate - 1;
+ }
+
+ public boolean isSpecialDay() {
+ if (visitDate == NumConstant.CHRISTMAS_DAY.getValue() || getDayOfWeek() == DayOfWeek.SUNDAY) {
+ return true;
+ }
+ return false;
+ }
+} | Java | Dday์ด๋ฒคํธ๊ฐ ์ต์ 1000์์ผ๋ก ์์ํ๊ณ 1์ผ ์ดํ๋ถํฐ 100์์ฉ ๋ถ๊ฒ๋๋๋ฐ
100์์ฉ ๋ถ๊ฒ๋๋ ๋ ์ ๊ฐ์๋ฅผ ๊ตฌํ๋ ๋ฉ์๋์
๋๋ค!
1์ด ๋ฐฉ๋ฌธ ๋ ์ง์ธ ๊ฒฝ์ฐ 0์ returnํ๋ฏ๋ก 100์ ์ ์ฉ์ด ์๋๋ ๊ฒ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.service;
+
+import christmas.constant.Badge;
+import christmas.domain.customer.CustomerInfo;
+import christmas.domain.event.EventStatus;
+import christmas.handler.EventHandler;
+
+import java.util.Collections;
+import java.util.Map;
+
+public class EventService {
+ private final EventHandler eventHandler;
+ private final CustomerInfo customerInfo;
+
+ private EventService(CustomerInfo customerInfo) {
+ eventHandler = EventHandler.from(EventStatus.createInstance());
+ this.customerInfo = customerInfo;
+ }
+
+ public static EventService of(CustomerInfo customerInfo) {
+ return new EventService(customerInfo);
+ }
+
+ public void applyDiscount() {
+ eventHandler.applyDiscount(customerInfo);
+ }
+
+ public int getTotalBenefitAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalBenefitAmount();
+ }
+ return 0;
+ }
+
+ public Map<String, Integer> getBenefits() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getBenefits();
+ }
+ return Collections.emptyMap();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return customerInfo.getOrderList();
+ }
+
+ public String getGiveaway() {
+ if (customerInfo.isApplyGiveawayEvent()) {
+ return "์ดํ์ธ 1๊ฐ";
+ }
+ return "์์";
+ }
+
+ public int getTotalOrderAmount() {
+ return customerInfo.getTotalOrderAmount();
+ }
+
+ public int getTotalDiscountAmount() {
+ if (customerInfo.isOverMinAmount()) {
+ return eventHandler.getTotalDiscountAmount();
+ }
+ return 0;
+ }
+
+ public String getBadge() {
+ return Badge.getBadge(eventHandler.getTotalBenefitAmount());
+ }
+
+} | Java | ๋ฆฌํฉํ ๋ง ๋์์ด์๋๋ฐ ์ ์ ์์ด ๊ฐ๋ฐํ๋ค๋ณด๋ ๋์น ๋ถ๋ถ์ด๋ค์ ์ง์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,31 @@
+package christmas.constant;
+
+public enum Badge {
+ MISS("์์"),
+ STAR("๋ณ"),
+ TREE("ํธ๋ฆฌ"),
+ SANTA("์ฐํ");
+ private String name;
+
+ Badge(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public static String getBadge(int totalBenefitAmount) {
+ totalBenefitAmount = Math.abs(totalBenefitAmount);
+ if(totalBenefitAmount >= NumConstant.STAR_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.TREE_BADGE_AMOUNT.getValue()) {
+ return STAR.name;
+ }
+ if(totalBenefitAmount >= NumConstant.TREE_BADGE_AMOUNT.getValue() && totalBenefitAmount < NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return TREE.name;
+ }
+ if(totalBenefitAmount >= NumConstant.SANTA_BADGE_AMOUNT.getValue()) {
+ return SANTA.name;
+ }
+ return MISS.name;
+ }
+} | Java | ์ค ์ ๋ ์ด ์ฝ๋๋ฅผ ๋ณด๊ณ ๋์ ๊น๋ํ๋ค๊ณ ๋๊ผ์๋๋ฐ.. ๊ฐ์ฌํฉ๋๋ค!! |
@@ -0,0 +1,38 @@
+package christmas.domain.order;
+
+import christmas.constant.MenuType;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Orders {
+ private final List<Order> orders;
+
+ private Orders(List<Order> orders) {
+ this.orders = orders;
+ }
+
+ public static Orders from(List<Order> orders) {
+ return new Orders(orders);
+ }
+
+ public int getTotalOrderAmount() {
+ return orders.stream()
+ .map(Order::getOrderAmount)
+ .reduce(0, Integer::sum);
+ }
+
+ public int getOrderNumByMenuType(MenuType menuType) {
+ return orders.stream()
+ .filter(order -> order.isMatchMenuType(menuType))
+ .mapToInt(Order::getMenuNum)
+ .sum();
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return orders.stream()
+ .collect(Collectors.toMap(Order::getMenuName, Order::getMenuNum));
+ }
+} | Java | ๋ฉ์๋ ๋ค์ด๋ฐ์์ ์ฌ๋ฌ ์ฃผ๋ฌธ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ์ข์ ์ด๋ฆ์ด ๋ญ๊ฐ ์์๊น ํ๋ค๊ฐ ๋์จ๊ฒ ์ด๊ฑด๋ฐ ๋ค์ด๋ฐ ์ด๋ ต๋ค์ ใ
ใ
|
@@ -0,0 +1,48 @@
+package christmas.domain.menu;
+
+import christmas.constant.MenuType;
+
+import java.util.*;
+
+public class Menus {
+ private final List<Menu> menus;
+ private static Menus instance;
+
+ private Menus(List<Menu> menus) {
+ this.menus = menus;
+ }
+
+ public static Menus getInstance() {
+ if(instance == null) {
+ instance = new Menus(initialMenus());
+ }
+ return instance;
+ }
+
+ private static List<Menu> initialMenus() {
+ List<Menu> initialMenus = new ArrayList<>();
+
+ initialMenus.add(Menu.of("์์ก์ด์ํ", 6000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํํ์ค", 5500, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("์์ ์๋ฌ๋", 8000, MenuType.APPETIZER));
+ initialMenus.add(Menu.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, MenuType.MAIN));
+ initialMenus.add(Menu.of("๋ฐ๋นํ๋ฆฝ", 54000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํด์ฐ๋ฌผํ์คํ", 35000, MenuType.MAIN));
+ initialMenus.add(Menu.of("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000, MenuType.MAIN));
+ initialMenus.add(Menu.of("์ด์ฝ์ผ์ดํฌ", 15000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์์ด์คํฌ๋ฆผ", 5000, MenuType.DESSERT));
+ initialMenus.add(Menu.of("์ ๋ก์ฝ๋ผ", 3000, MenuType.DRINK));
+ initialMenus.add(Menu.of("๋ ๋์์ธ", 60000, MenuType.DRINK));
+ initialMenus.add(Menu.of("์ดํ์ธ", 25000, MenuType.DRINK));
+
+ return initialMenus;
+ }
+
+ public Optional<Menu> getMenuByMenuName(String menuName) {
+ return menus.stream()
+ .filter(menu -> menu.getMenuName().equals(menuName))
+ .findFirst();
+
+ }
+
+} | Java | Menus๋ ์ฝ๊ฒ๋งํด ๋ฉ๋ดํ์ผ๋ก ์ฌ์ฉ๋ ๊ฐ์ฒด์
๋๋ค! ๋ฐํ์ ์์ ์ ๋ณ๊ฒฝ๋ ์ผ์ด ์์๋ฏํ์ฌ ์ฑ๊ธํค ๋ฐฉ์์ผ๋ก ์ ์ธํ์์ต๋๋ค. ์ด์ ๋ํด ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | ํ
์คํธ์์ ์ฐ์ด๋ ๋ฐ์ดํฐ๋ค์ ํ ๊ณณ์ ๋ชจ์๋์ผ์
จ๋ค์. ํ
์คํธ ์ผ์ด์ค๊ฐ ๋ง์์ง๋ฉด ๋ง์์ง์๋ก ํ
์คํธ ์ฝ๋ ์์ฒด๊ฐ ๊ธธ์ด์ง๋๋ฐ, ์ด๋ฐ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ฉด ๋ฐฉ์งํ ์ ์๊ฒ ์ด์!
๊ทธ๋ฐ๋ฐ ์ด ๋ฐฉ์์ ์ฑํํ๋ฉด ํ์ฌ ํ
์คํธํ๋ ์ผ์ด์ค๊ฐ ๋ฌด์์ธ์ง ํ
์คํธ ์ฝ๋์ ์ง์ ์ ์ผ๋ก ๋๋ฌ๋์ง ์์์, ์ด๋ค ๊ฐ์ด ์
๋ ฅ๋๊ณ ๊ทธ์ ๋ํ ๊ฒฐ๊ณผ ๊ฐ์ ๋ฌด์์ธ์ง ์๊ธฐ๊ฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๋ ํ
์คํธ ๋ด์ฉ์ด ๋ฐ๋๋ค๋ฉด, ํ
์คํธ ์ผ์ด์ค ํ์ผ๋ก ๋์ด๊ฐ์ ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ณ๊ฒฝํด์ผ ํ ์๋ ์์ ๊ฒ์๋ฐ, ๊ด๋ฆฌํ๊ธฐ ์ด๋ ต์ง ์์๊น ์ถ์ด์.
์ด๋ค ์ด์ ์์ ์ด ๋ฐฉ๋ฒ์ ์ฑํํ์
จ๋์ง๊ฐ ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,17 @@
+import { EOL as LINE_SEPARATOR } from "os";
+
+export const COMMON_STRINGS = {
+ LINE_SEPARATOR,
+ EMPTY: "",
+ WHITE_SPACE: " ",
+ COLON: ":",
+ DASH: "-",
+ COMMA: ",",
+};
+
+export const CATEGORY_DICT = {
+ appetizer: "appetizer",
+ main: "main",
+ dessert: "dessert",
+ drink: "drink",
+}; | JavaScript | ์ด ๋ถ๋ถ์ ๋ค๋ฅธ common ํ์ผ์ ์์ฑํ์ ์ด์ ๊ฐ ์๋์? domain์์ ์ฌ์ฉํ๊ณ ์๋๋ฐ, domain์ ์ง์ ์์ฑํ๋ค๊ฑฐ๋, 'category'๋ผ๋ ์์ ํ์ผ์ ๋ฐ๋ก ๋ง๋ ๋ค๊ฑฐ๋ ํ์ง ์๊ณ ์ฌ๊ธฐ์ ์์ฑํ์ ์ด์ ๊ฐ ๊ถ๊ธํด์. Enum๊ฐ์ ๊ฐ๋
์ด๋ผ ๋ฐ๋ก ๋นผ์ ๊ฑธ๊น์? |
@@ -0,0 +1,5 @@
+export { default as DOMAIN } from "./domain.js";
+export { default as INPUT } from "./input.js";
+export { default as OUTPUT } from "./output.js";
+export { default as ERROR } from "./error.js";
+export { default as VALIDATION } from "./validation.js"; | JavaScript | ์์๋ฅผ ์ ์ธํ ํ์ผ์์๋ `export default`๋ฅผ ํด์ฃผ๊ณ ์๋๋ฐ, ๊ทธ๋ฐ ์์ ํ์ผ๋ค์ ๊ฐ์ธ๋ ํ์ผ์ ์ฌ์ฉํ๋ ์ด์ ๊ฐ ๊ถ๊ธํด์. ์ด๋ค ์ด์ ๋๋ฌธ์ ์ด๋ฐ ๋ฐฉ์์ ์ฑํํ์ ๊ฑด๊ฐ์? |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | `key`, `value`์๋ ์ด๋ฆ์ ๋ถ์ด๋ฉด ๋ ์ดํดํ๊ธฐ ์ฌ์ธ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | `Boolean()`์ ์ฌ์ฉํ์ง ์์๋ ๊ฒฐ๊ณผ๊ฐ ๊ฐ์๋ฐ ์ ๊ฑฐํด๋ ๋์ง ์์๊น์? |
@@ -0,0 +1,75 @@
+// eslint-disable-next-line no-unused-vars
+import MainOrder from "./MainOrder.js";
+import BasicCalculator from "./BasicCalculator.js";
+import { DayCalc, ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class DiscountCalculator {
+ // ์์ ๋ฉ์๋(๋
ผ๋ฆฌ์ )
+ /** @param {MainOrder} mainOrder */
+ static #calcEventFlag(mainOrder) {
+ return BasicCalculator.calcEventFlag(mainOrder);
+ }
+
+ // ๊ณ ์ ๋ฉ์๋
+ /** @param {MainOrder} mainOrder */
+ static discountInfo(mainOrder) {
+ const christmas = DiscountCalculator.christmasDiscount(mainOrder);
+ const weekday = DiscountCalculator.weekdayDiscount(mainOrder);
+ const weekend = DiscountCalculator.weekendDiscount(mainOrder);
+ const special = DiscountCalculator.specialDiscount(mainOrder);
+
+ return {
+ christmas, weekday, weekend, special,
+ };
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekdayDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (DayCalc.isWeekend(day)) return 0;
+ const { dessert } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(dessert);
+ return quantity * DOMAIN.WEEKDAY_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekendDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isWeekend(day)) return 0;
+ const { main } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(main);
+ return quantity * DOMAIN.WEEKEND_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static specialDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isSpecialDay(day)) return 0;
+ return DOMAIN.SPECIAL_DAY_DISCOUNT;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static christmasDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ const [start, end] = [DOMAIN.D_DAY_START_INCLUSIVE, DOMAIN.D_DAY_END_INCLUSIVE];
+
+ if (end < day) return 0;
+ const multiplier = DayCalc.eventMoneyMultiplier(start, end, day);
+ return DOMAIN.D_DAY_DEFAULT_DISCOUNT + multiplier * DOMAIN.D_DAY_BONUS_DISCOUNT;
+ }
+}
+
+export default DiscountCalculator; | JavaScript | `eventFlag`๋ฅผ ํ์ธํ๋ ๋ถ๋ถ์ด ๋ค๋ฅธ ๊ณ์ฐ ๋ฉ์๋์์๋ ์ค๋ณตํ์ฌ ์ํ๋๊ณ ์๋๋ฐ, ์ด๊ฑธ ๋ฐ๊นฅ์ผ๋ก ๋นผ๋ด์ ์ฌ์ฌ์ฉํ๋ ๊ฑด ์ด๋จ๊น์? ์๋๋ฉด `eventFlag`๋ฅผ ํ์ธํ๋ ์์น๋ฅผ ๋ค๋ฅธ ๊ณณ์ ๋ ์๋ ์์ ๊ฒ ๊ฐ์์. ๊ฐ๊ฐ์ ๋ฉ์๋ ์์ ๋ฃ์ผ์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค.
```javascript
calculate(detailFunction) {
const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
if (!eventFlag) return 0;
detailFunction();
}
weekdayDiscount(mainOrder) {
const day = mainOrder.getDate();
if (DayCalc.isWeekend(day)) return 0;
const { dessert } = mainOrder.getMenus();
const quantity = ItemCalc.sumObjValue(dessert);
return quantity * DOMAIN.WEEKDAY_DISCOUNT_PER_MENUS;
}
calculate(() => weekdayDscount(mainOrder));
``` |
@@ -0,0 +1,34 @@
+import { DomainValidator } from "../utils/Validator/index.js";
+import { DomainParser } from "../utils/Parser/index.js";
+
+class MainOrder {
+ /** @type {number} */
+ #date;
+
+ /** @type {{appetizer: {}, main: {}, dessert:{}, drink: {}}} */
+ #menus;
+
+ /** @param {number} date */
+ constructor(date) {
+ DomainValidator.date(date);
+ this.#date = date;
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ /** @param {[string]} rawOrder */
+ setMenus(rawOrder) {
+ if (this.#menus) throw new Error();
+ DomainValidator.menus(rawOrder);
+ const parsedMenu = DomainParser.menus(rawOrder);
+ this.#menus = parsedMenu;
+ }
+
+ getMenus() {
+ return this.#menus;
+ }
+}
+
+export default MainOrder; | JavaScript | ๋ฉ๋ด๋ฅผ ์นดํ
๊ณ ๋ฆฌ๋ณ๋ก ๋๋์ด์ ์ ์ฅํ๋ ๊ฒ ํธ๋ฆฌํ๊ณ ์ข์ ๊ฒ ๊ฐ์์ ๐ |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | ์ ํน๋ณํ ๋ฆฌ๋ทฐ๋ฅผ ๋ง ๋ฐ์์ผ๊ฒ ๋ค๋ ๋ง์์ผ๋ก ๋ฆฌ๋ทฐ๋ฅผ ๋จ๊ธด ๊ฒ์ ์๋์ง๋ง ์์ฃผ์
์ ๋๋ฌด ๊ฐ์ฌํฉ๋๋ค.
์ฐ์ `static`๋ง ์ฐ๋ ๋ฉ์๋์ ๋ํด์ ๋ง์๋๋ฆฌ๊ฒ ์ต๋๋ค. ์ฌ์ค ์ ๋ ์ด๋ฒ ์ฐํ
์ฝ๊ฐ ํด๋์ค๋ฅผ ๊ตฌํํด์ ํ๋ก๊ทธ๋๋ฐํ๋ ๊ฒ์ด ์ฒ์์ธ๋ฐ์... ๋ฏธ์
์ ํธ์ ๊ตฌ์กฐ์์ `static`์ ์ฐ๋ ๊ฒ์ ๋ณด๊ณ ์ผ๋จ์ `static` ๋ฉ์๋๋ฅผ ์ค์ฌ์ผ๋ก ์ฐ๊ฒ ๋์์ด์. ์ ๊ฐ์ฒด๋ณด๋ค ํด๋์ค๋ฅผ ์ ํธํ๋์ง ๋ฌผ์ด๋ณด์ ๋ค๋ฉด... ์ผ๋จ์ ๋ฉ์๋๋ฅผ ํธ์ถํ ๋ ์๋ฌด๋๋ ๋๋ฌธ์๋ฅผ ์ฐ๊ณ ์ถ๊ธฐ๋ ํ๊ณ (ํด๋์ค, ์์ฑ์๊ฐ ์๋ ๊ฒฝ์ฐ ๋๋ฌธ์๋ฅผ ์ฐ๋ ๊ฑด ์๋ฐ์คํฌ๋ฆฝํธ ์ฝ๋ ์ปจ๋ฒค์
์ ์๋ฐฐ๋๋๊น), ๋ ๊ฐ์ฒด์ ๊ฒฝ์ฐ์ ์๋ฌด๋๋ ๋ฐํ์์์ ์กฐ์๋ ์ ์๋ค๋ ์๊ฐ์ด ๋ค์ด์. ํด๋์ค๋ผ๊ณ ๋ ์์ ํ ๊ฑด ์๋๊ฒ ์ง๋ง... ์๋ฌด๋๋ ๊ทธ๋ฅ ์ฐํ
์ฝ์์ ์ฐ๋๊น ์ด์ ๊ฐ ์๊ฒ ๊ฑฐ๋ ํ ๋ถ๋ถ์ด ํฝ๋๋ค.
๋ง๋ถ์ฌ์ `static` ๋ฉ์๋๋ฅผ ์ฐ๋ ์ด์ ๋.. ์๋ฌด๋๋ ์ธ์คํด์ค๋ฅผ ์ ๋ง๋ค๊ณ ์ถ๋ค๋ ์๊ฐ์ด ํฐ ๊ฒ ๊ฐ๋ค์. ์ธ์คํด์ค๋ฅผ ์์ฑ์ํค๊ณ '๊ฒฐ๊ณผ'๋ฅผ ์ค๊ฐ ์ํ๋ก ๊ด๋ฆฌํ๊ฒ ๋ ๊ฒฝ์ฐ์, ์ฃผ๋ฌธ์ด ๋ฐ๋๊ฑฐ๋ ๋ฐฉ๋ฌธ ์ผ์ ์ ๋ฐ๊พผ๋ค๊ฑฐ๋ ํ๋ ์กฐ์์ ํ์ ๊ฒฝ์ฐ์ ์ค๊ฐ ๊ฒฐ๊ณผ๊น์ง ๋ฐ๊พธ์ด์ผ ํ๋๋ฐ ๊ทธ๊ฒ ์กฐ๊ธ ๋ฒ๊ฑฐ๋ก์ธ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ ์ธ์คํด์ค๋ฅผ ๊ฐ์ง ์๋ ํด๋์ค๋ฅผ ๋ง์ด ๋ง๋ ๊ฒ ๊ฐ์ต๋๋ค.
์ถฉ๋ถํ ๋๋ต์ ์๋๊ฒ ์ง๋ง ๋์ถฉ์ ์ด๋ ๋ค์ ๐ |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | > ํ
์คํธ์์ ์ฐ์ด๋ ๋ฐ์ดํฐ๋ค์ ํ ๊ณณ์ ๋ชจ์๋์ผ์
จ๋ค์. ํ
์คํธ ์ผ์ด์ค๊ฐ ๋ง์์ง๋ฉด ๋ง์์ง์๋ก ํ
์คํธ ์ฝ๋ ์์ฒด๊ฐ ๊ธธ์ด์ง๋๋ฐ, ์ด๋ฐ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ฉด ๋ฐฉ์งํ ์ ์๊ฒ ์ด์!
>
> ๊ทธ๋ฐ๋ฐ ์ด ๋ฐฉ์์ ์ฑํํ๋ฉด ํ์ฌ ํ
์คํธํ๋ ์ผ์ด์ค๊ฐ ๋ฌด์์ธ์ง ํ
์คํธ ์ฝ๋์ ์ง์ ์ ์ผ๋ก ๋๋ฌ๋์ง ์์์, ์ด๋ค ๊ฐ์ด ์
๋ ฅ๋๊ณ ๊ทธ์ ๋ํ ๊ฒฐ๊ณผ ๊ฐ์ ๋ฌด์์ธ์ง ์๊ธฐ๊ฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์. ๋ ํ
์คํธ ๋ด์ฉ์ด ๋ฐ๋๋ค๋ฉด, ํ
์คํธ ์ผ์ด์ค ํ์ผ๋ก ๋์ด๊ฐ์ ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ณ๊ฒฝํด์ผ ํ ์๋ ์์ ๊ฒ์๋ฐ, ๊ด๋ฆฌํ๊ธฐ ์ด๋ ต์ง ์์๊น ์ถ์ด์.
>
> ์ด๋ค ์ด์ ์์ ์ด ๋ฐฉ๋ฒ์ ์ฑํํ์
จ๋์ง๊ฐ ๊ถ๊ธํฉ๋๋ค!
ํ
์คํธ ์ผ์ด์ค์ ๊ฒฝ์ฐ์๋ ์ฌ์ค ์ ๋ 3์ฃผ์ฐจ๊น์ง ์ด๋ฐ ๋ฐฉ๋ฒ์ ์ฐ์ง๋ ์์๋๋ฐ์.. 4์ฃผ์ฐจ์๋ ํ๋์ ์ผ์ด์ค๊ฐ ์ฌ๋ฌ ์๋๋ฆฌ์ค(ํ์ผ, ์ฃผ๋ง, ํน๋ณ ๋ฑ)์ ์ ์ฉ๋์ด์ผ ํ ๊ฒฝ์ฐ๊ฐ ๋ง๋๋ผ๊ณ ์. ์ด๋ฐ ๊ฒฝ์ฐ์ ๊ตณ์ด ๋ฉ๋ด๋ฅผ ๋งค๋ฒ ์ฐ๊ณ ์์๋๋ ๊ฒฐ๊ณผ๋ฅผ ์ฐ๋ ๊ฒ ์ฐธ ๋ถํธํ์ต๋๋ค. ๋ ๊ฒฐ๊ณผ๊ฐ์ด์ด์ผ ํ๋ ๊ฒ์ด ๋ค์์๋ ์ค๊ฐ ์ธ์๊ฐ ๋๊ธฐ๋ ํ๊ณ ์.
๊ทธ๋ฆฌ๊ณ ์ฌ์ค ์ฒ์์ ํ
์คํธ ์ฝ๋๋ฅผ ์ง๊ณ ๋ฉ์๋๋ฅผ ๊ตฌํํ๋ ๋ฐฉ์์ผ๋ก ๊ฐ๋ฐ์ ํด๋ดค๋๋ฐ์. ์์ํ๋ ์ค๊ฐ ์ธ์๋ค์ด ์๊พธ ๋ฐ๋๋๋ผ๊ณ ์. ๊ทธ๋ฌ๋๊น ์ฌ์ค ์ฒ์ ํ
์คํธ ์ฝ๋๋ฅผ ์งค ๋น์์, `์ด ํํ ๊ธ์ก`์ ๊ตฌํ๋ ํ
์คํธ์ ์ธ์๋ `์ด ํ ์ธ ๊ธ์ก`๊ณผ `reward` ๊ฐ์ฒด์๋๋ฐ์... ์ค๊ฐ์ ํ๋ผ๋ฏธํฐ๊ฐ ๋ฐ๋๋๊น ํ
์คํธ ์ฝ๋ ์ ์ฒด๋ฅผ ์์ด์ผ ํ๋๋ผ๊ณ ์. ๊ทธ๋์ ๊ฒฐ๊ตญ ํ
์คํธ ๋๋ ์ค๊ฐ ์ธ์๋ฅผ ์๊ฐํ์ง ๋ง๊ณ ์
๋ ฅ๊ณผ ๊ทธ์ ํด๋นํ๋ ์ค๊ฐ, ์ต์ข
๊ฒฐ๊ณผ๋ฅผ ๋ชจ๋ ๊ฐ์ฒด์ ๋ชฐ์์ ๊ด๋ฆฌํ๊ณ ํ
์คํธ๊ฐ ๋ฐ๋ ๋ ์ค๊ฐ ์ค๊ฐ ์ธ์๋ฅผ ๋ฐ๊พธ์๋ ์๊ฐ์ผ๋ก ์ด๋ฐ ๊ตฌํ์ด ๋๊ฒ ๋์์ด์.
๋ง์ฝ ์ ์ง ๋ณด์์ ๊ด์ ์์ ์๊ฐํด๋ณธ๋ค๋ฉด ์ค๊ฐ ์ธ์๋ฅผ ์ข ์์ ํ๊ณ , jest ์ต์
์ --verbose๋ฅผ ๋ฃ์ด์ ํ
์คํธ๋ฅผ ํ๋ ์ค๊ฐ์ ๋ฌด์์ด ํ
์คํธ๋๋์ง ๋ณผ ์ ์์ ๊ฒ ๊ฐ๊ธฐ๋ ํ๋ค์.
์... ์ฌ์ค ๊ฐ๋ฐ ์ค๊ฐ๊น์ง๋ ์ ํํ
๋ ๊ต์ฅํ ์ ์ง ๋ณด์์ ํธ๋ฆฌํ ์ฝ๋์๋๋ฐ์(ํ
์คํธ ์ธ์๊ฐ ๋ฐ๋์ด๋ ์ ํ๊ธฐ๋ฒ์ผ๋ก ์ ๊ทผํ๋ ํ๋๋ง ๋ฐ๊พธ๋ฉด ๋๋๊น์) ๋ค ์์ฑํ๊ณ ๋ณด๋ ๋ค์ ์ฌ๋์๊ฒ๋ ์๋นํ ๋ถ์น์ ํ ์ฝ๋๊ฐ ๋์๋ค์.
์ด๋ป๊ฒ ํ๋ ๊ฒ ์ข์์ง ์ ๋ ๊ณ ๋ฏผ์ด ๋ฉ๋๋ค. uraflower๋๊ป์๋ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,17 @@
+import { EOL as LINE_SEPARATOR } from "os";
+
+export const COMMON_STRINGS = {
+ LINE_SEPARATOR,
+ EMPTY: "",
+ WHITE_SPACE: " ",
+ COLON: ":",
+ DASH: "-",
+ COMMA: ",",
+};
+
+export const CATEGORY_DICT = {
+ appetizer: "appetizer",
+ main: "main",
+ dessert: "dessert",
+ drink: "drink",
+}; | JavaScript | ์ฌ์ค validation์์๋ ์ฌ์ฉ๋๊ธฐ์ domain์์ ์ฐ๋ ๊ฒ์ ๋ฐ๋ก ๋นผ๋ฒ๋ ธ์ต๋๋ค. ํํธ์ผ๋ก๋ ์ด ๋
์์ด ๋๋ฉ์ธ์ ์ฑ๊ฒฉ์ ๊ฐ๊ณ ์๋ ๊ฒ์ ๋ถ๋ช
ํ์ง๋ง ๋ ๊ทธ ์์ฒด๋ก๋ ๋๋ฉ์ธ์ด ์๋๊ธฐ๋ ํด์(์ด๋ฆ์ด ๋๋ฉ์ธ ์ง์์ด๋ผ๊ธฐ์๋ ์ ๋งคํ๋๊น์) ๋ฐ๋ก ๋ถ๋ฅํ๊ณ ์ถ๋ค๋ ์๊ฐ์ด ๋ ๋ค๊ธฐ๋ ํ์ต๋๋ค. ๋ฌผ๋ก common์ผ๋ก ๋บ ๊ฒ์ด ์ข์ ์ผ์ด์๋์ง๋ ๋ชจ๋ฅด๊ฒ ์ง๋ง์.
Enum๊ฐ์ ๊ฒฝ์ฐ๋ ์ ๊ฐ ์ฌ์ค ์ ๋ชจ๋ฅด๊ฒ ์ง๋ง, ์์๋ณด๊ณ ๋ง๋ถ์ฌ์ผ ํ ๋ด์ฉ์ด ์๋ค๋ ์๊ฐ์ด ๋ค๋ฉด ๋ ๋จ๊ธฐ๋๋ก ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,5 @@
+export { default as DOMAIN } from "./domain.js";
+export { default as INPUT } from "./input.js";
+export { default as OUTPUT } from "./output.js";
+export { default as ERROR } from "./error.js";
+export { default as VALIDATION } from "./validation.js"; | JavaScript | ์ค์ ๋ก ๊ทธ๋ด ์ผ์ ๊ฑฐ์ ์๊ฒ ์ง๋ง `VALIDATION`, `DOMAIN`, `INPUT`, ๊ทธ๋ฆฌ๊ณ `OUTPUT`์ ๋์์ ์ํฌํธํด์ผ ํ๋ ์ํฉ์ ๊ณ ๋ คํ ๋ถ๋ถ์
๋๋ค.
```javascript
import DOMAIN from "../Constants/domain.js";
import VALIDATION from "../Constants/validation.js";
import INPUT from "../Constants/input.js";
import OUTPUT from "../Constants/output.js";
```
์์ ๊ฐ์ด ์์ `import`์ 4์ค์ ์ฌ์ฉํด์ผ ํ๋ ์ ์ด ๋ณ๋ก ๋ง์์ ๋ค์ง ์์์ `index.js`๋ฅผ ํตํด ๋ค์ ๋ด๋ณด๋ด๋ ๊ตฌ์กฐ๋ฅผ ์ทจํ ๊ฒ์ด๊ณ , ํน๋ณํ ์ด๋ค ์ด์ ๋ ์ด์ ์ด ํฌ์ง ์์๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | ์ฌ์ค ์ด ๋
์์ ์ฌ์ค `ItemCalc`๋ผ๊ณ ๋ฐ๋ก ํ์คํ ์ ํธ์ ์ธ ์ฑ๊ฒฉ์ธ ๊ณ์ฐ ํจ์๋ค์ ๋นผ๋์ ๋ชจ๋์ ์์๋๋ฐ, ๋ฉ๋ด์ ๊ฐ๊ฒฉ์ ๋ณธ๋ค๋ ์ ์ด ํ์คํ ๋๋ฉ์ธ์ด๋ผ ์ด์ชฝ์ผ๋ก ์ด์ฌ๋ฅผ ์ค๊ฒ ๋์์ต๋๋ค. ์ฎ๊ธฐ๋ ๊ณผ์ ์์ ์กฐ๊ธ ๋ถ์ฃผ์ํ๋๋ด์. ๋ง์ํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,27 @@
+import { ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class BasicCalculator {
+ /** @param {MainOrder} mainOrder */
+ static originalTotal(mainOrder) {
+ const nestedMenus = mainOrder.getMenus();
+ const result = Object.values(nestedMenus)
+ .map((menus) => BasicCalculator.calcMenus(menus));
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {{[menu: string]: number}} menus */
+ static calcMenus(menus) {
+ const result = Object.entries(menus)
+ .map(([k, v]) => DOMAIN.MENU_DICT[k].price * v);
+ return ItemCalc.sumArray(result);
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static calcEventFlag(mainOrder) {
+ const originalTotal = BasicCalculator.originalTotal(mainOrder);
+ return Boolean(DOMAIN.EVENT_THRESHOLD_INCLUSIVE <= originalTotal);
+ }
+}
+
+export default BasicCalculator; | JavaScript | ์ฌ์ค ์ ๋ ์ด๋ฐ ๊ฒฝ์ฐ ๊ทธ๋ฅ ๊ฐ์ธ์ ์ธ ์ด์ ๋ก `Boolean()`์ ์ฐ๋ ๊ฒ์ ์ข์ํฉ๋๋ค. ์๊ฐํด๋ณด๋ฉด ์ค๊ฐ์ ์ ๋ฃ์ ๊ฒ๋ ๋ง์ด ์๊ธด ํ ํ
๋ฐ, ์์ผ๋ก ๋ฆฌํดํ๊ธฐ๋ณด๋ค๋ ๊ฐ์ผ๋ก ๋ฆฌํดํ๋ ๊ฒ์ด ๋ญ๊ฐ ์ง๊ด์ ์ผ๋ก ๋ง๋ ๊ฒ ๊ฐ๋ค๋ ๋๋์ด ๋ ๋ฌ๊น์. ๊ทธ๋ฅ ๊ฐ์ธ์ ์ผ๋ก ์์ ๊ฐ์ด ๋๋ ๋ถ๋ถ์
๋๋ค. ์๋ฐ์คํฌ๋ฆฝํธ ํน์ฑ ์, ์ ์๋์ง ์์ ๋ณ์์ฌ๋ ์ด๋ป๊ฒ๋ ๋น๊ตํด์ ๋ฐํํด์ค ๊ฑฐ๋๊น ๋ถ์ํ ๋ง์์ด ๋๋ ๊ฑธ๊น์? ์๋ฌด๋๋ ๊ทธ๋ ๊ฒ ํ๊ฒ ๋ฉ๋๋ค. |
@@ -0,0 +1,75 @@
+// eslint-disable-next-line no-unused-vars
+import MainOrder from "./MainOrder.js";
+import BasicCalculator from "./BasicCalculator.js";
+import { DayCalc, ItemCalc } from "../utils/Calc/index.js";
+import { DOMAIN } from "../Constants/index.js";
+
+class DiscountCalculator {
+ // ์์ ๋ฉ์๋(๋
ผ๋ฆฌ์ )
+ /** @param {MainOrder} mainOrder */
+ static #calcEventFlag(mainOrder) {
+ return BasicCalculator.calcEventFlag(mainOrder);
+ }
+
+ // ๊ณ ์ ๋ฉ์๋
+ /** @param {MainOrder} mainOrder */
+ static discountInfo(mainOrder) {
+ const christmas = DiscountCalculator.christmasDiscount(mainOrder);
+ const weekday = DiscountCalculator.weekdayDiscount(mainOrder);
+ const weekend = DiscountCalculator.weekendDiscount(mainOrder);
+ const special = DiscountCalculator.specialDiscount(mainOrder);
+
+ return {
+ christmas, weekday, weekend, special,
+ };
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekdayDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (DayCalc.isWeekend(day)) return 0;
+ const { dessert } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(dessert);
+ return quantity * DOMAIN.WEEKDAY_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static weekendDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isWeekend(day)) return 0;
+ const { main } = mainOrder.getMenus();
+ const quantity = ItemCalc.sumObjValue(main);
+ return quantity * DOMAIN.WEEKEND_DISCOUNT_PER_MENUS;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static specialDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ if (!DayCalc.isSpecialDay(day)) return 0;
+ return DOMAIN.SPECIAL_DAY_DISCOUNT;
+ }
+
+ /** @param {MainOrder} mainOrder */
+ static christmasDiscount(mainOrder) {
+ const eventFlag = DiscountCalculator.#calcEventFlag(mainOrder);
+ if (!eventFlag) return 0;
+
+ const day = mainOrder.getDate();
+ const [start, end] = [DOMAIN.D_DAY_START_INCLUSIVE, DOMAIN.D_DAY_END_INCLUSIVE];
+
+ if (end < day) return 0;
+ const multiplier = DayCalc.eventMoneyMultiplier(start, end, day);
+ return DOMAIN.D_DAY_DEFAULT_DISCOUNT + multiplier * DOMAIN.D_DAY_BONUS_DISCOUNT;
+ }
+}
+
+export default DiscountCalculator; | JavaScript | ์ด ๋ถ๋ถ๊ณผ ๊ฐ์ ๊ฒฝ์ฐ๋ ์๋ ๋ฐ๋ก ๋ถ๋ฆฌ๋์ด์์๋๋ฐ์. ํ ์ธ์ด ์๋๋ผ ์ฆ์ ํ ๋๋ฌธ์ ๊ทธ๋ฅ eventFlag๋ก ๋น ์ง๊ฒ ๋์์ต๋๋ค. `reward`์ ๊ฒฝ์ฐ ๋ฐํ๊ฐ์ด 0์ด ์๋๋ผ {}์ธ๋ฐ ์ด๋ด ๊ฒฝ์ฐ ํธ์ถํ๋ ํจ์๊ฐ ๋๋ก ๊ฐ๋ฆฌ๊ฒ ๋๊ณ , ์ด ๊ฒฝ์ฐ ์ ์ง ๋ณด์์ ์์ด์๋ ๊ทธ๋ ๊ณ ๋ถํ์ํ๊ฒ ๋ฉ์๋๋ฅผ ๋๋ฆฌ๊ณ ์ถ์ง๋ ์๋ค๋ ์๊ฐ์ ๊ทธ๋ฅ `eventFlag`๋ฅผ ์ ์งํ๊ฒ ๋์๋ค์.
๊ทธ๋ฐ๋ฐ ๋ง์์ ๋ฃ๊ณ ๋๋... ์ฌ์ ํ ๋ถ๋ฆฌ๊ฐ ๋๋ค์. ์ธ์๋ก true์ผ ๊ฒฝ์ฐ ๋ฐํํ ๊ฐ์ ๋ฃ์ด์ฃผ๋ฉด ๋๋๊น์. ์๋ฌด๋๋.. ์ ๊ฐ ๋ ์๊ฐํ ๋ถ๋ถ์
๋๋ค. |
@@ -0,0 +1,34 @@
+import { DomainValidator } from "../utils/Validator/index.js";
+import { DomainParser } from "../utils/Parser/index.js";
+
+class MainOrder {
+ /** @type {number} */
+ #date;
+
+ /** @type {{appetizer: {}, main: {}, dessert:{}, drink: {}}} */
+ #menus;
+
+ /** @param {number} date */
+ constructor(date) {
+ DomainValidator.date(date);
+ this.#date = date;
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ /** @param {[string]} rawOrder */
+ setMenus(rawOrder) {
+ if (this.#menus) throw new Error();
+ DomainValidator.menus(rawOrder);
+ const parsedMenu = DomainParser.menus(rawOrder);
+ this.#menus = parsedMenu;
+ }
+
+ getMenus() {
+ return this.#menus;
+ }
+}
+
+export default MainOrder; | JavaScript | ๋์ ์ค์ฒฉ์ด ๋ฐ์ํด์ ๊ทธ๋ฅ ์ํํด์๋ ํฉ๊ณ๋ฅผ ๊ตฌํ ์ ์๋ค๋ ๊ฒ์ด ๋จ์ ์ด๋๋๋ค๐ |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | `Jest`์ `--verbose`๋ผ๋ ์ต์
์ด ์๋์ง ๋ชฐ๋๋ค์. ๊ทธ๋ฐ๋ฐ ์ฐพ์๋ณด๋ `--verbose`๋ ํ
์คํธ์ ์ฌ์ฉ๋ ๊ฐ๋ค์ ๋ณด์ฌ์ฃผ๋ ๊ฒ ์๋๋ผ ํ
์คํธ ๊ฒฐ๊ณผ๋ฅผ ๊ณ์ธต ๊ตฌ์กฐ๋ก ๋ณด์ฌ์ฃผ๋ ์ต์
์ธ ๊ฒ ๊ฐ์์. ํน์ ์ ๊ฐ ์๋ชป ์ดํดํ ๊ฒ์ด๋ผ๋ฉด ์๋ ค์ฃผ์ธ์!
---
### ํ
์คํธ ์ฝ๋์ ๋ชฉ์
์ ๊ฐ ๋ฆฌ๋ทฐ๋๋ฆฐ ์๋๋ "์ด๋ค ๊ฐ์ผ๋ก ํ
์คํธ๋ฅผ ์งํํ๋์ง๋ฅผ **ํ
์คํธ ์ฝ๋ ๋ด๋ถ** ์์ ํ์ธํ๊ณ ๊ด๋ฆฌํด์ผ ์ฝ๋๋ฅผ ์ดํดํ๊ณ ์ ์ง๋ณด์ํ๊ธฐ ์ฝ์ง ์์๊น?"๋ผ๋ ๋ป์ด์์ต๋๋ค.
๋ฌผ๋ก ์ง๊ธ์ฒ๋ผ ํ
์คํธ ์ฝ๋์ ํ
์คํธ์ ์ฌ์ฉ๋๋ ๊ฐ๋ค์ ๋ฐ๋ก ๋ถ๋ฆฌํ์ฌ ์ ์ฅํด๋ ๋ง์ฐ์ค ์ฌ๋ฆฌ๋ฉด ๊ฐ์ด ๋ค ๋์ค๊ธด ํ์ง๋ง, ์ฝ๋๋ฅผ ๋ฑ ๋ดค์ ๋ ์ด๋ค ๊ฐ์ด ์์ธ๋ฅผ ์ผ์ผํค๋์ง, ๋ ์ ์์ธ์ง, ์ด๋ค ์ผ์ด์ค๋ค์ด ์ด๋ค ๊ฒฐ๊ณผ๋ฅผ ๋ด๋์ง ์ ์ ์๊ฒ๋ ๋ฌธ์ ์ญํ ๋ ์ํํ๋ ๊ฒ ํ
์คํธ ์ฝ๋๋ผ๊ณ ์๊ฐํด์. ๊ทธ๋์ ํ
์คํธ ์ฝ๋ ๋ด๋ถ์์ ๊ฐ๋ค์ด ๊ด๋ฆฌ๋์ด์ผ ํ์ง ์์๊น ์๊ฐํด๋ด
๋๋ค.
### ๊ณตํต์ ์ผ๋ก ์ฌ์ฉ๋๋ ๊ฐ์ ์ถ์ถํ๋ ๊ฒ์ ์ฅ๋จ์
๋ง์ํ์ ๊ฒ์ฒ๋ผ ์ฌ๋ฌ ๊ตฐ๋ฐ์์ ๋์ผํ๊ฒ ์ฌ์ฉ๋๋ ๊ฐ๋ค์ด ์์ ๋, ํ๋ก๋์
์ฝ๋์์ ์ถ์ถํ๋ฏ ํ
์คํธ ์ฝ๋์์๋ ์ถ์ถํด์ผ ํ๋์ง ๊ณ ๋ฏผ์ด ๋๊ธด ํ๋ค์๐ค. ๋์ผํ ๊ฐ์ ์ฌ์ฉํ๋ ํ
์คํธ๊ฐ ๋ง์์ง์๋ก ์ถ์ถํ๋ ๊ฒ ๋ ํธํ ์๋ ์์ ๊ฒ ๊ฐ๊ตฌ์.
๊ทธ๋ฐ๋ฐ A,B,C ... ์ฌ๋ฌ ๊ฐ์ ํ
์คํธ๊ฐ "Z" ๋ผ๋ ํ
์คํธ ์ผ์ด์ค๋ฅผ ์ฌ์ฉํ๋๋ฐ, A ํ
์คํธ๊ฐ ๋ชจ์ข
์ ์ด์ ๋ก ํด๋น ํ
์คํธ ์ผ์ด์ค์์ ๋ฑ ํ๋๋ง ๋นผ๊ณ ์ฌ์ฉํ๊ฒ ๋๋ค๊ณ ํ๋ฉด ๊ณจ์น์ํ์ง ๊ฒ ๊ฐ์์.
์๋ฅผ ๋ค๋ฉด "Z" ํ
์คํธ ์ผ์ด์ค๊ฐ ์์ ์ ์๊ฐ ์๋ ๊ฐ๋ค์ ๋ชจ์์ผ ๋, "Z"์๋ ์์ ๊ฐ์ด ์์ ์ ์๋๋ฐ์. ๊ทธ๋ผ A,B,C ... ์ฌ๋ฌ ๊ฐ์ ํ
์คํธ๋ "Z"๋ฅผ ๋ฝ์์ ์ฌ์ฉํ ๊ฒ์
๋๋ค. ๊ทธ๋ฐ๋ฐ A ๋ผ๋ ๊ธฐ๋ฅ์ด ๋ชจ์ข
์ ์ด์ ๋ก ์ธํด ์์๊ฐ ๋ค์ด์๋ ๋๋๋ก ๋ณ๊ฒฝ๋๋ค๋ฉด, "Z" ์ผ์ด์ค๋ฅผ ์ง๊ธ์ฒ๋ผ ์ ๋ฝ์๋ค ์ธ ์ ์์ ๊ฒ ๊ฐ์์.
---
์ ๋ ๋ฌด์์ด ์ ๋ต์ธ์ง ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค๐
. ์ ํฌ๊ฐ ์์ ๊ท๋ชจ์ ํ๋ก์ ํธ์๋ง ํ
์คํธ ์ฝ๋๋ฅผ ์ ์ฉํด๋ด์ ํท๊ฐ๋ คํ๋ ๊ฑธ์๋ ์๋ค๋ ์๊ฐ๋ ๋ค๊ตฌ์. ํ
์คํธ ์ฝ๋์ ๊ดํ ์ฑ
์ ์ฝ์ด๋ณด๊ฑฐ๋ ์ ์ ํฐ ๊ท๋ชจ์ ์ ์ฉ์์ผ๋ณธ๋ค๋ฉด ์ข์ ๋ฐฉ์์ ๋ํ ํ์ ์ ๊ฐ์ง ์ ์์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,77 @@
+export const validInputDates = ["0", "1", "31", "32", "-1", "-31"];
+
+export const invalidInputDates = [
+ "-0",
+ "2.5",
+ "foo",
+ "bar",
+ "๐",
+ "12.0",
+ "12.000000000000004",
+ "12345678910987654321",
+];
+
+export const validDomainDates = [1, 2, 11, 15, 23, 31];
+
+export const invalidDomainDates = [32, 0];
+
+export const validInputMenus = [
+ "-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ์คํ
์ดํฌ-0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-30",
+ "๋ ๋์์ธ-1",
+ "๋ ๋์์ธ-1,๋ธ๋ฃจ์์ธ-1,ํผํ์์ธ-1,๊ทธ๋ฆฐ์์ธ-1",
+ "foo-1",
+];
+
+export const invalidInputMenus = [
+ "ํฐ๋ณธ์คํ
์ดํฌ1",
+ "์์ก์ด์ํ-1,ํฐ๋ณธ-์คํ
์ดํฌ-1",
+ "์์ ์๋ฌ๋-1,ํฐ๋ณธ์คํ
์ดํฌ--1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-foo",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.0",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.000000000000004",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1.์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,,์์ ์๋ฌ๋-1",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1,-,์์ ์๋ฌ๋-1",
+];
+
+export const valiidDomainMenus = [
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-3",
+ "ํฐ๋ณธ์คํ
์ดํฌ-1",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-3",
+ "์ ๋ก์ฝ๋ผ-6",
+ ],
+ ],
+];
+
+export const invalidDomainMenus = [
+ [["-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-1", "-1", "์์ ์๋ฌ๋-1"]],
+ [["foo-1"]],
+ [["ํฐ๋ณธ์คํ์ดํฌ-1"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-0"]],
+ [["์ดํ์ธ-1", "์ ๋ก์ฝ๋ผ-2", "๋ ๋์์ธ-1"]],
+ [["์ ๋ก์ฝ๋ผ-15"]],
+ [["ํฐ๋ณธ์คํ
์ดํฌ-10", "ํํ์ค-10", "ํด์ฐ๋ฌผํ์คํ-1"]],
+ [
+ [
+ "์์ก์ด์ํ-3",
+ "ํํ์ค-2",
+ "์์ ์๋ฌ๋-5",
+ "ํฐ๋ณธ์คํ
์ดํฌ-3",
+ "ํด์ฐ๋ฌผํ์คํ-2",
+ "์์ด์คํฌ๋ฆผ-5",
+ "์ ๋ก์ฝ๋ผ-1",
+ ],
+ ],
+]; | JavaScript | ์ ์ด ๋ถ๋ถ์ ์ ๊ฐ ์คํดํ๊ธฐ๋ ํ๊ณ , ๋ ์ค๋ช
์ด ์ข ๋ถ์ถฉ๋ถํ๋๋ฐ์...
์ฐ์ verbose๋ฅผ ์ฐ๊ณ ์ธ์์ ๋๊ธธ ๋, ์ ์ฒด๋ฅผ ๋๊ธฐ๋ ๊ฒ์ด ์๋๋ผ ์ ํ๊ธฐ๋ฒ์ผ๋ก ํน์ ํ๋๋ฅผ ํน์ ํด์ ๋๊ธฐ๊ฒ ๋๋ค๋ฉด ํ
์คํธ๋ฅผ '๋๋ ธ์ ๋' ์ด๋ค ๊ฐ์ด ํ
์คํธ๊ฐ ๋๋์ง ์ ์ ์์ ๊ฒ์ด๋ ๋ง์ด์์ต๋๋ค. ๋ฌผ๋ก ์ด๋ ๊ฒ ํ๋ค๊ณ ํ๋๋ผ๋ 'ํ
์คํธ ์ฝ๋'์๋ ์ง์ ์ ์ผ๋ก ์ด๋ค ๊ฐ์ด ๋ค์ด์ค๋์ง ์ ์๋ ์์ง๋ง์. ๋ง์ํด์ฃผ์ ๋ฌธ์ ๊ฐ ์ด๋ ์ ๋ ํด์๊ฐ ๋๋ฆฌ๋ผ๋ ์๊ฐ์ด์์ต๋๋ค.
๋ฌผ๋ก `๋ฌธ์`์ ์ญํ ์ ํด์ผ ํ๋ค๋ฉด ์ด ํ
์คํธ ์ฝ๋๋ ์ด๋ค ๋ถ๋ถ์์ ๊ธฐ๋ฅ์ ๋ชปํ๊ณ ์๋ ๊ฒ์ด ์ฌ์ค์
๋๋ค. ์ด ๋ถ๋ถ์ ๊น๋ํ๊ฒ ์ธ์ ํ ์๋ฐ์ ์๊ฒ ๋ค์.
ํ์ง๋ง ์ผ์ด์ค๊ฐ ํน์ํ๊ฒ ๋ฐ๋๋ ์ํฉ์ด๋ผ๋ฉด ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ชฐ์์ ๊ด๋ฆฌํ๋ ํธ์ด ํ์คํ ํธ๋ฆฌํ๋ค๊ณ ์๊ฐํฉ๋๋ค. ๋ง์ฝ `ํ์ผ ํ ์ธ`์ ๋์์ด ๋๋ ํ๋ชฉ์ ์ด๋ค ์ด์ ์์์ธ์ง `์ ๋ก์ฝ๋ผ`๊ฐ ์ถ๊ฐ ๋์๋ค๊ณ ํ๋ฉด, (๋๊ธฐ๋ ์ธ์์ ์ข
๋ฅ์ ๋ฐ๋ผ ๋ค๋ฅด๊ฒ ์ง๋ง) ํต์์ ์ธ ๋ฐฉ๋ฒ์ผ๋ก๋ 1. ํ์ผ ํ ์ธ ๊ณ์ฐ ํ
์คํธ, 2. ์ ์ฒด ํ ์ธ ๊ณ์ฐ ํ
์คํธ, 3. ํํ ๊ณ์ฐ ํ
์คํธ, 4. ๋ฐฐ์ง ํ
์คํธ๊ฐ ์ํฅ์ ๋ฐ๊ฒ ๋ฉ๋๋ค. ๊ฒฐ๊ตญ ์ด ๋ค ๊ฐ์ ํ
์คํธ ์ฝ๋๋ฅผ ์ฐพ์์ ์ ๋ก ์ฝ๋ผ ๊ด๋ จ ์ผ์ด์ค๋ฅผ ๋ค ์์ ํด์ผ ํ๋ ๋ฐ๋ฉด, ํ
์คํธ ์ผ์ด์ค๋ฅผ ๋ชฐ์์ ๊ด๋ฆฌํ๊ฒ ๋๋ฉด `์ ๋ก ์ฝ๋ผ` ์ผ์ด์ค๋ฅผ ์ฐพ์ ๋ค์ ์ 4๊ฐ์ ๋ด์ฉ์ ๊ณ ์ณ์ฃผ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.
๋ง์ฝ ์ฑ ๋นผ๋ ๊ฒ์ด ํ๋ค๋ค๋ ๊ฒ์ด ๋ฌธ์ ๋ผ๋ฉด ์๋ง๋ ํ
์คํธ ์ผ์ด์ค๋ง๋ค ํ์ฉ๋๋ ์๋๋ฆฌ์ค๋ ์์ค์ ํ๋๋ก ์ ํด์ค ์๋ ์๊ฒ ์ฃ ? ๊ทธ๋ฌ๋ฉด A์์ ํ
์คํธํ ๋ Z์์ `inputLevel`์ ์ ์ธํ๊ณ ํํฐํ๊ฑฐ๋ `domainLevel`์ธ ๊ฒ๋ค๋ง ํํฐ๋ฅผ ํด์ ํ
์คํธ๋ฅผ ํ ์ ์์ผ๋ ๋๋ฆ์ ๋ฐฉ๋ฒ์ด ๋ ๊ฒ ๊ฐ๊ธฐ๋ ํฉ๋๋ค.
์ฌ์ค ์ด๋ฐ ๋ฌธ์ ๋๋ฌธ์ ์ง๊ธ๋ `inputCase`์ `validCase` ๊ทธ๋ฆฌ๊ณ `tryErrorCase`๋ผ๋ 3๊ฐ์ง ๋ณ๋์ ํ์ผ์ ํต์ผ๋ ํ์ ์์ด ์ด์ฉํ๊ณ ์์๋๋ฐ์. ๋ง์ํด์ฃผ์ ๋ถ๋ถ์ ์๊ฐํ๊ณ ๋ณด๋ ์กฐ๊ธ ๋ ํต์ผ์ฑ ์๋ ํ์์ผ๋ก ์ฌ์ฉํ๋ฉด์๋ ๋ ์ผ์ด์ค๋ฅผ ๋นผ์ ์ฐ๊ธฐ ์ด๋ ค์ด ์ํฉ๋ค์ด ๋๋๋ ๋ถ๋ถ๋ ์กฐ๊ธ์ ํด๊ฒฐํ ๊ธธ์ด ๋ณด์ด๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฌผ๋ก ์ด๋ฐ ๋ฐฉ๋ฒ์ด ๊ทธ๋ฆฌ ๊น๋ํ์ง๋ ์์ง๋ง ๋ง์ด์ฃ . ๊ทธ๋๋ ๋ง์ํด์ฃผ์ ๋ถ๋ถ์ด ๋ง์ ๋์์ด ๋์์ต๋๋ค.
์์ผ๋ก ํ์ฅ์์ ํด๋๊ฐ๋ฉด์ ๋ฌด์์ด ์ด๋ค ์ํฉ์์ ๋ ์ข์์ง, ๋ ์ด๋ค ์ฅ์ ๊ณผ ๋จ์ ์ด ์๋์ง ๋ ๋ฐฐ์ฐ๊ฒ ๋๊ฒ ์ฃ . ๋๋ถ์ ๊ทธ๋ฐ ๋ฐฐ์์ ์๊ฐ์ด ์์ ๋ ์กฐ๊ธ ๋ ์ด๋ฆฐ ์ฌ๋์ด ๋ ์ ์์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,61 @@
+package christmas.controller;
+
+import christmas.domain.VisitDate;
+import christmas.domain.order.Order;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.function.Function;
+
+public class Controller {
+
+ private VisitDate visitDate;
+ private Order order;
+ private final OutputView outputView = new OutputView();
+ private final InputView inputView = new InputView();
+
+ public void run() {
+ askVisitDate();
+
+ askOrderMenu();
+
+ showPreviewBenefit();
+ }
+
+
+ private void askVisitDate() {
+ outputView.askVisitDate();
+
+ String userInput = getValidInput(VisitDate::new);
+
+ visitDate = new VisitDate(userInput);
+ }
+
+ private void askOrderMenu() {
+ outputView.askOrderMenu();
+
+ String userInput = getValidInput(Order::new);
+
+ order = new Order(userInput);
+ }
+
+ private void showPreviewBenefit() {
+ outputView.showBenefit();
+ outputView.showPreviewBenefit(order, visitDate);
+ }
+
+ private <T> String getValidInput(Function<String, T> constructor) {
+ String input;
+
+ do {
+ input = inputView.getUserInput().trim();
+ try {
+ constructor.apply(input);
+ } catch (IllegalArgumentException e) {
+ outputView.printExceptionMessage(e.getMessage());
+ input = null;
+ }
+ } while (input == null);
+
+ return input;
+ }
+}
\ No newline at end of file | Java | Function ๊ฐ์ด ํจ์๋ฅผ ์ ๋ฌํ๋ ๋ฐฉ๋ฒ์ผ๋ก ์ณ์ ๊ฐ์ ๋ฐ์ ๋๊น์ง ๋ฐ๋ณตํ๊ตฐ์!
์ ๋ ์ณ์ ๊ฐ์ ๋ฐ์ ๋๊น์ง ๋ค์ ๋ฐ๋ ๊ธฐ๋ฅ์ ๊ทธ์ ๋ ์ง์ ๋ฉ๋ด, ๋ ๊ณณ์์ ์ค๋ณต ๊ตฌํํ์์ต๋๋ค. ๊ทธ ๋ค์ ํจ์ํ ํ๋ก๊ทธ๋๋ฐ์ ๋ํด ์ ํด๋ณด๊ธด ํ์ง๋ง ์ ์๋ฟ์ง ์์๋๋ฐ
์ด ์ฝ๋๋ฅผ ๋ณด๋๊น ์ดํด๊ฐ ๋๋ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,30 @@
+package christmas.config;
+
+import christmas.config.menu.Beverage;
+import christmas.config.menu.Menu;
+
+public enum Present {
+ CHAMPAGNE(120_000, Beverage.CHAMPAGNE, 1);
+
+ private final int baseAmount;
+ private final Menu menu;
+ private final int presentCount;
+
+ Present(int baseAmount, Menu menu, int presentCount) {
+ this.baseAmount = baseAmount;
+ this.menu = menu;
+ this.presentCount = presentCount;
+ }
+
+ public int getBaseAmount() {
+ return baseAmount;
+ }
+
+ public Menu getMenu() {
+ return menu;
+ }
+
+ public int getPresentCount() {
+ return presentCount;
+ }
+}
\ No newline at end of file | Java | ๋ฉ๋ด๋ฅผ ํด๋์ค๋ก ์ ์ํ๋ ๋ฐฉ์์ด ์ฌ๋๋ง๋ค ๋ค๋ฅธ๊ฒ ์ ๊ธฐํ๋ค์! ์ ๋ ๋ฉ๋ด ํ์
์ผ ๊ตฌํํ๊ณ ๋ฉ๋ด ํ์
์ ๊ฐ์ง ๋ฉ๋ด๋ค์ ์ ๋ถ Menu enum ํด๋์ค์ ๋ฃ์์ต๋๋ค.
๊ทผ๋ฐ Present์ ๊ธฐ์ค ๊ธ์ก์ด ์๋ค๋ ์ ์ด ๋์ ๋๋๋ค. ์ด Present ํด๋์ค๋ "๊ธฐ์ค ๊ธ์ก์ ๋์ผ๋ฉด ๋ฐ๋ ์ด๋ฒคํธ๋ค์ ์ ๋ฌผ ๋ชฉ๋ก"์ผ๋ก ๋ณด์
๋๋ค. ๋ง์ฝ ๊ธฐ์ค ๊ธ์ก์ ๋๋๊ฒ ์๋๋ผ ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก ์ ๋ฌผ์ ์ง๊ธ ๋ฐ๋ ์ด๋ฒคํธ๊ฐ ์๋ค๋ฉด ๋ค๋ฅธ ํด๋์ค๋ฅผ ๊ตฌํํด์ผํ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,76 @@
+package christmas.domain;
+
+import static christmas.config.message.ErrorMessage.INVALID_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_START_DATE;
+import static christmas.domain.constant.DateConstant.MONTH;
+import static christmas.domain.constant.DateConstant.SPECIAL_DAYS;
+import static christmas.domain.constant.DateConstant.WEEKDAYS;
+import static christmas.domain.constant.DateConstant.WEEKEND;
+import static christmas.domain.constant.DateConstant.YEARS;
+
+import christmas.validator.InputValidator;
+import christmas.validator.NumberValidator;
+import java.time.DateTimeException;
+import java.time.LocalDate;
+
+public class VisitDate {
+
+ private final int date;
+
+ public VisitDate(String date) {
+ validate(date);
+
+ this.date = convertToInt(date);
+ }
+
+ private void validate(String date) {
+ if (!NumberValidator.isNumeric(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (InputValidator.isBlank(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (!isValidDay(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+ }
+
+ private static boolean isValidDay(String date) {
+ try {
+ int day = Integer.parseInt(date);
+ LocalDate.of(YEARS, MONTH, day);
+ return true;
+ } catch (DateTimeException e) {
+ return false;
+ }
+ }
+
+ private int convertToInt(String date) {
+ return Integer.parseInt(date);
+ }
+
+ public boolean isWeekday() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKDAYS.contains(day.getDayOfWeek());
+ }
+
+ public boolean isWeekend() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKEND.contains(day.getDayOfWeek());
+ }
+
+ public boolean isSpecialDate() {
+ return SPECIAL_DAYS.contains(date);
+ }
+
+ public boolean isChristmasDdayPeriod() {
+ return CHRISTMAS_D_DAY_DISCOUNT_START_DATE <= date && date <= CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+ }
+
+ public int getChristmasDiscountAccrueDate() {
+ return date - 1;
+ }
+}
\ No newline at end of file | Java | ํ์ผ / ์ฃผ๋ง ์ ํ์ธํ๋๋ฐ LocalDate ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํ๋ ์ฌ์ด ๋ฐฉ๋ฒ์ด ์๋ ์ค ๋ชฐ๋์ต๋๋ค.
๊ทธ๊ฒ๋ ๋ชจ๋ฅด๊ณ ์์ ๋ ์ง, ๋ ๋ ์ง์ ์์ผ์ ๊ตฌํ๊ณ ๊ณ์ฐํ๊ณ .. ์ฌ์ด ๋ฐฉ๋ฒ๋๊ณ ๊ณ ์ ํ์๋ค์ |
@@ -0,0 +1,30 @@
+package christmas.config;
+
+import christmas.config.menu.Beverage;
+import christmas.config.menu.Menu;
+
+public enum Present {
+ CHAMPAGNE(120_000, Beverage.CHAMPAGNE, 1);
+
+ private final int baseAmount;
+ private final Menu menu;
+ private final int presentCount;
+
+ Present(int baseAmount, Menu menu, int presentCount) {
+ this.baseAmount = baseAmount;
+ this.menu = menu;
+ this.presentCount = presentCount;
+ }
+
+ public int getBaseAmount() {
+ return baseAmount;
+ }
+
+ public Menu getMenu() {
+ return menu;
+ }
+
+ public int getPresentCount() {
+ return presentCount;
+ }
+}
\ No newline at end of file | Java | ๊ทธ๋ ๋ค์! ์ ์ฆ์ ํ์ด๋ผ๋๊ฒ ์ผ์ ๊ธ์ก ์ด์์ผ ๊ฒฝ์ฐ์๋ง ์ง๊ธ์ด ๊ฐ๋ฅํ๋ค๊ณ ์๊ฐ์ ํ๋๋ฐ! ๋ง์ฝ ๋ค๋ฅธ ๋ฐฉ์์ผ ๊ฒฝ์ฐ๋ ๋ ์์ ์ด ํ์ํ๊ฒ ๋ค์ |
@@ -0,0 +1,23 @@
+package christmas.config;
+
+public enum Badge {
+ STAR(5_000, "๋ณ"),
+ TREE(10_000, "ํธ๋ฆฌ"),
+ SANTA(20_000, "์ฐํ");
+
+ private final int baseAmount;
+ private final String name;
+
+ Badge(int baseAmount, String name) {
+ this.baseAmount = baseAmount;
+ this.name = name;
+ }
+
+ public int getBaseAmount() {
+ return baseAmount;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
\ No newline at end of file | Java | (๊ถ๊ธํด์!)
config ํจํค์ง์ ์ญํ ์ด ๋ฌด์์ธ๊ฐ์?
์์๋ฅผ ๊ด๋ฆฌํ๋ค๋ฉด domain์ constant์ ๋ค๋ฅธ์ ์ด ๋ฌด์์ธ๊ฐ์! |
@@ -0,0 +1,18 @@
+package christmas.config.message;
+
+import static christmas.domain.constant.MenuConstant.MAXIMUM_ORDER_QUANTITY;
+
+public enum ErrorMessage {
+ INVALID_DATE("[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."),
+ INVALID_ORDER("[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."),
+ EXCEEDED_ORDER_QUANTITY_LIMIT(String.format("[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ %d๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.", MAXIMUM_ORDER_QUANTITY));
+ private final String message;
+
+ ErrorMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
\ No newline at end of file | Java | (์ถ์ฒ๋๋ ค์!)
[ERROR] ํน์ `๋ค์ ์
๋ ฅํด ์ฃผ์ธ์` ๋ prefix, suffix๋ก ๋ถ๋ฆฌ๊ฐ ๊ฐ๋ฅํ ๊ฒ ๊ฐ์์ :) |
@@ -0,0 +1,71 @@
+package christmas.config.message;
+
+import christmas.util.NumberFormatter;
+
+public enum ResultMessage {
+ ORDER_MENU("<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIFT_MENU("<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT_DETAILS("<ํํ ๋ด์ญ>"),
+ TOTAL_BENEFIT_AMOUNT("<์ดํํ ๊ธ์ก>"),
+ ESTIMATED_PAYMENT_AFTER_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ DECEMBER_EVENT_BADGE("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ NONE("์์"),
+ MONETARY_UNIT("์"),
+ ORDER_MENU_FORMAT("%s %s๊ฐ"),
+ BENEFIT_FORMAT("%s: -%s์"),
+ TOTAL_BENEFIT_FORMAT("-%s์"),
+ NEW_LINE("\n");
+
+ private final String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public static String getOrderMenuFormat(String orderMenuList) {
+ return NEW_LINE.getMessage() + ORDER_MENU.getMessage() + NEW_LINE.getMessage() + orderMenuList;
+ }
+
+ public static String getTotalOrderAmountFormat(int totalOrderAmount) {
+ return TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(totalOrderAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getGiftFormat(String gifts) {
+ return GIFT_MENU.getMessage() + NEW_LINE.getMessage() + gifts + NEW_LINE.getMessage();
+ }
+
+ public static String getTotalBenefitAmountFormat(String totalBenefitAmount) {
+ return TOTAL_BENEFIT_AMOUNT.getMessage() + NEW_LINE.getMessage() + totalBenefitAmount + NEW_LINE.getMessage();
+ }
+
+ public static String getFinalPaymentAmountFormat(int finalPaymentAmount) {
+ return ESTIMATED_PAYMENT_AFTER_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(finalPaymentAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getBadgeEventFormat(String badge) {
+ return DECEMBER_EVENT_BADGE.getMessage() + NEW_LINE.getMessage() + badge;
+ }
+
+ public static String getOrderMenuFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getPresentFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getBenefitFormat(String eventName, int discountAmount) {
+ return String.format(BENEFIT_FORMAT.getMessage(), eventName, NumberFormatter.getNumberFormat(discountAmount));
+ }
+
+ public static String getTotalBenefitFormat(int totalBenefitAmount) {
+ return String.format(TOTAL_BENEFIT_FORMAT.getMessage(), NumberFormatter.getNumberFormat(totalBenefitAmount));
+ }
+}
\ No newline at end of file | Java | (๊ถ๊ธํด์)
์ฝ๋๋ฅผ ๋ณด๋ค๊ฐ ์๋ ์ํฉ์์ ์ถ๋ ฅ ๋ฉ์์ง๋ฅผ ์์๋ก ๋ถ๋ฆฌํ๋ฉด ์ป์ ์ ์๋ ์ด์ ์ด ๋ฌด์์ธ๊ฐ์?
- ํ ๋ฒ๋ง ์ฌ์ฉํ๋ ๋ฌธ์์ด์ ๊ฒฝ์ฐ
- `์์` ๊ณผ `์`, `\n` ์ ๋ถ๋ฆฌํ์ง ์์๋ ์ด๋ค ์๋ฏธ๋ฅผ ๊ฐ์ง๋์ง ์ดํด๊ฐ๋ ๊ฒฝ์ฐ
(์ด๋ฐ ๋ฐฉ๋ฒ๋ ์์ด์!)
๋ง์ฝ 0๊ณผ ๊ฐ์ ๊ฐ์ด ์๊ธด๋ค๋ฉด `-0`์ผ๋ก ํ์ ๋ ๊ฐ๋ฅ์ฑ์ด ์๊ธฐ ๋๋ฌธ์ BENEFIT_FORMAT์ ๊ธ์ก์ -1์ ๊ณฑํ๋ ๊ฒ๋ ํ๋์ ๋ฐฉ๋ฒ์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค!! |
@@ -0,0 +1,150 @@
+# ๐ ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
+
+## ๐ค ํจํค์ง ๊ตฌ์
+
+### 1์ฐจ ๊ตฌ์
+
+
+### ์ต์ข
๊ฒฐ๊ณผ & ๋ค์ด์ด๊ทธ๋จ
+
+
+
+## ๐ ์๋ ํ๋ฆ
+
+
+## ๐น์ด๋ฒคํธ ๋ชฉํ
+1. ์ค๋ณต๋ ํ ์ธ๊ณผ ์ฆ์ ์ ํ์ฉํด์, ๊ณ ๊ฐ๋ค์ด ํํ์ ๋ง์ด ๋ฐ๋๋ค๋ ๊ฒ์ ์ฒด๊ฐํ ์ ์๊ฒ ํ๋ ๊ฒ
+2. ์ฌํด 12์์ ์ง๋ 5๋
์ค ์ต๊ณ ์ ํ๋งค ๊ธ์ก์ ๋ฌ์ฑ
+3. 12์ ์ด๋ฒคํธ ์ฐธ์ฌ ๊ณ ๊ฐ์ 5%๊ฐ ๋ด๋
1์ ์ํด ์ด๋ฒคํธ์ ์ฌ์ฐธ์ฌํ๋ ๊ฒ
+
+## ๐จ ์ถ๋ ฅ ์์
+```
+์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.
+12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)
+3
+์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)
+ํฐ๋ณธ์คํ
์ดํฌ-1,๋ฐ๋นํ๋ฆฝ-1,์ด์ฝ์ผ์ดํฌ-2,์ ๋ก์ฝ๋ผ-1
+12์ 3์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!
+
+<์ฃผ๋ฌธ ๋ฉ๋ด>
+ํฐ๋ณธ์คํ
์ดํฌ 1๊ฐ
+๋ฐ๋นํ๋ฆฝ 1๊ฐ
+์ด์ฝ์ผ์ดํฌ 2๊ฐ
+์ ๋ก์ฝ๋ผ 1๊ฐ
+
+<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>
+142,000์
+
+<์ฆ์ ๋ฉ๋ด>
+์ดํ์ธ 1๊ฐ
+
+<ํํ ๋ด์ญ>
+ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ: -1,200์
+ํ์ผ ํ ์ธ: -4,046์
+ํน๋ณ ํ ์ธ: -1,000์
+์ฆ์ ์ด๋ฒคํธ: -25,000์
+
+<์ดํํ ๊ธ์ก>
+-31,246์
+
+<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>
+135,754์
+
+<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>
+์ฐํ
+```
+
+## โ ๏ธ ์ฃผ์ ์ฌํญ & ํ์ต ๋ชฉํ
+> - ํด๋์ค(๊ฐ์ฒด)๋ฅผ ๋ถ๋ฆฌ (๊ฐ์ฒด๋ฅผ ๊ฐ์ฒด์ค๋ฝ๊ฒ ์ฌ์ฉ)
+> - ๋ฉ์๋์ ๊ธธ์ด๋ 15๋ผ์ธ์ ๋์ง ์๋๋ก
+> - ๋น์ฆ๋์ค ๋ก์ง๊ณผ UI๋ก์ง ๋ถ๋ฆฌ
+> - indent(์ธ๋ดํธ, ๋ค์ฌ์ฐ๊ธฐ) depth๋ฅผ 3์ด ๋์ง ์๋๋ก ๊ตฌํ
+> - 3ํญ ์ฐ์ฐ์, else ์ฌ์ฉ ๊ธ์ง
+> - ๋๋ฉ์ธ ๋ก์ง์ ๋จ์ ํ
์คํธ๋ฅผ ๊ตฌํ
+
+## ๐ ๊ธฐ๋ฅ ๊ตฌํ ๋ฆฌ์คํธ
+- [X] : ์ ์ ๊ฒ์ฆ ํด๋์ค ์์ฑ `[NumberValidator]`
+- [X] : ๋ฐฉ๋ฌธ๋ ์ง ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] : ๊ฒ์ ์๋ด ๊ด๋ จ ๋ฉ์์ง Enum ์์ฑ `[GuideMessage]`
+ - [X] : `VisitDate` ํด๋์ค ์์ฑ
+ - [X] : ๐จ ๋ฌธ์ & ๊ณต๋ฐฑ ์
๋ ฅ์ ์์ธ๋ฐ์
+ - [X] : ๐จ 1~31์ด ์๋ ๊ฒฝ์ฐ ์์ธ๋ฐ์
+ - `[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`
+
+- [X] : ๋ฉ๋ด ์
๋ ฅ ๋ฐ๊ธฐ
+ - [X] : menu Enum ์์ฑ
+ - [X] : `Menu` ์ธํฐํ์ด์ค ์์ฑ
+ - [X] : `Order` ํด๋์ค ์์ฑ
+ - [X] : ๐จ ๊ณต๋ฐฑ ์
๋ ฅ์ ์์ธ ๋ฐ์
+ - [X] : ๐จ ์๋ ๋ฉ๋ด ์
๋ ฅํ ๊ฒฝ์ฐ ์์ธ๋ฐ์
+ - [X] : ๐จ ๋ฉ๋ด๋ 1์ด์๋ง ์
๋ ฅ๊ฐ๋ฅ
+ - [X] : ๐จ ์ค๋ณต์ผ๋ก ์
๋ ฅ์ ์์ธ๋ฐ์
+ - [X] : ๐จ ์๋ฃ๋ง ์ฃผ๋ฌธ ์๋จ
+ - [X] : ๐จ ๋ฉ๋ด๋ ํ๋ฒ์ 20๊ฐ ๊น์ง ๊ฐ๋ฅ
+ - `[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.`
+
+- [X] : ํ ์ธ ๊ธฐ๋ฅ ๊ตฌํ
+ - [X] : DiscountPolicy ์ธํฐํ์ด์ค ์์ฑ
+ - [X] : WeekdayDiscount ํด๋์ค ์์ฑ
+ - [X] : WeekendDisCount ํด๋์ค ์์ฑ
+ - [X] : ChristmasDdayDisCount ํด๋์ค ์์ฑ
+ - [X] : SpecialDiscount ํด๋์ค ์์ฑ
+ - [X] : DiscountService / DiscountConfig ํด๋์ค ์์ฑ
+- [X] : `Amount` ์ธํฐํ์ด์ค ์์ฑ
+ - [X] : TotalOrderAmount ํด๋์ค ์์ฑ
+ - [X] : DiscountAmount ํด๋์ค ์์ฑ
+ - [X] : FinalPaymentAmount ํด๋์ค ์์ฑ
+- [X] : `PresentEvent` ํด๋์ค ์์ฑ
+- [X] : `Badge` ํด๋์ค ์์ฑ
+ - 5์ฒ ์ ์ด์: ๋ณ
+ - 1๋ง ์ ์ด์: ํธ๋ฆฌ
+ - 2๋ง ์ ์ด์: ์ฐํ
+
+- [X] : ์ถ๋ ฅ
+ - [X] : ์ฃผ๋ฌธ ๋ฉ๋ด
+ - [X] : ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก
+ - [X] : ์ฆ์ ๋ฉ๋ด
+ - [X] : ํํ ๋ด์ญ
+ - [X] : ์ดํํ ๊ธ์ก ๋ด์ญ
+ - [X] : ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก
+ - [X] : 12์ ์ด๋ฒคํธ ๋ฑ์ง
+
+## ๐ ํ
์คํธ ์ฝ๋
+- `NumberValidatorTest`
+ - ์ ์ ๊ฒ์ฆ
+- `VisitDateTest`
+ - ๋ฐฉ๋ฌธ ๋ ์ง ์์ธ ๊ฒ์ฆ
+ - ํ์ผ, ์ฃผ๋ง, ํน๋ณ, ํฌ๋ฆฌ์ค๋ง์ค ํ ์ธ ์ ์ฉ ๊ฐ๋ฅํ์ง ๊ฒ์ฆ
+- `OrderTest`
+ - ์ฃผ๋ฌธ ์์ธ ๊ฒ์ฆ
+ - ์ฃผ๋ฌธ ๋ชฉ๋ก์ ํด๋น ์นดํ
๊ณ ๋ฆฌ ๋ฉ๋ด์ ์ ๋ฐํ ๊ฒ์ฆ
+ - ์ฃผ๋ฌธ ๋ชฉ๋ก์ ํด๋น ์นดํ
๊ณ ๋ฆฌ๊ฐ ์กด์ฌํ๋์ง ๋ฐํ ๊ฒ์ฆ
+- **Discount**
+ - `DiscountServiceTest`
+ - ํํ๊ธ์ก ๋ฐํ ๊ฒ์ฆ
+ - `WeekdayDiscountTest`
+ - ๋ฐฉ๋ฌธ ๋ ์ง ํ์ผ์ธ์ง ๊ฒ์ฆ
+ - ๋์ ํธ์ ์๋๋งํผ ํ์ผ ํ ์ธ๊ธ์ก ๋ฐํ ๊ฒ์ฆ
+ - `WeekendDiscountTest`
+ - ๋ฐฉ๋ฌธ ๋ ์ง ์ฃผ๋ง์ธ์ง ๊ฒ์ฆ
+ - ๋ฉ์ธ์์์ ์๋๋งํผ ์ฃผ๋ง ํ ์ธ๊ธ์ก ๋ฐํ ๊ฒ์ฆ
+ - `SpecialDiscountTest`
+ - ๋ฐฉ๋ฌธ ๋ ์ง ํน๋ณํ ์ธ ๋ ์ง์ธ์ง ๊ฒ์ฆ
+ - `ChristmasDdayDiscountTest`
+ - ๋ฐฉ๋ฌธ ๋ ์ง๊ฐ ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ ๋ ์ง์ธ์ง ๊ฒ์ฆ
+ - ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ฐ๋ผ์ ํ ์ธ๊ธ์ก ๋ฐํ ๊ฒ์ฆ
+
+- `BadgeTest`
+ - ํ ์ธ ๊ธ์ก์ ๋ฐ๋ฅธ ๋ฑ์ง ๋ฐํ ๊ฒ์ฆ
+- `PresentEventTest`
+ - ์ด ์ฃผ๋ฌธ๊ธ์ก ๊ธฐ์ค ์ฆ์ ํ ์ /๋ฌด ๊ฒ์ฆ
+ - ์ด ์ฃผ๋ฌธ๊ธ์ก ๊ธฐ์ค ์ฆ์ ํ ๋ชฉ๋ก ๋ฐํ ๊ฒ์ฆ
+
+- **Amount**
+ - `TotalOrderAmountTest`
+ - ์ด ์ฃผ๋ฌธ๊ธ์ก ๋ฐํ ๊ฒ์ฆ
+ - `FinalPaymentAmountTest`
+ - ์ต์ข
๊ฒฐ์ ๊ธ์ก ๋ฐํ ๊ฒ์ฆ
+ - `TotalBenefitAmountTest`
+ - ์ด ํํ๊ธ์ก ๋ฐํ ๊ฒ์ฆ
+ - ํํ๊ธ์ก์ด ์์ ๊ฒฝ์ฐ ์์ ๋ฐํ ๊ฒ์ฆ | Unknown | ์ธ์ธํ ๋ถ๋ถ์ด์ง๋ง ํ
์คํธ ์ฝ๋์ ๋ํด์๋ ๊ฐ์ ์ด๋ค ์ญํ ์ ๊ฒ์ฆํ๋์ง ๋์์์ผ๋๊น ๋ณด๊ธฐ ์ข์ ๊ฒ ๊ฐ์์! ์ ๋ README ์์ฑํ ๋ ์ฐธ๊ณ ํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,30 @@
+package christmas.config.menu;
+
+public enum Appetizer implements Menu {
+ BUTTON_MUSHROOM_SOUP("์์ก์ด์ํ", 6_000),
+ TAPAS("ํํ์ค", 5_500),
+ CAESAR_SALAD("์์ ์๋ฌ๋", 8_000);
+
+ private final String name;
+ private final int price;
+
+ Appetizer(String name, int price) {
+ this.name = name;
+ this.price = price;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public int getPrice() {
+ return price;
+ }
+
+ @Override
+ public Category getCategory() {
+ return Category.APPETIZER;
+ }
+}
\ No newline at end of file | Java | ์ ๊ทธ๋ฅ ๋จ์ํ 6000 ์ผ๋ก ์ ์๋๋ฐ ์ธ๋๋ฐ๋ฅผ ์ด์ฉํด์๋ ์์ฑํ ์ ์๊ตฐ์,, ์ฒ์ ์์์ต๋๋ค..! ์ซ์๊ฐ ๊ธธ ๋ ํ์คํ ๋ ์ข์ ํํ ๊ฐ์์! ์์ง ์๋ฐ์ ๋ํด ์ํด๋ฌ์ ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค! |
@@ -0,0 +1,61 @@
+package christmas.controller;
+
+import christmas.domain.VisitDate;
+import christmas.domain.order.Order;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.function.Function;
+
+public class Controller {
+
+ private VisitDate visitDate;
+ private Order order;
+ private final OutputView outputView = new OutputView();
+ private final InputView inputView = new InputView();
+
+ public void run() {
+ askVisitDate();
+
+ askOrderMenu();
+
+ showPreviewBenefit();
+ }
+
+
+ private void askVisitDate() {
+ outputView.askVisitDate();
+
+ String userInput = getValidInput(VisitDate::new);
+
+ visitDate = new VisitDate(userInput);
+ }
+
+ private void askOrderMenu() {
+ outputView.askOrderMenu();
+
+ String userInput = getValidInput(Order::new);
+
+ order = new Order(userInput);
+ }
+
+ private void showPreviewBenefit() {
+ outputView.showBenefit();
+ outputView.showPreviewBenefit(order, visitDate);
+ }
+
+ private <T> String getValidInput(Function<String, T> constructor) {
+ String input;
+
+ do {
+ input = inputView.getUserInput().trim();
+ try {
+ constructor.apply(input);
+ } catch (IllegalArgumentException e) {
+ outputView.printExceptionMessage(e.getMessage());
+ input = null;
+ }
+ } while (input == null);
+
+ return input;
+ }
+}
\ No newline at end of file | Java | (๊ถ๊ธํด์!)
์ฒ์์ `getValidInput(VisitDate::new)` ์ฝ๋๋ฅผ ๋ดค์ ๋ `VisitDate`๊ฐ ๋ฐํ๋ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐํ์ต๋๋ค.
ํ์ง๋ง ๋ฌธ์์ด์ด ๋ฐํ๋์๊ณ ๋ด๋ถ ์ฝ๋๋ฅผ ๋ดค์ ๋ VisitDate๋ฅผ ์์ฑํ๋ ๊ณผ์ ์์ ๊ฒ์ฆ ๊ณผ์ ์ ๊ฑฐ์น๊ณ ๋ง์ง๋ง์ ์
๋ ฅํ ๋ฌธ์์ด์ ๋ค์ ๋ฐํํ๋ ์ฝ๋์์ต๋๋ค.
๊ทธ๋ ๋ค๋ฉด ์ด๋ฏธ ๊ฒ์ฆ์ด ์๋ฃ๋ ๊ฐ์ ์ฌ์ฉํด๋ ์ถฉ๋ถํ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐํ๋๋ฐ ๋ค์ ํ๋ฒ ๋ ์์ฑํ๋ ์ด์ ๊ฐ ์๋์? |
@@ -0,0 +1,6 @@
+package christmas.domain.amount;
+
+public interface Amount {
+
+ int getAmount();
+}
\ No newline at end of file | Java | (๊ฐ์ธ์ ์ธ ์๊ฐ์
๋๋ค!)
Amount๋ฅผ ์ถ์ ํด๋์ค๋ก ์ ์ฉํด๋ ๊ด์ฐฎ์ ๊ฒ ๊ฐ์ต๋๋ค :) |
@@ -0,0 +1,76 @@
+package christmas.domain;
+
+import static christmas.config.message.ErrorMessage.INVALID_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_START_DATE;
+import static christmas.domain.constant.DateConstant.MONTH;
+import static christmas.domain.constant.DateConstant.SPECIAL_DAYS;
+import static christmas.domain.constant.DateConstant.WEEKDAYS;
+import static christmas.domain.constant.DateConstant.WEEKEND;
+import static christmas.domain.constant.DateConstant.YEARS;
+
+import christmas.validator.InputValidator;
+import christmas.validator.NumberValidator;
+import java.time.DateTimeException;
+import java.time.LocalDate;
+
+public class VisitDate {
+
+ private final int date;
+
+ public VisitDate(String date) {
+ validate(date);
+
+ this.date = convertToInt(date);
+ }
+
+ private void validate(String date) {
+ if (!NumberValidator.isNumeric(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (InputValidator.isBlank(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (!isValidDay(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+ }
+
+ private static boolean isValidDay(String date) {
+ try {
+ int day = Integer.parseInt(date);
+ LocalDate.of(YEARS, MONTH, day);
+ return true;
+ } catch (DateTimeException e) {
+ return false;
+ }
+ }
+
+ private int convertToInt(String date) {
+ return Integer.parseInt(date);
+ }
+
+ public boolean isWeekday() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKDAYS.contains(day.getDayOfWeek());
+ }
+
+ public boolean isWeekend() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKEND.contains(day.getDayOfWeek());
+ }
+
+ public boolean isSpecialDate() {
+ return SPECIAL_DAYS.contains(date);
+ }
+
+ public boolean isChristmasDdayPeriod() {
+ return CHRISTMAS_D_DAY_DISCOUNT_START_DATE <= date && date <= CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+ }
+
+ public int getChristmasDiscountAccrueDate() {
+ return date - 1;
+ }
+}
\ No newline at end of file | Java | (๊ถ๊ธํด์)
๋ฌธ์์ด์ด ๊ณต๋ฐฑ๊ฒ์ฌ ์ฝ๋๊ฐ ์ ์ ๊ฒ์ฆ ์ฝ๋๋ณด๋ค ์์ ์ค๋ ๊ฒ์ด ์์์ ์ฌ๋ฐ๋ฅด๋ค๊ณ ์๊ฐํ๋๋ฐ ํน์ ์ด๋ป๊ฒ ์๊ฐํ์๋์ง ๊ถ๊ธํฉ๋๋ค :) |
@@ -0,0 +1,71 @@
+package christmas.config.message;
+
+import christmas.util.NumberFormatter;
+
+public enum ResultMessage {
+ ORDER_MENU("<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIFT_MENU("<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT_DETAILS("<ํํ ๋ด์ญ>"),
+ TOTAL_BENEFIT_AMOUNT("<์ดํํ ๊ธ์ก>"),
+ ESTIMATED_PAYMENT_AFTER_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ DECEMBER_EVENT_BADGE("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ NONE("์์"),
+ MONETARY_UNIT("์"),
+ ORDER_MENU_FORMAT("%s %s๊ฐ"),
+ BENEFIT_FORMAT("%s: -%s์"),
+ TOTAL_BENEFIT_FORMAT("-%s์"),
+ NEW_LINE("\n");
+
+ private final String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public static String getOrderMenuFormat(String orderMenuList) {
+ return NEW_LINE.getMessage() + ORDER_MENU.getMessage() + NEW_LINE.getMessage() + orderMenuList;
+ }
+
+ public static String getTotalOrderAmountFormat(int totalOrderAmount) {
+ return TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(totalOrderAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getGiftFormat(String gifts) {
+ return GIFT_MENU.getMessage() + NEW_LINE.getMessage() + gifts + NEW_LINE.getMessage();
+ }
+
+ public static String getTotalBenefitAmountFormat(String totalBenefitAmount) {
+ return TOTAL_BENEFIT_AMOUNT.getMessage() + NEW_LINE.getMessage() + totalBenefitAmount + NEW_LINE.getMessage();
+ }
+
+ public static String getFinalPaymentAmountFormat(int finalPaymentAmount) {
+ return ESTIMATED_PAYMENT_AFTER_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(finalPaymentAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getBadgeEventFormat(String badge) {
+ return DECEMBER_EVENT_BADGE.getMessage() + NEW_LINE.getMessage() + badge;
+ }
+
+ public static String getOrderMenuFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getPresentFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getBenefitFormat(String eventName, int discountAmount) {
+ return String.format(BENEFIT_FORMAT.getMessage(), eventName, NumberFormatter.getNumberFormat(discountAmount));
+ }
+
+ public static String getTotalBenefitFormat(int totalBenefitAmount) {
+ return String.format(TOTAL_BENEFIT_FORMAT.getMessage(), NumberFormatter.getNumberFormat(totalBenefitAmount));
+ }
+}
\ No newline at end of file | Java | ์ถ๋ ฅํ์์ ๋ง๋ String์ ๋ฐํํ๋ ๋ฉ์๋๊ฐ์์! ์ ๋ ์ด๋ฐ ์ญํ ์ View์ ๋ถ์ฌํ๋๋ฐ ์ฌ๊ธฐ์ ์์ฑํ์ ์ด์ ๊ฐ ๊ถ๊ธํด์! |
@@ -0,0 +1,26 @@
+package christmas.domain;
+
+import christmas.config.menu.Appetizer;
+import christmas.config.menu.Beverage;
+import christmas.config.menu.Dessert;
+import christmas.config.menu.MainDish;
+import christmas.config.menu.Menu;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class MenuCategory {
+
+ private final List<Menu> menuCategory = new ArrayList<>();
+
+ public MenuCategory() {
+ menuCategory.addAll(Arrays.asList(Appetizer.values()));
+ menuCategory.addAll(Arrays.asList(Beverage.values()));
+ menuCategory.addAll(Arrays.asList(Dessert.values()));
+ menuCategory.addAll(Arrays.asList(MainDish.values()));
+ }
+
+ public List<Menu> getMenuCategory() {
+ return menuCategory;
+ }
+}
\ No newline at end of file | Java | Order์์ ๋ฉ๋ด ์นดํ
๊ณ ๋ฆฌ๋ฅผ ์ฐธ์กฐํ๊ธฐ ์ํด์ MenuCategory๋ผ๋ ํด๋์ค๋ฅผ ๋ง๋์ ๊ฒ ๊ฐ์์! MenuCategory์์ ๋ชจ๋ ๋ฉ๋ด๋ค์ด ๋ด๊ฒจ์๋ ๊ฒ ๊ฐ์๋ฐ MenuCategory ํด๋์ค ๋์ Menu์์ ๋ง๋ ์นดํ
๊ณ ๋ฆฌ๋ฅผ ๋ฐํํ๋ ๋ฉ์๋๊ฐ ์๋๊ฑด ์ด๋จ๊น์?? |
@@ -0,0 +1,76 @@
+package christmas.domain;
+
+import static christmas.config.message.ErrorMessage.INVALID_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_START_DATE;
+import static christmas.domain.constant.DateConstant.MONTH;
+import static christmas.domain.constant.DateConstant.SPECIAL_DAYS;
+import static christmas.domain.constant.DateConstant.WEEKDAYS;
+import static christmas.domain.constant.DateConstant.WEEKEND;
+import static christmas.domain.constant.DateConstant.YEARS;
+
+import christmas.validator.InputValidator;
+import christmas.validator.NumberValidator;
+import java.time.DateTimeException;
+import java.time.LocalDate;
+
+public class VisitDate {
+
+ private final int date;
+
+ public VisitDate(String date) {
+ validate(date);
+
+ this.date = convertToInt(date);
+ }
+
+ private void validate(String date) {
+ if (!NumberValidator.isNumeric(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (InputValidator.isBlank(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (!isValidDay(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+ }
+
+ private static boolean isValidDay(String date) {
+ try {
+ int day = Integer.parseInt(date);
+ LocalDate.of(YEARS, MONTH, day);
+ return true;
+ } catch (DateTimeException e) {
+ return false;
+ }
+ }
+
+ private int convertToInt(String date) {
+ return Integer.parseInt(date);
+ }
+
+ public boolean isWeekday() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKDAYS.contains(day.getDayOfWeek());
+ }
+
+ public boolean isWeekend() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKEND.contains(day.getDayOfWeek());
+ }
+
+ public boolean isSpecialDate() {
+ return SPECIAL_DAYS.contains(date);
+ }
+
+ public boolean isChristmasDdayPeriod() {
+ return CHRISTMAS_D_DAY_DISCOUNT_START_DATE <= date && date <= CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+ }
+
+ public int getChristmasDiscountAccrueDate() {
+ return date - 1;
+ }
+}
\ No newline at end of file | Java | ์ ๋ ๋ชฐ๋์ต๋๋ค..๐ญ ์ข์ ๋ฐฉ๋ฒ์ด ์์๋ค์!! |
@@ -0,0 +1,24 @@
+package christmas.domain.amount;
+
+import christmas.config.menu.Menu;
+import java.util.Map;
+
+public class TotalOrderAmount implements Amount {
+
+ private int totalOrderAmount;
+
+ public TotalOrderAmount(Map<Menu, Integer> order) {
+ for (Map.Entry<Menu, Integer> menu : order.entrySet()) {
+ totalOrderAmount += menu.getKey().getPrice() * menu.getValue();
+ }
+ }
+
+ @Override
+ public int getAmount() {
+ return totalOrderAmount;
+ }
+
+ public boolean isPresentAvailable(int baseAmount) {
+ return totalOrderAmount >= baseAmount;
+ }
+}
\ No newline at end of file | Java | Order ํด๋์ค์์ ์ธ์๋ก menus๋ก ์ฃผ์
จ๋๋ฐ, ์ฌ๊ธฐ์๋ ์ธ์๋ช
์ order๋ง๊ณ menus๋ก ํ๋๊ฑด ์ด๋จ๊น์?? |
@@ -0,0 +1,23 @@
+package christmas.config;
+
+public enum Badge {
+ STAR(5_000, "๋ณ"),
+ TREE(10_000, "ํธ๋ฆฌ"),
+ SANTA(20_000, "์ฐํ");
+
+ private final int baseAmount;
+ private final String name;
+
+ Badge(int baseAmount, String name) {
+ this.baseAmount = baseAmount;
+ this.name = name;
+ }
+
+ public int getBaseAmount() {
+ return baseAmount;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
\ No newline at end of file | Java | ์ ๋ ์ด๊ฒ ์ข ์ด์ํ๊ฑฐ ๊ฐ๋ค๊ณ ๋ ์๊ฐํ๋๋ฐ config์ ํ๋ก์ ํธ์ ์ค์ ์ ๋ณด๋ฅผ ๋ด๊ณ ์๋ ํจํค์ง๋ฅผ ๊ตฌ์์ ํ๋๋ฐ
๋ฐ๋ก constant๋ฅผ ์๋ง๋ค๊ณ config์ ๋ค ๋ฃ๋๊ฒ ๋ ์ข์์๊ฑฐ๊ฐ๋ค์.. |
@@ -0,0 +1,18 @@
+package christmas.config.message;
+
+import static christmas.domain.constant.MenuConstant.MAXIMUM_ORDER_QUANTITY;
+
+public enum ErrorMessage {
+ INVALID_DATE("[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."),
+ INVALID_ORDER("[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์."),
+ EXCEEDED_ORDER_QUANTITY_LIMIT(String.format("[ERROR] ๋ฉ๋ด๋ ํ ๋ฒ์ ์ต๋ %d๊ฐ๊น์ง๋ง ์ฃผ๋ฌธํ ์ ์์ต๋๋ค.", MAXIMUM_ORDER_QUANTITY));
+ private final String message;
+
+ ErrorMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
\ No newline at end of file | Java | ๋ถ๋ฆฌํ๋ ๋ฐฉ๋ฒ์ ์๊ฐ์ํ๊ณ ์์๋๋ฐ ์ฌํ๋ ์ฝ๋๋ณด๊ณ ์ด๋ฐ๋ฐฉ๋ฒ๋ ์๊ตฌ๋ ! ๊นจ๋ณ์์ต๋๋ค! ๊ฐ์ฌํฉ๋๋ค |
@@ -0,0 +1,71 @@
+package christmas.config.message;
+
+import christmas.util.NumberFormatter;
+
+public enum ResultMessage {
+ ORDER_MENU("<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIFT_MENU("<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT_DETAILS("<ํํ ๋ด์ญ>"),
+ TOTAL_BENEFIT_AMOUNT("<์ดํํ ๊ธ์ก>"),
+ ESTIMATED_PAYMENT_AFTER_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ DECEMBER_EVENT_BADGE("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ NONE("์์"),
+ MONETARY_UNIT("์"),
+ ORDER_MENU_FORMAT("%s %s๊ฐ"),
+ BENEFIT_FORMAT("%s: -%s์"),
+ TOTAL_BENEFIT_FORMAT("-%s์"),
+ NEW_LINE("\n");
+
+ private final String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public static String getOrderMenuFormat(String orderMenuList) {
+ return NEW_LINE.getMessage() + ORDER_MENU.getMessage() + NEW_LINE.getMessage() + orderMenuList;
+ }
+
+ public static String getTotalOrderAmountFormat(int totalOrderAmount) {
+ return TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(totalOrderAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getGiftFormat(String gifts) {
+ return GIFT_MENU.getMessage() + NEW_LINE.getMessage() + gifts + NEW_LINE.getMessage();
+ }
+
+ public static String getTotalBenefitAmountFormat(String totalBenefitAmount) {
+ return TOTAL_BENEFIT_AMOUNT.getMessage() + NEW_LINE.getMessage() + totalBenefitAmount + NEW_LINE.getMessage();
+ }
+
+ public static String getFinalPaymentAmountFormat(int finalPaymentAmount) {
+ return ESTIMATED_PAYMENT_AFTER_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(finalPaymentAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getBadgeEventFormat(String badge) {
+ return DECEMBER_EVENT_BADGE.getMessage() + NEW_LINE.getMessage() + badge;
+ }
+
+ public static String getOrderMenuFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getPresentFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getBenefitFormat(String eventName, int discountAmount) {
+ return String.format(BENEFIT_FORMAT.getMessage(), eventName, NumberFormatter.getNumberFormat(discountAmount));
+ }
+
+ public static String getTotalBenefitFormat(int totalBenefitAmount) {
+ return String.format(TOTAL_BENEFIT_FORMAT.getMessage(), NumberFormatter.getNumberFormat(totalBenefitAmount));
+ }
+}
\ No newline at end of file | Java | ์.. ๊ทธ๋ ๊ตฐ์ ๊ฐ์ ์๋ฏธ์ ์์๋ ๊ทธ๋ ๊ณ .. ๋จ์ ๋ฉ์์ง๋ฅผ ๊ด๋ฆฌํ๋ ๊ณณ์ด๋ผ๊ณ ์๊ฐํด์ ๊ตฌํ์ ํ๋๋ฐ ์กฐ๊ธ๋ ๊น๊ฒ ์๊ฐ์ ํด์ผํ ํ์๊ฐ ์๊ตฐ์ |
@@ -0,0 +1,76 @@
+package christmas.domain;
+
+import static christmas.config.message.ErrorMessage.INVALID_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+import static christmas.domain.constant.DateConstant.CHRISTMAS_D_DAY_DISCOUNT_START_DATE;
+import static christmas.domain.constant.DateConstant.MONTH;
+import static christmas.domain.constant.DateConstant.SPECIAL_DAYS;
+import static christmas.domain.constant.DateConstant.WEEKDAYS;
+import static christmas.domain.constant.DateConstant.WEEKEND;
+import static christmas.domain.constant.DateConstant.YEARS;
+
+import christmas.validator.InputValidator;
+import christmas.validator.NumberValidator;
+import java.time.DateTimeException;
+import java.time.LocalDate;
+
+public class VisitDate {
+
+ private final int date;
+
+ public VisitDate(String date) {
+ validate(date);
+
+ this.date = convertToInt(date);
+ }
+
+ private void validate(String date) {
+ if (!NumberValidator.isNumeric(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (InputValidator.isBlank(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+
+ if (!isValidDay(date)) {
+ throw new IllegalArgumentException(INVALID_DATE.getMessage());
+ }
+ }
+
+ private static boolean isValidDay(String date) {
+ try {
+ int day = Integer.parseInt(date);
+ LocalDate.of(YEARS, MONTH, day);
+ return true;
+ } catch (DateTimeException e) {
+ return false;
+ }
+ }
+
+ private int convertToInt(String date) {
+ return Integer.parseInt(date);
+ }
+
+ public boolean isWeekday() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKDAYS.contains(day.getDayOfWeek());
+ }
+
+ public boolean isWeekend() {
+ LocalDate day = LocalDate.of(YEARS, MONTH, date);
+ return WEEKEND.contains(day.getDayOfWeek());
+ }
+
+ public boolean isSpecialDate() {
+ return SPECIAL_DAYS.contains(date);
+ }
+
+ public boolean isChristmasDdayPeriod() {
+ return CHRISTMAS_D_DAY_DISCOUNT_START_DATE <= date && date <= CHRISTMAS_D_DAY_DISCOUNT_END_DATE;
+ }
+
+ public int getChristmasDiscountAccrueDate() {
+ return date - 1;
+ }
+}
\ No newline at end of file | Java | ์ ์ด๋ถ๋ถ์ ์ ๊ฐ ๋์ณค๋ค์... |
@@ -0,0 +1,6 @@
+package christmas.domain.amount;
+
+public interface Amount {
+
+ int getAmount();
+}
\ No newline at end of file | Java | ๋ต ์ถ์ํด๋์ค๋ ํ๋ฒ ์ ์ฉํด๋ณด๊ฒ ์ต๋๋ค |
@@ -0,0 +1,61 @@
+package christmas.controller;
+
+import christmas.domain.VisitDate;
+import christmas.domain.order.Order;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.function.Function;
+
+public class Controller {
+
+ private VisitDate visitDate;
+ private Order order;
+ private final OutputView outputView = new OutputView();
+ private final InputView inputView = new InputView();
+
+ public void run() {
+ askVisitDate();
+
+ askOrderMenu();
+
+ showPreviewBenefit();
+ }
+
+
+ private void askVisitDate() {
+ outputView.askVisitDate();
+
+ String userInput = getValidInput(VisitDate::new);
+
+ visitDate = new VisitDate(userInput);
+ }
+
+ private void askOrderMenu() {
+ outputView.askOrderMenu();
+
+ String userInput = getValidInput(Order::new);
+
+ order = new Order(userInput);
+ }
+
+ private void showPreviewBenefit() {
+ outputView.showBenefit();
+ outputView.showPreviewBenefit(order, visitDate);
+ }
+
+ private <T> String getValidInput(Function<String, T> constructor) {
+ String input;
+
+ do {
+ input = inputView.getUserInput().trim();
+ try {
+ constructor.apply(input);
+ } catch (IllegalArgumentException e) {
+ outputView.printExceptionMessage(e.getMessage());
+ input = null;
+ }
+ } while (input == null);
+
+ return input;
+ }
+}
\ No newline at end of file | Java | ๋ง์๋ค์ด๋ณด๋ ๋ง๋ ๋ง์์ด๋ค์! ๊ตณ์ด ํ๋ฒ๋ ์์ฑํ๋ ๊ณผ์ ์ด ์์ฝ๋ค์... ๋ฆฌํํ ๋ง ๊ณผ์ ์์ ํ๋ฒ ์์ ํด๋ด์ผ๊ฒ ์ต๋๋ค. ๊ณ ๊ธ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,71 @@
+package christmas.config.message;
+
+import christmas.util.NumberFormatter;
+
+public enum ResultMessage {
+ ORDER_MENU("<์ฃผ๋ฌธ ๋ฉ๋ด>"),
+ TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>"),
+ GIFT_MENU("<์ฆ์ ๋ฉ๋ด>"),
+ BENEFIT_DETAILS("<ํํ ๋ด์ญ>"),
+ TOTAL_BENEFIT_AMOUNT("<์ดํํ ๊ธ์ก>"),
+ ESTIMATED_PAYMENT_AFTER_DISCOUNT("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>"),
+ DECEMBER_EVENT_BADGE("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>"),
+ NONE("์์"),
+ MONETARY_UNIT("์"),
+ ORDER_MENU_FORMAT("%s %s๊ฐ"),
+ BENEFIT_FORMAT("%s: -%s์"),
+ TOTAL_BENEFIT_FORMAT("-%s์"),
+ NEW_LINE("\n");
+
+ private final String message;
+
+ ResultMessage(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public static String getOrderMenuFormat(String orderMenuList) {
+ return NEW_LINE.getMessage() + ORDER_MENU.getMessage() + NEW_LINE.getMessage() + orderMenuList;
+ }
+
+ public static String getTotalOrderAmountFormat(int totalOrderAmount) {
+ return TOTAL_ORDER_AMOUNT_BEFORE_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(totalOrderAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getGiftFormat(String gifts) {
+ return GIFT_MENU.getMessage() + NEW_LINE.getMessage() + gifts + NEW_LINE.getMessage();
+ }
+
+ public static String getTotalBenefitAmountFormat(String totalBenefitAmount) {
+ return TOTAL_BENEFIT_AMOUNT.getMessage() + NEW_LINE.getMessage() + totalBenefitAmount + NEW_LINE.getMessage();
+ }
+
+ public static String getFinalPaymentAmountFormat(int finalPaymentAmount) {
+ return ESTIMATED_PAYMENT_AFTER_DISCOUNT.getMessage() + NEW_LINE.getMessage()
+ + NumberFormatter.getNumberFormat(finalPaymentAmount) + MONETARY_UNIT.getMessage() + NEW_LINE.getMessage();
+ }
+
+ public static String getBadgeEventFormat(String badge) {
+ return DECEMBER_EVENT_BADGE.getMessage() + NEW_LINE.getMessage() + badge;
+ }
+
+ public static String getOrderMenuFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getPresentFormat(String menuName, int count) {
+ return String.format(ORDER_MENU_FORMAT.getMessage(), menuName, NumberFormatter.getNumberFormat(count)) + NEW_LINE.getMessage();
+ }
+
+ public static String getBenefitFormat(String eventName, int discountAmount) {
+ return String.format(BENEFIT_FORMAT.getMessage(), eventName, NumberFormatter.getNumberFormat(discountAmount));
+ }
+
+ public static String getTotalBenefitFormat(int totalBenefitAmount) {
+ return String.format(TOTAL_BENEFIT_FORMAT.getMessage(), NumberFormatter.getNumberFormat(totalBenefitAmount));
+ }
+}
\ No newline at end of file | Java | View์์๋ ๋จ์ ์ถ๋ ฅ๋ง ํ๋๋ก ๊ตฌํ์ ํ์ต๋๋ค. ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ๊ฒ์ View๊ฐ ์๋ ๊ณณ์์ ๊ฐ์ ธ์ค๋ ๋ฐฉ๋ฒ์ ์๊ฐํด์.. ์๋ View์์ ๋ค ์ฒ๋ฆฌ๋ฅผ ํ์๋๋ฐ ๊ฐ๋
์ฑ๋ ์์ข๊ณ ๊ทธ๋์ enum์์ ์ํ๋ ๊ฐ์ ๋ฐํํ๋๋ก ๊ตฌํํ์ต๋๋ค! |
@@ -0,0 +1,26 @@
+package christmas.domain;
+
+import christmas.config.menu.Appetizer;
+import christmas.config.menu.Beverage;
+import christmas.config.menu.Dessert;
+import christmas.config.menu.MainDish;
+import christmas.config.menu.Menu;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class MenuCategory {
+
+ private final List<Menu> menuCategory = new ArrayList<>();
+
+ public MenuCategory() {
+ menuCategory.addAll(Arrays.asList(Appetizer.values()));
+ menuCategory.addAll(Arrays.asList(Beverage.values()));
+ menuCategory.addAll(Arrays.asList(Dessert.values()));
+ menuCategory.addAll(Arrays.asList(MainDish.values()));
+ }
+
+ public List<Menu> getMenuCategory() {
+ return menuCategory;
+ }
+}
\ No newline at end of file | Java | ๊ทธ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ธ๊ฑฐ ๊ฐ๋ค์! ์์งํ ์ด๋ถ๋ถ๋ ์กฐ๊ธ ์์ ์ด ํ์ํ๋ค๊ณ ์๊ฐํ๊ณ ์์๋๋ฐ ใ
ใ
๊ฐ์ฌํฉ๋๋ค |
@@ -0,0 +1,58 @@
+package christmas.domain;
+
+import java.util.Map;
+
+public class Bill {
+
+ private int numberOfDessert;
+ private int numberOfMain;
+ private int totalAmount;
+
+ public Bill() {
+ this.numberOfDessert = 0;
+ this.numberOfMain = 0;
+ this.totalAmount = 0;
+ }
+
+ public static Bill getBill() {
+ return new Bill();
+ }
+
+ public void calculate(Map<String, Integer> orderInfo) {
+ for (String menu : orderInfo.keySet()) {
+ this.totalAmount += getPrice(menu, orderInfo) * orderInfo.get(menu);
+ }
+ }
+
+ private int getPrice(String menu, Map<String, Integer> orderInfo) {
+ for (Menu type : Menu.values()) {
+ if (type.getMenuName().contains(menu)) {
+ int index = type.getMenuName().indexOf(menu);
+ checkType(type, menu, orderInfo);
+ return type.getMenuPrice().get(index);
+ }
+ }
+ return 0;
+ }
+
+ private void checkType(Menu type, String menu, Map<String, Integer> orderInfo) {
+ if (type == Menu.DESSERT) {
+ this.numberOfDessert += orderInfo.get(menu);
+ }
+ if (type == Menu.MAIN) {
+ this.numberOfMain += orderInfo.get(menu);
+ }
+ }
+
+ public int getNumberOfDessert() {
+ return numberOfDessert;
+ }
+
+ public int getNumberOfMain() {
+ return numberOfMain;
+ }
+
+ public int getTotalAmount() {
+ return totalAmount;
+ }
+} | Java | 3์ฃผ์ฐจ ๋ฆฌ๋ทฐ์์ ํ๋ ์ค์ด๊ธฐ๋ฅผ ๋ดค์๋๋ฐ Bill ํด๋์ค์์ ์ด ์ธ๊ฐ์ง ํ๋๋ฅผ ๊ตณ์ด ๊ฐ์ง๊ณ ๊ฐ์ผํ๋ ์๊ฐ์ด ๋ค์์ต๋๋ค. ์๋ฅผ ๋ค์ด์ calculate method์์ return void ๋์ ์ ๊ณ์ฐํ totalAmount๋ฅผ return ํด์ค๋ ๋ ํ
๋๊น์ |
@@ -0,0 +1,117 @@
+package christmas.domain;
+
+import christmas.domain.event.badge.BadgeEvent;
+import christmas.domain.event.discount.DDayEvent;
+import christmas.domain.event.discount.DiscountEvent;
+import christmas.domain.event.discount.SpecialEvent;
+import christmas.domain.event.discount.WeekdayEvent;
+import christmas.domain.event.discount.WeekendEvent;
+import christmas.domain.event.giveaway.ChampagneEvent;
+import christmas.domain.event.giveaway.Giveaway;
+import christmas.domain.event.giveaway.GiveawayEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitDetails {
+
+ private static final int PARTICIPATION_CRITERIA = 10000;
+ private static final int MIN_AMOUNT = 0;
+ public static final int EVENT_START_DAY = 1;
+ public static final int EVENT_LAST_DAY = 31;
+ private final List<String> discountNames;
+ private final List<Integer> discountAmount;
+ private int totalDiscountAmount;
+ private String badge;
+ private Giveaway giveaway;
+
+ public BenefitDetails() {
+ this.discountNames = new ArrayList<>();
+ this.discountAmount = new ArrayList<>();
+ }
+
+ public static BenefitDetails getBenefitDetails() {
+ return new BenefitDetails();
+ }
+
+ public void receive(int date, Bill bill) {
+ if (bill.getTotalAmount() >= PARTICIPATION_CRITERIA &&
+ date >= EVENT_START_DAY && date <= EVENT_LAST_DAY) {
+ getDiscountInfo(date, bill);
+ }
+ getGiveawayInfo(bill);
+ this.totalDiscountAmount = discountAmount.stream().mapToInt(Integer::intValue).sum();
+ this.badge = BadgeEvent.getBenefitAmountEvent().giveBadge(totalDiscountAmount);
+ }
+
+ private void getGiveawayInfo(Bill bill) {
+ ChampagneEvent champagneEvent = GiveawayEvent.getChampagneEvent();
+ this.giveaway = champagneEvent.give(bill.getTotalAmount());
+ if (giveaway.quantity() > MIN_AMOUNT) {
+ discountNames.add(champagneEvent.getChampagneEventName());
+ discountAmount.add(giveaway.price());
+ }
+ }
+
+ private void getDiscountInfo(int date, Bill bill) {
+ getDDayEventInfo(date);
+ getWeekdayEventInfo(date, bill.getNumberOfDessert());
+ getWeekendEventInfo(date, bill.getNumberOfMain());
+ getSpecialEventInfo(date);
+ }
+
+ private void getSpecialEventInfo(int date) {
+ SpecialEvent specialEvent = DiscountEvent.getSpecialEvent();
+ int discount = specialEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(specialEvent.getSpecialEventName());
+ }
+ }
+
+ private void getWeekendEventInfo(int date, int numberOfMain) {
+ WeekendEvent weekendEvent = DiscountEvent.getWeekendEvent();
+ int discount = weekendEvent.discount(date, numberOfMain);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekendEvent.getWeekendEventName());
+ }
+ }
+
+ private void getWeekdayEventInfo(int date, int numberOfDessert) {
+ WeekdayEvent weekdayEvent = DiscountEvent.getWeekdayEvent();
+ int discount = weekdayEvent.discount(date, numberOfDessert);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekdayEvent.getWeekdayEventName());
+ }
+ }
+
+ private void getDDayEventInfo(int date) {
+ DDayEvent dDayEvent = DiscountEvent.getDDayEvent();
+ int discount = dDayEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(dDayEvent.getDDayEventName());
+ }
+ }
+
+ public List<String> getDiscountNames() {
+ return discountNames;
+ }
+
+ public List<Integer> getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public int getTotalDiscountAmount() {
+ return totalDiscountAmount;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public Giveaway getGiveaway() {
+ return giveaway;
+ }
+} | Java | discountNames ์ discountAmount๊ณผ ๊ฐ์ด ๊ด๋ฆฌ๋๋๊ฑฐ ๊ฐ์๋ฐ Map์ผ๋ก ํ๋์ ๋ณ์๋ก ๊ตฌํํ๋ค๋ฉด ์ด๋จ๊น์ |
@@ -0,0 +1,35 @@
+package christmas.domain;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.stream.Stream;
+
+public enum Menu {
+
+ APPETIZER(List.of("์์ก์ด์ํ", "ํํ์ค", "์์ ์๋ฌ๋"), List.of(6000, 5500, 8000)),
+ MAIN(List.of("ํฐ๋ณธ์คํ
์ดํฌ", "๋ฐ๋นํ๋ฆฝ", "ํด์ฐ๋ฌผํ์คํ", "ํฌ๋ฆฌ์ค๋ง์คํ์คํ"), List.of(55000, 54000, 35000, 25000)),
+ DESSERT(List.of("์ด์ฝ์ผ์ดํฌ", "์์ด์คํฌ๋ฆผ"), List.of(15000, 5000)),
+ BEVERAGE(List.of("์ ๋ก์ฝ๋ผ", "๋ ๋์์ธ", "์ดํ์ธ"), List.of(3000, 60000, 25000));
+
+ private static final List<String> ALL_MENU = Stream.of(APPETIZER.menuName, MAIN.menuName,
+ DESSERT.menuName, BEVERAGE.menuName).flatMap(Collection::stream).toList();
+ private final List<String> menuName;
+ private final List<Integer> menuPrice;
+
+ Menu(List<String> menuName, List<Integer> menuPrice) {
+ this.menuName = menuName;
+ this.menuPrice = menuPrice;
+ }
+
+ public List<String> getMenuName() {
+ return menuName;
+ }
+
+ public List<Integer> getMenuPrice() {
+ return menuPrice;
+ }
+
+ public static boolean isExistMenu(String menu) {
+ return ALL_MENU.contains(menu);
+ }
+} | Java | ๋ฉ๋ด์ ๊ธ์ก์ ๊ฐ์ ์์๋๋ก ๋ฐ๋ก ์ ์ฅํ๋๊ฒ๋ณด๋ค {์์ก์ด์ํ, 6000} ์ด๋ฐ์์ผ๋ก ์ ์ฅ์ํค๋๊ฒ ๋ ๊ฐ๋
์ฑ์ ์ข์ง ์์๊น์ !? |
@@ -0,0 +1,25 @@
+package christmas.domain.event.badge;
+
+public class BenefitAmountEvent {
+
+ private static final String STAR_BADGE = "๋ณ";
+ private static final String TREE_BADGE = "ํธ๋ฆฌ";
+ private static final String SANTA_BADGE = "์ฐํ";
+ private static final String NONE = "์์";
+ private static final int STAR_STANDARD_AMOUNT = 5000;
+ private static final int TREE_STANDARD_AMOUNT = 10000;
+ private static final int SANTA_STANDARD_AMOUNT = 20000;
+
+ public String giveBadge(int benefitAmount) {
+ if (benefitAmount < STAR_STANDARD_AMOUNT) {
+ return NONE;
+ }
+ if (benefitAmount < TREE_STANDARD_AMOUNT) {
+ return STAR_BADGE;
+ }
+ if (benefitAmount < SANTA_STANDARD_AMOUNT) {
+ return TREE_BADGE;
+ }
+ return SANTA_BADGE;
+ }
+} | Java | ์ฌ๊ธฐ์๋ {๋ณ, 5000}์ฒ๋ผ Badge Type๋ณ๋ก ์ด๋ฆ๊ณผ ๊ธ์ก์ ํ๋ฒ์ ์ ์ฅํด๋์ผ๋ฉด ๋ ์ข์์ ๊ฑฐ ๊ฐ์์ |
@@ -0,0 +1,23 @@
+package christmas.domain.event.giveaway;
+
+public class ChampagneEvent implements GiveawayEvent {
+
+ private static final int STANDARD_AMOUNT = 120000;
+ private static final String GIVEAWAY_NAME = "์ดํ์ธ";
+ private static final int GIVEAWAY_AMOUNT = 25000;
+ private static final int GIVEAWAY_QUANTITY = 1;
+ private static final String NO_GIVEAWAY = "์์";
+ private static final int LESS_THAN_STANDARD_AMOUNT = 0;
+ private static final int NO_QUANTITY = 0;
+
+ public String getChampagneEventName() {
+ return "์ฆ์ ์ด๋ฒคํธ";
+ }
+
+ public Giveaway give(int amount) {
+ if (amount >= STANDARD_AMOUNT) {
+ return new Giveaway(GIVEAWAY_NAME, GIVEAWAY_AMOUNT, GIVEAWAY_QUANTITY);
+ }
+ return new Giveaway(NO_GIVEAWAY, LESS_THAN_STANDARD_AMOUNT, NO_QUANTITY);
+ }
+} | Java | Menu์์ enum ๊ฐ์ ์๋ฃ๊ตฌ์กฐ(?...)๋ฅผ ์ฌ์ฉํด์ ์ฒ๋ฆฌํ์๋ค๋ฉด champagneEvent๋ด์์ ์ด๋ ๊ฒ static ์ผ๋ก ๋ณ๋ ์ด๋ฆ์ ๋ค์ ์์ฑํ์ง ์์๋ ํด๋น๋ฉ๋ด๋ฅผ ๊ฐ์ ธ์์ ๋์ด๋ค ์ฌ์ฉํ ์ ์์์ ๊ฑฐ ๊ฐ์์ |
@@ -0,0 +1,114 @@
+package christmas.view;
+
+import static christmas.util.Constant.*;
+
+import christmas.domain.BenefitDetails;
+import java.util.Map;
+
+public class OutputView {
+
+ public static final String AMOUNT_OUTPUT_CONVERT_PATTERN = "\\B(?=(\\d{3})+(?!\\d))";
+ private static final int MIN_AMOUNT = 0;
+ public static final int DECEMBER = 12;
+
+ public void printReadDate() {
+ System.out.printf(Message.READ_DATE.getMessage(), DECEMBER, DECEMBER);
+ }
+
+ public void printReadMenu() {
+ System.out.println(Message.READ_MENU.getMessage());
+ }
+
+ public void printEventPreview(int date) {
+ System.out.printf(Message.EVENT_PREVIEW.getMessage(), DECEMBER, date);
+ }
+
+ public void printOrderMenu(Map<String, Integer> orderInfo) {
+ System.out.printf(Message.ORDER_MENU.getMessage());
+ for (String menu : orderInfo.keySet()) {
+ System.out.printf(Message.NAME_AND_NUMBER.getMessage(), menu, orderInfo.get(menu));
+ }
+ }
+
+ public void printTotalAmount(int amount) {
+ System.out.printf(Message.TOTAL_AMOUNT.getMessage());
+ System.out.printf(Message.CURRENCY_UNIT.getMessage(), String.valueOf(amount)
+ .replaceAll(AMOUNT_OUTPUT_CONVERT_PATTERN, DELIMITER_COMMA));
+ }
+
+ public void printGiveaway(BenefitDetails benefitDetails) {
+ System.out.printf(Message.GIVEAWAY.getMessage());
+ if (benefitDetails.getGiveaway().name().equals(Message.NONE.getMessage())) {
+ System.out.println(Message.NONE.getMessage());
+ return;
+ }
+ System.out.printf(Message.NAME_AND_NUMBER.getMessage(),
+ benefitDetails.getGiveaway().name(),
+ benefitDetails.getGiveaway().quantity());
+ }
+
+ public void printBenefitDetails(BenefitDetails benefitDetails) {
+ System.out.printf(Message.BENEFIT_DETAILS.getMessage());
+ if (benefitDetails.getTotalDiscountAmount() == MIN_AMOUNT) {
+ System.out.println(Message.NONE.getMessage());
+ return;
+ }
+ for (int i = 0; i < benefitDetails.getDiscountAmount().size(); i++) {
+ System.out.printf(Message.NAME_AND_CURRENCY_UNIT.getMessage(),
+ benefitDetails.getDiscountNames().get(i),
+ String.valueOf(benefitDetails.getDiscountAmount().get(i))
+ .replaceAll(AMOUNT_OUTPUT_CONVERT_PATTERN, DELIMITER_COMMA));
+ }
+ }
+
+ public void printTotalDiscountAmount(BenefitDetails benefitDetails) {
+ System.out.printf(Message.TOTAL_DISCOUNT_AMOUNT.getMessage());
+ if (benefitDetails.getTotalDiscountAmount() == MIN_AMOUNT) {
+ System.out.printf(Message.CURRENCY_UNIT.getMessage(), MIN_AMOUNT);
+ return;
+ }
+ System.out.printf(Message.MINUS_CURRENCY_UNIT.getMessage(),
+ String.valueOf(benefitDetails.getTotalDiscountAmount())
+ .replaceAll(AMOUNT_OUTPUT_CONVERT_PATTERN, DELIMITER_COMMA));
+ }
+
+ public void printAmountOfPayment(int amount) {
+ System.out.printf(Message.AMOUNT_OF_PAYMENT.getMessage());
+ System.out.printf(Message.CURRENCY_UNIT.getMessage(), String.valueOf(amount)
+ .replaceAll(AMOUNT_OUTPUT_CONVERT_PATTERN, DELIMITER_COMMA));
+ }
+
+ public void printEventBadge(BenefitDetails benefitDetails) {
+ System.out.printf(Message.EVENT_BADGE.getMessage(), DECEMBER);
+ System.out.println(benefitDetails.getBadge());
+ }
+
+ private enum Message {
+ READ_DATE("์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น %d์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.%n" +
+ "%d์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)%n"),
+ READ_MENU("์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)"),
+ EVENT_PREVIEW("%d์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!%n"),
+ ORDER_MENU("%n<์ฃผ๋ฌธ ๋ฉ๋ด>%n"),
+ TOTAL_AMOUNT("%n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>%n"),
+ GIVEAWAY("%n<์ฆ์ ๋ฉ๋ด>%n"),
+ BENEFIT_DETAILS("%n<ํํ ๋ด์ญ>%n"),
+ TOTAL_DISCOUNT_AMOUNT("%n<์ดํํ ๊ธ์ก>%n"),
+ AMOUNT_OF_PAYMENT("%n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>%n"),
+ EVENT_BADGE("%n<%d์ ์ด๋ฒคํธ ๋ฐฐ์ง>%n"),
+ NAME_AND_NUMBER("%s %d๊ฐ%n"),
+ CURRENCY_UNIT("%s์%n"),
+ MINUS_CURRENCY_UNIT("-%s์%n"),
+ NAME_AND_CURRENCY_UNIT("%s: -%s์%n"),
+ NONE("์์");
+
+ private final String message;
+
+ Message(String message) {
+ this.message = message;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ }
+} | Java | Message๋ฅผ OutputView์์ ๋ ์ด์ ๊ฐ ์๋์?! |
@@ -0,0 +1,63 @@
+package christmas.controller;
+
+import christmas.domain.BenefitDetails;
+import christmas.domain.Bill;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.Map;
+
+public class EventController {
+
+ private final InputView inputView;
+ private final OutputView outputView;
+
+ public EventController(InputView inputView, OutputView outputView) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ }
+
+ public void hold() {
+ int date = getDate();
+ Map<String, Integer> orderInfo = getOrder(date);
+ Bill bill = getBill(orderInfo);
+ BenefitDetails benefitDetails = getBenefitDetails(date, bill);
+ getResult(bill, benefitDetails);
+ }
+
+ private void getResult(Bill bill, BenefitDetails benefitDetails) {
+ int paymentAmount = bill.getTotalAmount() - benefitDetails.getTotalDiscountAmount() +
+ benefitDetails.getGiveaway().price();
+ outputView.printAmountOfPayment(paymentAmount);
+ outputView.printEventBadge(benefitDetails);
+ }
+
+ private BenefitDetails getBenefitDetails(int date, Bill bill) {
+ BenefitDetails benefitDetails = BenefitDetails.getBenefitDetails();
+ benefitDetails.receive(date, bill);
+
+ outputView.printGiveaway(benefitDetails);
+ outputView.printBenefitDetails(benefitDetails);
+ outputView.printTotalDiscountAmount(benefitDetails);
+ return benefitDetails;
+ }
+
+ private Bill getBill(Map<String, Integer> orderInfo) {
+ Bill bill = Bill.getBill();
+ bill.calculate(orderInfo);
+ outputView.printTotalAmount(bill.getTotalAmount());
+ return bill;
+ }
+
+ private Map<String, Integer> getOrder(int date) {
+ outputView.printReadMenu();
+ Map<String, Integer> orderInfo = inputView.readMenu();
+ outputView.printEventPreview(date);
+ outputView.printOrderMenu(orderInfo);
+ return orderInfo;
+ }
+
+ private int getDate() {
+ outputView.printReadDate();
+ return inputView.readDate();
+ }
+} | Java | ๋๋ถ๋ถ์ ๋ถ๋ค์ด ์ฝํธ๋กค๋ฌ์์ ์ฌ์ฉํ๋ ๋ฉ์๋๋ฅผ get์ผ๋ก ๋ช
๋ช
ํ์๋๊ตฐ์. ์ ๋ ์ปจํธ๋กค๋ฌ ๋ด๋ถ์์ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค๋ ์๋ฏธ๋ก create๋ก ์ฌ์ฉํ๋๋ฐ ์ด ๋ถ๋ถ์ ๋ํด์ ๋ง์ ๋๋๋ฉด ์ข์๊ฑฐ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,63 @@
+package christmas.controller;
+
+import christmas.domain.BenefitDetails;
+import christmas.domain.Bill;
+import christmas.view.InputView;
+import christmas.view.OutputView;
+import java.util.Map;
+
+public class EventController {
+
+ private final InputView inputView;
+ private final OutputView outputView;
+
+ public EventController(InputView inputView, OutputView outputView) {
+ this.inputView = inputView;
+ this.outputView = outputView;
+ }
+
+ public void hold() {
+ int date = getDate();
+ Map<String, Integer> orderInfo = getOrder(date);
+ Bill bill = getBill(orderInfo);
+ BenefitDetails benefitDetails = getBenefitDetails(date, bill);
+ getResult(bill, benefitDetails);
+ }
+
+ private void getResult(Bill bill, BenefitDetails benefitDetails) {
+ int paymentAmount = bill.getTotalAmount() - benefitDetails.getTotalDiscountAmount() +
+ benefitDetails.getGiveaway().price();
+ outputView.printAmountOfPayment(paymentAmount);
+ outputView.printEventBadge(benefitDetails);
+ }
+
+ private BenefitDetails getBenefitDetails(int date, Bill bill) {
+ BenefitDetails benefitDetails = BenefitDetails.getBenefitDetails();
+ benefitDetails.receive(date, bill);
+
+ outputView.printGiveaway(benefitDetails);
+ outputView.printBenefitDetails(benefitDetails);
+ outputView.printTotalDiscountAmount(benefitDetails);
+ return benefitDetails;
+ }
+
+ private Bill getBill(Map<String, Integer> orderInfo) {
+ Bill bill = Bill.getBill();
+ bill.calculate(orderInfo);
+ outputView.printTotalAmount(bill.getTotalAmount());
+ return bill;
+ }
+
+ private Map<String, Integer> getOrder(int date) {
+ outputView.printReadMenu();
+ Map<String, Integer> orderInfo = inputView.readMenu();
+ outputView.printEventPreview(date);
+ outputView.printOrderMenu(orderInfo);
+ return orderInfo;
+ }
+
+ private int getDate() {
+ outputView.printReadDate();
+ return inputView.readDate();
+ }
+} | Java | ๋ฉ์๋๋ฅผ ์ฌ์ฉ ์์์ ๋ฐ๋ผ ๋ฐฐ์นํ์๋ฉด ๊ฐ๋
์ฑ ํฅ์์ ์ข๋ ๋์์ด ๋ ๊ฑฐ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,117 @@
+package christmas.domain;
+
+import christmas.domain.event.badge.BadgeEvent;
+import christmas.domain.event.discount.DDayEvent;
+import christmas.domain.event.discount.DiscountEvent;
+import christmas.domain.event.discount.SpecialEvent;
+import christmas.domain.event.discount.WeekdayEvent;
+import christmas.domain.event.discount.WeekendEvent;
+import christmas.domain.event.giveaway.ChampagneEvent;
+import christmas.domain.event.giveaway.Giveaway;
+import christmas.domain.event.giveaway.GiveawayEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitDetails {
+
+ private static final int PARTICIPATION_CRITERIA = 10000;
+ private static final int MIN_AMOUNT = 0;
+ public static final int EVENT_START_DAY = 1;
+ public static final int EVENT_LAST_DAY = 31;
+ private final List<String> discountNames;
+ private final List<Integer> discountAmount;
+ private int totalDiscountAmount;
+ private String badge;
+ private Giveaway giveaway;
+
+ public BenefitDetails() {
+ this.discountNames = new ArrayList<>();
+ this.discountAmount = new ArrayList<>();
+ }
+
+ public static BenefitDetails getBenefitDetails() {
+ return new BenefitDetails();
+ }
+
+ public void receive(int date, Bill bill) {
+ if (bill.getTotalAmount() >= PARTICIPATION_CRITERIA &&
+ date >= EVENT_START_DAY && date <= EVENT_LAST_DAY) {
+ getDiscountInfo(date, bill);
+ }
+ getGiveawayInfo(bill);
+ this.totalDiscountAmount = discountAmount.stream().mapToInt(Integer::intValue).sum();
+ this.badge = BadgeEvent.getBenefitAmountEvent().giveBadge(totalDiscountAmount);
+ }
+
+ private void getGiveawayInfo(Bill bill) {
+ ChampagneEvent champagneEvent = GiveawayEvent.getChampagneEvent();
+ this.giveaway = champagneEvent.give(bill.getTotalAmount());
+ if (giveaway.quantity() > MIN_AMOUNT) {
+ discountNames.add(champagneEvent.getChampagneEventName());
+ discountAmount.add(giveaway.price());
+ }
+ }
+
+ private void getDiscountInfo(int date, Bill bill) {
+ getDDayEventInfo(date);
+ getWeekdayEventInfo(date, bill.getNumberOfDessert());
+ getWeekendEventInfo(date, bill.getNumberOfMain());
+ getSpecialEventInfo(date);
+ }
+
+ private void getSpecialEventInfo(int date) {
+ SpecialEvent specialEvent = DiscountEvent.getSpecialEvent();
+ int discount = specialEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(specialEvent.getSpecialEventName());
+ }
+ }
+
+ private void getWeekendEventInfo(int date, int numberOfMain) {
+ WeekendEvent weekendEvent = DiscountEvent.getWeekendEvent();
+ int discount = weekendEvent.discount(date, numberOfMain);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekendEvent.getWeekendEventName());
+ }
+ }
+
+ private void getWeekdayEventInfo(int date, int numberOfDessert) {
+ WeekdayEvent weekdayEvent = DiscountEvent.getWeekdayEvent();
+ int discount = weekdayEvent.discount(date, numberOfDessert);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekdayEvent.getWeekdayEventName());
+ }
+ }
+
+ private void getDDayEventInfo(int date) {
+ DDayEvent dDayEvent = DiscountEvent.getDDayEvent();
+ int discount = dDayEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(dDayEvent.getDDayEventName());
+ }
+ }
+
+ public List<String> getDiscountNames() {
+ return discountNames;
+ }
+
+ public List<Integer> getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public int getTotalDiscountAmount() {
+ return totalDiscountAmount;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public Giveaway getGiveaway() {
+ return giveaway;
+ }
+} | Java | ์ ๋ ์ฒ์์๋ ๋ฑ์ง๋ฅผ ์คํธ๋ง์ผ๋ก ๋ง๋๋๊ฑธ ๋๋ฉ์ธ์์ ์งํํ๋ค๊ฐ ๊ทธ ์ญํ ์ View์ชฝ์์ ํ๋๊ฒ ๋ง๋ค๊ณ ํ๋จํด์ ๊ฐ์ฒด๋ฅผ ๋ง๋๋ ๋ฐฉ์์ผ๋ก ๋ฐ๊ฟจ๋๋ฐ ์ด์ ๋ํด์ ์ด๋ป๊ฒ ์๊ฐํ์๋์??? |
@@ -0,0 +1,117 @@
+package christmas.domain;
+
+import christmas.domain.event.badge.BadgeEvent;
+import christmas.domain.event.discount.DDayEvent;
+import christmas.domain.event.discount.DiscountEvent;
+import christmas.domain.event.discount.SpecialEvent;
+import christmas.domain.event.discount.WeekdayEvent;
+import christmas.domain.event.discount.WeekendEvent;
+import christmas.domain.event.giveaway.ChampagneEvent;
+import christmas.domain.event.giveaway.Giveaway;
+import christmas.domain.event.giveaway.GiveawayEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitDetails {
+
+ private static final int PARTICIPATION_CRITERIA = 10000;
+ private static final int MIN_AMOUNT = 0;
+ public static final int EVENT_START_DAY = 1;
+ public static final int EVENT_LAST_DAY = 31;
+ private final List<String> discountNames;
+ private final List<Integer> discountAmount;
+ private int totalDiscountAmount;
+ private String badge;
+ private Giveaway giveaway;
+
+ public BenefitDetails() {
+ this.discountNames = new ArrayList<>();
+ this.discountAmount = new ArrayList<>();
+ }
+
+ public static BenefitDetails getBenefitDetails() {
+ return new BenefitDetails();
+ }
+
+ public void receive(int date, Bill bill) {
+ if (bill.getTotalAmount() >= PARTICIPATION_CRITERIA &&
+ date >= EVENT_START_DAY && date <= EVENT_LAST_DAY) {
+ getDiscountInfo(date, bill);
+ }
+ getGiveawayInfo(bill);
+ this.totalDiscountAmount = discountAmount.stream().mapToInt(Integer::intValue).sum();
+ this.badge = BadgeEvent.getBenefitAmountEvent().giveBadge(totalDiscountAmount);
+ }
+
+ private void getGiveawayInfo(Bill bill) {
+ ChampagneEvent champagneEvent = GiveawayEvent.getChampagneEvent();
+ this.giveaway = champagneEvent.give(bill.getTotalAmount());
+ if (giveaway.quantity() > MIN_AMOUNT) {
+ discountNames.add(champagneEvent.getChampagneEventName());
+ discountAmount.add(giveaway.price());
+ }
+ }
+
+ private void getDiscountInfo(int date, Bill bill) {
+ getDDayEventInfo(date);
+ getWeekdayEventInfo(date, bill.getNumberOfDessert());
+ getWeekendEventInfo(date, bill.getNumberOfMain());
+ getSpecialEventInfo(date);
+ }
+
+ private void getSpecialEventInfo(int date) {
+ SpecialEvent specialEvent = DiscountEvent.getSpecialEvent();
+ int discount = specialEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(specialEvent.getSpecialEventName());
+ }
+ }
+
+ private void getWeekendEventInfo(int date, int numberOfMain) {
+ WeekendEvent weekendEvent = DiscountEvent.getWeekendEvent();
+ int discount = weekendEvent.discount(date, numberOfMain);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekendEvent.getWeekendEventName());
+ }
+ }
+
+ private void getWeekdayEventInfo(int date, int numberOfDessert) {
+ WeekdayEvent weekdayEvent = DiscountEvent.getWeekdayEvent();
+ int discount = weekdayEvent.discount(date, numberOfDessert);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekdayEvent.getWeekdayEventName());
+ }
+ }
+
+ private void getDDayEventInfo(int date) {
+ DDayEvent dDayEvent = DiscountEvent.getDDayEvent();
+ int discount = dDayEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(dDayEvent.getDDayEventName());
+ }
+ }
+
+ public List<String> getDiscountNames() {
+ return discountNames;
+ }
+
+ public List<Integer> getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public int getTotalDiscountAmount() {
+ return totalDiscountAmount;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public Giveaway getGiveaway() {
+ return giveaway;
+ }
+} | Java | ์๋ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ ๋ฉ์๋๊ฐ ์์ผ๋ ์์ฑ์ ๋ถ๋ถ์ private๋ก ๋ฐ๊ฟ์ฃผ์
๋ ๊ด์ฐฎ์๊ฑฐ ๊ฐ์ต๋๋ค~ |
@@ -0,0 +1,117 @@
+package christmas.domain;
+
+import christmas.domain.event.badge.BadgeEvent;
+import christmas.domain.event.discount.DDayEvent;
+import christmas.domain.event.discount.DiscountEvent;
+import christmas.domain.event.discount.SpecialEvent;
+import christmas.domain.event.discount.WeekdayEvent;
+import christmas.domain.event.discount.WeekendEvent;
+import christmas.domain.event.giveaway.ChampagneEvent;
+import christmas.domain.event.giveaway.Giveaway;
+import christmas.domain.event.giveaway.GiveawayEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitDetails {
+
+ private static final int PARTICIPATION_CRITERIA = 10000;
+ private static final int MIN_AMOUNT = 0;
+ public static final int EVENT_START_DAY = 1;
+ public static final int EVENT_LAST_DAY = 31;
+ private final List<String> discountNames;
+ private final List<Integer> discountAmount;
+ private int totalDiscountAmount;
+ private String badge;
+ private Giveaway giveaway;
+
+ public BenefitDetails() {
+ this.discountNames = new ArrayList<>();
+ this.discountAmount = new ArrayList<>();
+ }
+
+ public static BenefitDetails getBenefitDetails() {
+ return new BenefitDetails();
+ }
+
+ public void receive(int date, Bill bill) {
+ if (bill.getTotalAmount() >= PARTICIPATION_CRITERIA &&
+ date >= EVENT_START_DAY && date <= EVENT_LAST_DAY) {
+ getDiscountInfo(date, bill);
+ }
+ getGiveawayInfo(bill);
+ this.totalDiscountAmount = discountAmount.stream().mapToInt(Integer::intValue).sum();
+ this.badge = BadgeEvent.getBenefitAmountEvent().giveBadge(totalDiscountAmount);
+ }
+
+ private void getGiveawayInfo(Bill bill) {
+ ChampagneEvent champagneEvent = GiveawayEvent.getChampagneEvent();
+ this.giveaway = champagneEvent.give(bill.getTotalAmount());
+ if (giveaway.quantity() > MIN_AMOUNT) {
+ discountNames.add(champagneEvent.getChampagneEventName());
+ discountAmount.add(giveaway.price());
+ }
+ }
+
+ private void getDiscountInfo(int date, Bill bill) {
+ getDDayEventInfo(date);
+ getWeekdayEventInfo(date, bill.getNumberOfDessert());
+ getWeekendEventInfo(date, bill.getNumberOfMain());
+ getSpecialEventInfo(date);
+ }
+
+ private void getSpecialEventInfo(int date) {
+ SpecialEvent specialEvent = DiscountEvent.getSpecialEvent();
+ int discount = specialEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(specialEvent.getSpecialEventName());
+ }
+ }
+
+ private void getWeekendEventInfo(int date, int numberOfMain) {
+ WeekendEvent weekendEvent = DiscountEvent.getWeekendEvent();
+ int discount = weekendEvent.discount(date, numberOfMain);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekendEvent.getWeekendEventName());
+ }
+ }
+
+ private void getWeekdayEventInfo(int date, int numberOfDessert) {
+ WeekdayEvent weekdayEvent = DiscountEvent.getWeekdayEvent();
+ int discount = weekdayEvent.discount(date, numberOfDessert);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekdayEvent.getWeekdayEventName());
+ }
+ }
+
+ private void getDDayEventInfo(int date) {
+ DDayEvent dDayEvent = DiscountEvent.getDDayEvent();
+ int discount = dDayEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(dDayEvent.getDDayEventName());
+ }
+ }
+
+ public List<String> getDiscountNames() {
+ return discountNames;
+ }
+
+ public List<Integer> getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public int getTotalDiscountAmount() {
+ return totalDiscountAmount;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public Giveaway getGiveaway() {
+ return giveaway;
+ }
+} | Java | ํ๋์ ๊ฐ์๊ฐ 5๊ฐ์
์ ํด๋น ํด๋์ค์ ์ฑ
์์ด ๋ง์ ๋๋์
๋๋ค! ํด๋์ค๋ฅผ ์ถ๊ฐ๋ก ์์ฑํ์๋๊ฒ ์ด๋จ๊น์? ์ ๋ ์ฒ์์ Benefits๋ผ๋ ํ๋์ ํด๋์ค์์ ๋น์ทํ ๋ฉ์๋๋ค์ ๊ด๋ฆฌํ๋ค๊ฐ EventManager์ Benefits๋ก ๋๋ ์ ๊ด๋ฆฌํ๋ ์ฑ
์์ด ๋ถ์ฐ๋๋๋ผ๊ตฌ์! |
@@ -0,0 +1,117 @@
+package christmas.domain;
+
+import christmas.domain.event.badge.BadgeEvent;
+import christmas.domain.event.discount.DDayEvent;
+import christmas.domain.event.discount.DiscountEvent;
+import christmas.domain.event.discount.SpecialEvent;
+import christmas.domain.event.discount.WeekdayEvent;
+import christmas.domain.event.discount.WeekendEvent;
+import christmas.domain.event.giveaway.ChampagneEvent;
+import christmas.domain.event.giveaway.Giveaway;
+import christmas.domain.event.giveaway.GiveawayEvent;
+import java.util.ArrayList;
+import java.util.List;
+
+public class BenefitDetails {
+
+ private static final int PARTICIPATION_CRITERIA = 10000;
+ private static final int MIN_AMOUNT = 0;
+ public static final int EVENT_START_DAY = 1;
+ public static final int EVENT_LAST_DAY = 31;
+ private final List<String> discountNames;
+ private final List<Integer> discountAmount;
+ private int totalDiscountAmount;
+ private String badge;
+ private Giveaway giveaway;
+
+ public BenefitDetails() {
+ this.discountNames = new ArrayList<>();
+ this.discountAmount = new ArrayList<>();
+ }
+
+ public static BenefitDetails getBenefitDetails() {
+ return new BenefitDetails();
+ }
+
+ public void receive(int date, Bill bill) {
+ if (bill.getTotalAmount() >= PARTICIPATION_CRITERIA &&
+ date >= EVENT_START_DAY && date <= EVENT_LAST_DAY) {
+ getDiscountInfo(date, bill);
+ }
+ getGiveawayInfo(bill);
+ this.totalDiscountAmount = discountAmount.stream().mapToInt(Integer::intValue).sum();
+ this.badge = BadgeEvent.getBenefitAmountEvent().giveBadge(totalDiscountAmount);
+ }
+
+ private void getGiveawayInfo(Bill bill) {
+ ChampagneEvent champagneEvent = GiveawayEvent.getChampagneEvent();
+ this.giveaway = champagneEvent.give(bill.getTotalAmount());
+ if (giveaway.quantity() > MIN_AMOUNT) {
+ discountNames.add(champagneEvent.getChampagneEventName());
+ discountAmount.add(giveaway.price());
+ }
+ }
+
+ private void getDiscountInfo(int date, Bill bill) {
+ getDDayEventInfo(date);
+ getWeekdayEventInfo(date, bill.getNumberOfDessert());
+ getWeekendEventInfo(date, bill.getNumberOfMain());
+ getSpecialEventInfo(date);
+ }
+
+ private void getSpecialEventInfo(int date) {
+ SpecialEvent specialEvent = DiscountEvent.getSpecialEvent();
+ int discount = specialEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(specialEvent.getSpecialEventName());
+ }
+ }
+
+ private void getWeekendEventInfo(int date, int numberOfMain) {
+ WeekendEvent weekendEvent = DiscountEvent.getWeekendEvent();
+ int discount = weekendEvent.discount(date, numberOfMain);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekendEvent.getWeekendEventName());
+ }
+ }
+
+ private void getWeekdayEventInfo(int date, int numberOfDessert) {
+ WeekdayEvent weekdayEvent = DiscountEvent.getWeekdayEvent();
+ int discount = weekdayEvent.discount(date, numberOfDessert);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(weekdayEvent.getWeekdayEventName());
+ }
+ }
+
+ private void getDDayEventInfo(int date) {
+ DDayEvent dDayEvent = DiscountEvent.getDDayEvent();
+ int discount = dDayEvent.discount(date);
+ if (discount > MIN_AMOUNT) {
+ discountAmount.add(discount);
+ discountNames.add(dDayEvent.getDDayEventName());
+ }
+ }
+
+ public List<String> getDiscountNames() {
+ return discountNames;
+ }
+
+ public List<Integer> getDiscountAmount() {
+ return discountAmount;
+ }
+
+ public int getTotalDiscountAmount() {
+ return totalDiscountAmount;
+ }
+
+ public String getBadge() {
+ return badge;
+ }
+
+ public Giveaway getGiveaway() {
+ return giveaway;
+ }
+} | Java | ์ฝ๋ ์ปจ๋ฒค์
์ ์ง์ผ์ ํด๋น ๋ฐฉ์์ผ๋ก ๋ฐ๊ฟ์ฃผ์๋ฉด ์ข์ผ์ค๊ฑฐ ๊ฐ์์~!
```suggestion
this.totalDiscountAmount = discountAmount.stream()
.mapToInt(Integer::intValue)
.sum();
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.