code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,79 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.Message;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Benefit {
+ private int orderDate;
+ private int[] categoryCount;
+ Map<String, Integer> benefits;
+
+ public Benefit(int orderDate, int[] categoryCount, int totalPrice) {
+ this.orderDate = orderDate;
+ this.categoryCount = categoryCount;
+ benefits = new HashMap<>();
+ if (totalPrice < Constant.MIN_BENEFIT_PRICE.get()) {
+ return;
+ }
+ christmasBenefit();
+ weekBenefit();
+ starBenefit();
+ if (totalPrice >= Constant.PRESENT_COST.get()) {
+ presentBenefit();
+ }
+ }
+
+ public Map<String, Integer> getBenefits() {
+ return this.benefits;
+ }
+
+ public int getTotalBenefitPrice() {
+ int totalBenefitPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.benefits.entrySet()) {
+ int benefit = entry.getValue();
+ totalBenefitPrice += benefit;
+ }
+ return totalBenefitPrice;
+ }
+
+ public int getPresentPrice() {
+ if (this.benefits.containsKey(Message.PRESENT_BENEFIT.get())) {
+ return Constant.CHAMPAIGN_PRICE.get();
+ }
+ return Constant.ZERO.get();
+ }
+
+ private void christmasBenefit() {
+ if (orderDate > Constant.CHRISTMAS_DAY.get()) {
+ return;
+ }
+ int benefit = Constant.THOUSAND.get() + (orderDate - Constant.ONE.get()) * Constant.HUNDRED.get();
+ benefits.put(Message.D_DAY_BENEFIT.get(), benefit);
+ }
+
+ private void weekBenefit() {
+ if (orderDate % Constant.WEEKDAYS.get() == Constant.FRIDAY.get()
+ || orderDate % Constant.WEEKDAYS.get() == Constant.SATURDAY.get()) {
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.MAINMENU.get()];
+ benefits.put(Message.WEEKEND_BENEFIT.get(), benefit);
+ return;
+ }
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.DESSERT.get()];
+ benefits.put(Message.WEEKDAY_BENEFIT.get(), benefit);
+ }
+
+ private void starBenefit() {
+ if (orderDate != Constant.CHRISTMAS_DAY.get()
+ && orderDate % Constant.WEEKDAYS.get() != Constant.SUNDAY.get()) {
+ return;
+ }
+ benefits.put(Message.STAR_BENEFIT.get(), Constant.THOUSAND.get());
+ }
+
+ private void presentBenefit() {
+ benefits.put(Message.PRESENT_BENEFIT.get(), Constant.CHAMPAIGN_PRICE.get());
+ }
+} | Java | ์ ์ฝ๋์์๋ ๋ฐฐ์ด๋ง์ผ๋ก ํด๊ฒฐ์ด ๊ฐ๋ฅํด์ ๋ฐฐ์ด๋ก ์ฒ๋ฆฌํ๋๋ฐ ์ฌ๋ ค์ฃผ์ ๋งํฌ๋ฅผ ๋ณด๋๊น ์ปฌ๋ ์
ArrayList์ ์ฅ์ ์ด ๊ฐ๋ณ ๊ธธ์ด๋ง์ ์๋์๊ตฐ์. ๋ง์ด ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ์ด ์ ์ ์ ๊ฐ ์์ ๋ชฐ๋๋ ๋ถ๋ถ์ด์์ต๋๋ค. ํ๋์ฝ๋ฉํ๋ฉด์๋ ์ข์ ๋ฐฉ์์ด ์๋๋ผ๊ณ ๋๊ผ๋๋ฐ enum์ ์ฌ์ฉํ๋ฉด ๋์๋ค์... |
@@ -0,0 +1,96 @@
+package christmas.view;
+
+import christmas.util.Constant;
+import christmas.util.Message;
+import java.util.Map;
+
+import java.text.DecimalFormat;
+
+public class OutputView {
+ public static void printPreview(int orderDate) {
+ System.out.println("12์ " + orderDate + "์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!");
+ System.out.println();
+ }
+
+ public static void printOrder(Map<String, Integer> userOrder) {
+ System.out.println("<์ฃผ๋ฌธ ๋ฉ๋ด>");
+ for (Map.Entry<String, Integer> entry : userOrder.entrySet()) {
+ System.out.println(entry.getKey() + Message.SPACE.get() + entry.getValue() + Message.COUNT.get());
+ }
+ System.out.println();
+ }
+
+ public static void printTotalPrice(int totalPrice) {
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+
+ System.out.println("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>");
+ String formattedNumber = decimalFormat.format(totalPrice);
+ System.out.println(formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printPresent(int totalPrice) {
+ System.out.println("<์ฆ์ ๋ฉ๋ด>");
+ if (totalPrice < Constant.PRESENT_COST.get()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ System.out.println(Message.ONE_CHAMPAIGN.get());
+ System.out.println();
+ }
+
+ public static void printBenefits(Map<String, Integer> benefits) {
+ System.out.println("<ํํ ๋ด์ญ>");
+ if (benefits.isEmpty()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ for (Map.Entry<String, Integer> entry : benefits.entrySet()) {
+ System.out.print(entry.getKey() + ": -");
+ String fomattedNumber = decimalFormat.format(entry.getValue());
+ System.out.println(fomattedNumber + Message.WON.get());
+ }
+ System.out.println();
+ }
+
+ public static void printTotalBenefitPrice(int totalBenefitPrice) {
+ System.out.println("<์ดํํ ๊ธ์ก>");
+ if (totalBenefitPrice == Constant.ZERO.get()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ String formattedNumber = decimalFormat.format(totalBenefitPrice);
+ System.out.println(Message.HYPHEN.get() + formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printTotalPayment(int totalPayment) {
+ System.out.println("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>");
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ String formattedNumber = decimalFormat.format(totalPayment);
+ System.out.println(formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printEventBadge(int totalBenefitPrice) {
+ System.out.println("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+ if (totalBenefitPrice >= Constant.SANTA.get()) {
+ System.out.println("์ฐํ");
+ return;
+ }
+ if (totalBenefitPrice >= Constant.TREE.get()) {
+ System.out.println("ํธ๋ฆฌ");
+ return;
+ }
+ if (totalBenefitPrice >= Constant.STAR.get()) {
+ System.out.println("๋ณ");
+ return;
+ }
+ System.out.println(Message.NOTHING.get());
+ }
+} | Java | mvc์ ์ญํ ๋ถ๋ฆฌ์ ์ต์ํ์ง ์์์ ๊ทธ๋ฐ์ง View๊ฐ ์ฒ๋ฆฌํด๋ ๊ด์ฐฎ๋ค๊ณ ์๊ฐํ๋๋ฐ ๋ค์ ๋ณด๋๊น ๋ง์ํ์ ๋ถ๋ถ์ด ๋ง๋ ๊ฒ ๊ฐ๋ค์. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,135 @@
+package christmas;
+
+import christmas.model.OrderMenu;
+import christmas.util.Validator;
+
+import java.lang.reflect.Array;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ValidatorTest {
+ private List<Map<String, Integer>> menu = new ArrayList<>(List.of(
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ๋น์ด์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isDateNoneTest() {
+ assertThatThrownBy(() -> Validator.validateDate(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ์ซ์๊ฐ ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isDateInvalidTest() {
+ assertThatThrownBy(() -> Validator.validateDate("1a"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ๋ฒ์๋ฅผ ๋ฒ์ด๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void dateRangeTest() {
+ assertThatThrownBy(() -> Validator.validateDate("123"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ์ฃผ๋ฌธ์ด ๋น์ด์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOrderNoneTest() {
+ assertThatThrownBy(() -> Validator.validateOrder(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ์ฃผ๋ฌธ ์ค ๋น ๋ฌธ์์ด์ด ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isParsedNoneTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder(",ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,,๋ ๋์์ธ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder(",,,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์ฃผ๋ฌธ ํฌ๋งท์ด ์ฌ๋ฐ๋ฅด์ง ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isFormatWrongTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1-1,์ ๋ก์ฝ๋ผ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,---"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("๊ฐ์์ ์ซ์๊ฐ ์๋ ๊ฐ์ด ๋ค์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isNotNumberTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-2๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์ฃผ๋ฌธํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOrderInMenu() {
+ Map<String, Integer> order1 = Map.of("๋ ์๊ฟ", 1);
+ Map<String, Integer> order2 = Map.of("์์ก์ด์ํ", 2, "์ฐ์ ์ก์ฐ", 1);
+ Map<String, Integer> order3 = Map.of("์์ก์ด์ํ", 1, "์์ด์คํฌ๋ฆผ", 1);
+
+ assertThat(Validator.validateMenu(order1, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order2, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(false);
+ }
+
+ @DisplayName("0๊ฐ ์ดํ์ธ ๊ฐ์๊ฐ ์๋ค๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isCountValid() {
+ Map<String, Integer> order1 = Map.of("์์ด์คํฌ๋ฆผ", 0);
+ Map<String, Integer> order2 = Map.of("์์ก์ด์ํ", 1, "์์ด์คํฌ๋ฆผ", 0);
+
+ assertThat(Validator.validateMenu(order1, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order2, menu)).isEqualTo(true);
+ }
+
+ @DisplayName("20๊ฐ๊ฐ ๋์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isUnderTwenty() {
+ Map<String, Integer> order3 = Map.of("์์ก์ด์ํ", 21);
+ Map<String, Integer> order4 = Map.of("์์ก์ด์ํ", 10, "์์ด์คํฌ๋ฆผ", 11);
+
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order4, menu)).isEqualTo(true);
+ }
+
+ @DisplayName("์๋ฃ๋ง ์ฃผ๋ฌธํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOnlyBeverage() {
+ Map<String, Integer> order3 = Map.of("์ ๋ก์ฝ๋ผ", 1);
+ Map<String, Integer> order4 = Map.of("์ ๋ก์ฝ๋ผ", 3, "๋ ๋์์ธ", 1);
+
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order4, menu)).isEqualTo(true);
+ }
+} | Java | ํ
์คํธ๋ ๋ ์ ๊ฒฝ์จ์ผ๊ฒ ๊ตฐ์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,39 @@
+package christmas.util;
+
+public enum Constant {
+ NOT_IN_MENU(-1),
+ EPPETIZER(0),
+ MAINMENU(1),
+ DESSERT(2),
+ BEVERAGE(3),
+ CATEGORY_COUNT(4),
+ ZERO(0),
+ ONE(1),
+ THOUSAND(1000),
+ HUNDRED(100),
+ CHRISTMAS_DAY(25),
+ MIN_BENEFIT_PRICE(10000),
+ PRESENT_COST(120000),
+ CHAMPAIGN_PRICE(25000),
+ WEEKDAYS(7),
+ FRIDAY(1),
+ SATURDAY(2),
+ SUNDAY(3),
+ EVENT_PRICE(2023),
+ SANTA(20000),
+ TREE(10000),
+ STAR(5000),
+ MAX_MENU_COUNT(20),
+ KEY_INDEX(0),
+ VALUE_INDEX(1);
+
+ private final int value;
+
+ Constant(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return this.value;
+ }
+} | Java | ์์๋ฅผ ์ฒ๋ฆฌํ๋ค๋ ๊ฒ์๋ง ์ ๊ฒฝ์ฐ๋ค ๋ณด๋ ๋ฏธ์ฒ ์๊ฐ์ ๋ชปํ์ต๋๋ค. ๋ค์ ํ์ธํด๋ณด๋ ๊ฐ๋
์ฑ ์ธก๋ฉด์์๋ ๋ง์ด ๋ถํธํ ๊ฒ ๊ฐ์์. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ์ ๋ ์ด ๋ถ๋ถ์ ์ฒ๋ฆฌํ๋ฉด์ ์ข์ ๋ฐฉ์์ด ์๋๋ผ๊ณ ๋๊ผ๋๋ฐ, enum์ ํตํด ์ฒ๋ฆฌํ ์ ์๋จ ์๊ฐ์ ๋ชปํ๋ค์. ํด์ด๋ ์ฝ๋๋ฅผ ๋ณด๊ณ enum์ ์ ์ฒ๋ฆฌํ์
จ๋ค๊ณ ๋๊ผ๋๋ฐ ์ฐธ๊ณ ํด์ ์ ์ฉํด๋ด์ผ๊ฒ ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ๋ง์ํด์ฃผ์ ๋ถ๋ถ ๋ค์ ๋ณด๋๊น ํด๋์ค ์ด๋ฆ์ด ๋ด์ฉ์ ๋ค ํฌ๊ดํ์ง ๋ชปํด ์ด์ํ๊ฒ ๋๊ปด์ง๋ค์. ์ฃผ๋ฌธํ ๋ถ๋ถ์ ๋ค ์ฒ๋ฆฌํ๊ธฐ ์ํด ๋ ์ง๊ฐ ํ์ํ๋ฐ ํด๋์ค์ ์ด๋ฆ์ ๋ณ๊ฒฝํด๋ณด๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,47 @@
+package christmas.controller;
+
+import java.util.Map;
+
+import christmas.view.*;
+import christmas.model.*;
+
+public class MainController {
+ private OrderMenu orderMenu;
+
+ public MainController() {
+ orderMenu = new OrderMenu();
+ }
+
+ public void run() {
+ orderMenu.setOrderDate(InputView.readDate());
+ setReadOrder();
+
+ OutputView.printPreview(orderMenu.getOrderDate());
+ OutputView.printOrder(orderMenu.getUserOrder());
+ int totalPrice = orderMenu.getTotalPrice();
+ OutputView.printTotalPrice(totalPrice);
+ OutputView.printPresent(totalPrice);
+ benefitControl(totalPrice);
+ }
+
+ private void benefitControl(int totalPrice) {
+ Benefit benefit = new Benefit(orderMenu.getOrderDate(), orderMenu.getCategoryCount(), totalPrice);
+ OutputView.printBenefits(benefit.getBenefits());
+
+ int totalBenefitPrice = benefit.getTotalBenefitPrice();
+ OutputView.printTotalBenefitPrice(totalBenefitPrice);
+ OutputView.printTotalPayment(totalPrice - totalBenefitPrice + benefit.getPresentPrice());
+ OutputView.printEventBadge(totalBenefitPrice);
+ }
+
+ private void setReadOrder() {
+ Map<String, Integer> orderMenu;
+ try {
+ orderMenu = InputView.readOrder();
+ this.orderMenu.setUserOrder(orderMenu);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ setReadOrder();
+ }
+ }
+} | Java | MVC ๊ฐ๊ฐ์ ๋ถ๋ฆฌ๋์ด ์๋ ์์๋ค ๋ณด๋๊น ๊ฐ๊ฐ์ ๋ถ๋ฆฌ๋ ๊ฐ์ฒด๋ก ๋ณด๊ณ ์ธ์คํด์คํํด์ ์ฌ์ฉํ๋ ๊ฒ ๊ฐ์์. ๋ฌผ๋ก ์ด๊ฒ ์ ๋ต์ด๋ผ๋ ๊ฑด ์๋๋๋ค. ๋ง์ํ์ ๋๋ก ์ํ๋ฅผ ๊ฐ์ง์ง ์์ผ๋ ์คํํฑ ๋ฉ์๋๋ก ๋ง๋์ ๊ฒ๋ ํ ๊ฐ์ง ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
์ฐธ๊ณ ๋ก, ์คํํฑ ๋ฉ์๋๋ง์ผ๋ก ๊ตฌ์ฑ๋ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ฌธ์ ๋ฅผ ์ฐพ์๋ดค๋๋ฐ, ๋ง์ ๊ฒฝ์ฐ ๋ทฐ์์ ์ํ๋ฅผ ๊ฐ์ ธ์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ผ๋ฉฐ, ์คํํฑ ๋ฉ์๋์ ๊ฒฝ์ฐ ํ
์คํธ ์ ๋ชฉ ๊ฐ์ฒด๋ฅผ ๋ง๋ค๊ธฐ ์ด๋ ต๊ณ ์์์ด๋ ๋คํ์ฑ์ ์ฌ์ฉํ๊ธฐ ์ด๋ ค์์ ํ์ฅ์ฑ์ด๋ ์ ์ฐ์ฑ์ด ๋จ์ด์ง๋ค๊ณ ํ๋ค์. |
@@ -0,0 +1,42 @@
+import Customer from '../src/models/Customer';
+import Order from '../src/models/Order';
+
+describe('Customer ํด๋์ค', () => {
+ let customer;
+
+ beforeEach(() => {
+ customer = new Customer();
+ });
+
+ test('์ฃผ๋ฌธ์ด ์์ ๋, ๋ฑ์ง ๊ณ์ฐ ๊ฒฐ๊ณผ๋ null์ด ๋๋ค.', () => {
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBeNull();
+ });
+
+ test('์ ์ ํ ํ ์ธ ๊ธ์ก์ ๋ฐ๋ผ ์ฌ๋ฐ๋ฅธ ๋ฑ์ง๊ฐ ํ ๋น๋๋ค.', () => {
+ const order = new Order();
+ order.setDiscountAmount(10000);
+ customer.addOrder(order);
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBe('ํธ๋ฆฌ');
+ });
+
+ test('์ฌ๋ฌ ์ฃผ๋ฌธ์ ์ถ๊ฐํ์ ๋, ์ด ํ ์ธ ๊ธ์ก์ ๋ฐ๋ฅธ ๋ฑ์ง๊ฐ ํ ๋น๋๋ค.', () => {
+ const order1 = new Order();
+ order1.setDiscountAmount(3000);
+ const order2 = new Order();
+ order2.setDiscountAmount(2000);
+ customer.addOrder(order1);
+ customer.addOrder(order2);
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBe('๋ณ');
+ });
+
+ test('ํ ์ธ ๊ธ์ก์ด 5000์ ์ดํ์ผ ๋ ๋ฑ์ง๋ null๋ก ํ์๋๋ค.', () => {
+ const order = new Order();
+ order.setDiscountAmount(4000);
+ customer.addOrder(order);
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBeNull();
+ });
+}); | JavaScript | ์ง๊ธ์ `ํธ๋ฆฌ`์ ๋ํ ํ
์คํธ ์ผ์ด์ค๋ง ์๋๋ฐ, `๋ณ`๊ณผ `์ฐํ` ํ
์คํธ ์ผ์ด์ค๊น์ง ๋ชจ๋ ํฌํจํ๋ฉด ํ
์คํธ ์ ๋ขฐ๋๊ฐ ๋์์ง ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,48 @@
+import Menu from '../src/models/Menu';
+import { MenuConstants } from '../src/constants/MenuConstants';
+
+describe('Menu ํด๋์ค', () => {
+ let menu;
+
+ beforeEach(() => {
+ menu = new Menu();
+ });
+
+ test('๋ฉ๋ด ํญ๋ชฉ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์ด๊ธฐํ๋์ด์ผ ํ๋ค.', () => {
+ expect(menu.getItem('ํฐ๋ณธ์คํ
์ดํฌ')).toEqual({
+ name: 'ํฐ๋ณธ์คํ
์ดํฌ',
+ price: 55000,
+ category: 'MAINS',
+ });
+ expect(menu.getItem('์์ ์๋ฌ๋')).toEqual({
+ name: '์์ ์๋ฌ๋',
+ price: 8000,
+ category: 'APPETIZERS',
+ });
+ });
+
+ test('์กด์ฌํ์ง ์๋ ๋ฉ๋ด ํญ๋ชฉ์ ๋ํด null์ ๋ฐํํด์ผ ํ๋ค.', () => {
+ expect(menu.getItem('์์ก์ด์คํ')).toBeNull();
+ expect(menu.getItem('1234')).toBeNull();
+ expect(menu.getItem('์คํ
์ดํฌ@')).toBeNull();
+ });
+
+ test('๋ชจ๋ ๋ฉ๋ด ์นดํ
๊ณ ๋ฆฌ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ๋ก๋๋์ด์ผ ํ๋ค.', () => {
+ Object.keys(MenuConstants).forEach((category) => {
+ Object.keys(MenuConstants[category]).forEach((itemName) => {
+ const menuItem = menu.getItem(itemName);
+ expect(menuItem).not.toBeNull();
+ expect(menuItem.category).toBe(category);
+ });
+ });
+ });
+
+ test('๊ฐ ๋ฉ๋ด ํญ๋ชฉ์ ๊ฐ๊ฒฉ์ด ์ ํํด์ผ ํจ', () => {
+ Object.keys(MenuConstants).forEach((category) => {
+ Object.entries(MenuConstants[category]).forEach(([itemName, price]) => {
+ const menuItem = menu.getItem(itemName);
+ expect(menuItem.price).toBe(price);
+ });
+ });
+ });
+}); | JavaScript | ์ฌ๊ธฐ ๋ ํ
์คํธ ๋ชจ๋ ์ฌ๋ฌ ๊ฐ์ `expect()`๋ฅผ ๊ฐ์ง๊ณ ์๋๋ฐ์. `expect()`ํ๋ ๋ถ๋ถ์ ๊ตฌ์กฐ๊ฐ ๋น์ทํ๋๊น "๋ฉ๋ด ํญ๋ชฉ ์ด๊ธฐํ ํ
์คํธ"์ "์กด์ฌํ์ง ์๋ ๋ฉ๋ด ํญ๋ชฉ ํ
์คํธ"๋ฅผ `test.each()`๋ก ๋ณ๊ฒฝํ๋ ๊ฑด ์ด๋จ๊น์?. ํ๋ก๋์
์ฝ๋๋ฅผ ์์ฑํ ๋ ์ค๋ณต๋๋ ๋ถ๋ถ์ ์ ๊ฑฐํ๋ ๊ฒ์ฒ๋ผ, ํ
์คํธ ์ฝ๋๋ ๋ง์ฐฌ๊ฐ์ง๋ก ์ค๋ณต์ ์ ๊ฑฐํ๋ ๋ฆฌํฉํฐ๋ง์ด ํ์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค! |
@@ -0,0 +1,73 @@
+import OrderValidator from '../src/validators/OrderValidator';
+import Menu from '../src/models/Menu';
+import { ValidatorConstants } from '../src/validators/constants/ValidatorConstants';
+
+describe('OrderValidator ํด๋์ค', () => {
+ let mockMenu;
+
+ beforeEach(() => {
+ mockMenu = new Menu();
+ });
+
+ describe('validateOrderItems ๋ฉ์๋', () => {
+ test('์ ํจํ ์ฃผ๋ฌธ ํญ๋ชฉ์ ๋ํด ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const orderItems = [{ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).not.toThrow();
+ });
+
+ test('์กด์ฌํ์ง ์๋ ๋ฉ๋ด ํญ๋ชฉ์ ๋ํด ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [{ name: '๋ฏธ์ง์๋ฉ๋ด', quantity: 1 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+
+ test('์๋ฃ๋ง ํฌํจ๋ ์ฃผ๋ฌธ ์ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [{ name: '์ ๋ก์ฝ๋ผ', quantity: 2 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.ONLY_BEVERAGE_ERROR),
+ );
+ });
+
+ test('์ฃผ๋ฌธ ํญ๋ชฉ์ ์ด ์๋์ด 20๊ฐ๋ฅผ ์ด๊ณผํ๋ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = new Array(21).fill({ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 });
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+ test('์ฃผ๋ฌธ ํญ๋ชฉ์ ์ด ์๋์ด 20๊ฐ ์ดํ์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const orderItems = new Array(20).fill({ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 });
+ expect(() => OrderValidator.validateTotalQuantity(orderItems)).not.toThrow();
+ });
+
+ test('์ฃผ๋ฌธ ์๋์ด 0 ์ดํ์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [{ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 0 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+
+ test('์๋์ด 1 ์ด์์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const item = { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 };
+ expect(() => OrderValidator.validateQuantity(item)).not.toThrow();
+ });
+
+ test('์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ํฌํจ๋ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [
+ { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 },
+ { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 },
+ ];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+
+ test('์์๊ณผ ์๋ฃ๊ฐ ํผํฉ๋ ์ ํจํ ์ฃผ๋ฌธ์ ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const orderItems = [
+ { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 },
+ { name: '์ ๋ก์ฝ๋ผ', quantity: 2 },
+ ];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).not.toThrow();
+ });
+ });
+}); | JavaScript | `Validator` ํ
์คํธ ํ์ผ์์๋ ์์ธ๊ฐ ๋ฐ์ํ์ ๋ ์๋ฌ์ ์ ํ๊ณผ ๋ฉ์์ง ํฌํจ ์ฌ๋ถ๋ฅผ ๊ฒ์ฌํ๊ณ ์๋๋ฐ์. ๋ค๋ฅธ ๊ณณ์ ์์ธ ํ
์คํธ์์๋ ๋ฉ์์ง ๊ฒ์ฌ ์์ด ์์ธ๊ฐ ๋ฐ์ํ๋์ง๋ง(`toThrow()`) ๊ฒ์ฌํ๋ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,56 @@
+import InputView from '../views/InputView';
+import OutputView from '../views/OutputView';
+import OrderService from '../services/OrderService';
+import DiscountService from '../services/DiscountService';
+import Customer from '../models/Customer';
+import { DateFormatter } from '../utils/DateFormatter';
+
+export default class EventController {
+ #orderService;
+
+ #customer;
+
+ #discountService;
+
+ constructor() {
+ this.#orderService = new OrderService();
+ this.#customer = new Customer();
+ this.#discountService = new DiscountService();
+ }
+
+ async start() {
+ OutputView.printWelcomeMessage();
+ await this.handleOrderProcess();
+ }
+
+ async handleOrderProcess() {
+ try {
+ const inputDate = await this.getDateFromUser();
+ await this.handleMenuOrderProcess(inputDate);
+ } catch (error) {
+ OutputView.printErrorMessage(error.message);
+ await this.handleOrderProcess();
+ }
+ }
+
+ async getDateFromUser() {
+ const day = await InputView.readDate();
+ return DateFormatter.createDateFromDay(day);
+ }
+
+ async handleMenuOrderProcess(inputDate) {
+ try {
+ const inputMenuItems = await InputView.readMenu();
+ const order = this.#orderService.createOrder(inputDate, inputMenuItems);
+ order.applyDiscounts(this.#discountService, inputDate);
+ this.#customer.addOrder(order);
+ this.#customer.calculateBadge();
+ OutputView.printDay(inputDate);
+ OutputView.printOrderDetails(order);
+ OutputView.printBadge(this.#customer);
+ } catch (error) {
+ OutputView.printErrorMessage(error.message);
+ await this.handleMenuOrderProcess(inputDate);
+ }
+ }
+} | JavaScript | ํจ์ ๋ผ์ธ ์๊ฐ ๋ฑ 15๋ผ์ธ์ธ ๊ฒ ๊ฐ๋ค์. ๋ง์ฝ ์ด๋ค ์ถ๋ ฅ์ด ํ๋ ์ถ๊ฐ๋๋ค๋ฉด ์ฌ๊ธฐ์ ์ถ๊ฐํด์ผ ํ ํ
๋ฐ, ๊ทธ๋ฌ๋ฉด ํจ์ ๋ผ์ธ ์๊ฐ 15๋ผ์ธ์ ๋๊ธธ ์๋ ์์ ๊ฒ ๊ฐ์์.
ํจ์ ๋ผ์ธ ์ ์ ํ์ด ์๋ ๊ฒ์ 15๋ผ์ธ์ด๋ผ๋ ๊ฒ ์ค์ํด์๋ผ๊ธฐ๋ณด๋ค ๊ทธ๋งํผ **ํจ์๋ฅผ ์ ๋ถ๋ฆฌํ์** ๋ ์๋ฏธ์ธ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋์ ํจ์์ ๋ผ์ธ ์๊ฐ ๊ฐ๋น๊ฐ๋นํ๋ค๋ ๊ฒ์, ๋ฆฌํฉํฐ๋ง์ ์ ํธ๊ฐ ์๋๊น ์ถ์ด์๐ค
์ด ๋ฉ์๋๋ ๋์์ ์ฌ๋ฌ ๊ฐ์ง ์ผ์ ์ฒ๋ฆฌํ๊ณ ์๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋๋ฐ์(์
๋ ฅ ๋ฐ๊ธฐ, ์ฃผ๋ฌธ ์์ฑ, ๊ฐ์ข
ํ ์ธ ์ ์ฉ, ์ถ๋ ฅ, ์
๋ ฅ ์์ธ ์ฒ๋ฆฌ ๋ฐ ์ฌ์
๋ ฅ ๋ฐ๊ธฐ ๋ฑ). ๋ฉ์๋๊ฐ ํ๋์ ์ญํ ๋ง ์ํํ ์ ์๋๋ก ๋ถ๋ฆฌํ๋ ๊ฒ์ ์ด๋จ๊น์? |
@@ -0,0 +1,30 @@
+export default class Customer {
+ #orders;
+
+ #badge;
+
+ static BADGE_CRITERIA = [
+ { name: '์ฐํ', amount: 20000 },
+ { name: 'ํธ๋ฆฌ', amount: 10000 },
+ { name: '๋ณ', amount: 5000 },
+ ];
+
+ constructor() {
+ this.#orders = [];
+ this.#badge = null;
+ }
+
+ addOrder(order) {
+ this.#orders.push(order);
+ }
+
+ calculateBadge() {
+ const totalDiscount = this.#orders.reduce((sum, order) => sum + order.getDiscountAmount(), 0);
+ const badge = Customer.BADGE_CRITERIA.find((badgeName) => totalDiscount >= badgeName.amount);
+ this.#badge = badge ? badge.name : null;
+ }
+
+ getBadge() {
+ return this.#badge;
+ }
+} | JavaScript | ์์๋ฅผ ํ์ผ๋ก ๋ง๋ ๋ค๋ฉด ์์ ์ด ํ์ํ ๋ ์ฐพ๊ธฐ๊ฐ ์์ํ๊ณ , ๋ฐฐ์ง ์ ๋ณด๊ฐ ๋์ด๋๊ฑฐ๋ ์ค์ด๋ค์ด๋ ๊ด๋ฆฌํ๊ธฐ ํธ๋ฆฌํ ๊ฒ ๊ฐ์๋ฐ์. ํ์ผ๋ก ๋ง๋ค์ง ์๊ณ ์ฌ๊ธฐ์ ์์ฑํ์ ์ด์ ๊ฐ ์๋์? |
@@ -0,0 +1,81 @@
+import { OrderConstants } from './constants/OrderConstants';
+
+export default class Order {
+ #menuItems;
+
+ #totalAmount;
+
+ #discountAmount;
+
+ #gift;
+
+ #discountDetails;
+
+ constructor() {
+ this.#menuItems = new Map();
+ this.#totalAmount = 0;
+ this.#discountAmount = 0;
+ this.#gift = null;
+ this.#discountDetails = {};
+ }
+
+ applyDiscounts(discountService, date) {
+ const discountResults = discountService.applyDiscounts(this, date);
+ this.setDiscountDetails(discountResults);
+ this.checkForGift();
+ }
+
+ addMenuItem(menuItem, quantity) {
+ this.#menuItems.set(menuItem.name, { ...menuItem, quantity });
+ this.#totalAmount += menuItem.price * quantity;
+ }
+
+ addDiscountDetail(discountName, discountAmount) {
+ this.#discountDetails[discountName] =
+ (this.#discountDetails[discountName] || 0) + discountAmount;
+ this.#discountAmount += discountAmount;
+ }
+
+ setDiscountDetails(discountDetails) {
+ this.#discountDetails = { ...discountDetails };
+ this.#discountAmount = Object.values(this.#discountDetails).reduce(
+ (sum, amount) => sum + amount,
+ 0,
+ );
+ }
+
+ checkForGift() {
+ if (this.#totalAmount >= OrderConstants.GIFT_THRESHOLD_AMOUNT) {
+ this.#gift = `${OrderConstants.GIFT_NAME} ${OrderConstants.GIFT_QUANTITY}๊ฐ`;
+ }
+ }
+
+ getDiscountDetails() {
+ return this.#discountDetails;
+ }
+
+ getTotalAmount() {
+ return this.#totalAmount;
+ }
+
+ getFinalAmount() {
+ const giftDiscount = this.#discountDetails[OrderConstants.GIFT_EVENT_TITLE] || 0;
+ return this.#totalAmount - (this.#discountAmount - giftDiscount);
+ }
+
+ setDiscountAmount(discountAmount) {
+ this.#discountAmount = discountAmount;
+ }
+
+ getDiscountAmount() {
+ return this.#discountAmount;
+ }
+
+ getItems() {
+ return Array.from(this.#menuItems.values());
+ }
+
+ getGift() {
+ return this.#gift;
+ }
+} | JavaScript | ์ ๋ `Model`์ ์ฆ์ ๋ฉ๋ด์ ๋ํ ์ ๋ณด(๋ฐ์ดํฐ)๋ง ์ ์ฅํ๊ณ , ๊ทธ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ '`์ฆ์ ๋ฉ๋ด` `๊ฐ์`๊ฐ'์ ๊ฐ์ด ํฌ๋งทํ
ํ๋ ๊ฒ์ `View`์ ์ญํ ์ด๋ผ๊ณ ์๊ฐํด์.
๋ง์ฝ ์ฆ์ ๋ฉ๋ด ๋ฐ์ดํฐ์ ๋ํด ๋ค๋ฅธ ํ์์ผ๋ก ์ถ๋ ฅํ๋ ๋ทฐ๊ฐ ์ฌ๋ฌ ๊ฐ ์๊ธด๋ค๊ณ ๊ฐ์ ํด ๋ด
์๋ค. ์ง๊ธ ์ฝ๋๋ฐฉ์๋๋ก๋ผ๋ฉด ๊ฐ ๋ทฐ์์ ๋ํ๋ผ ์ถ๋ ฅ ํ์์ `Model`์์ ์ํํด์ผ ํฉ๋๋ค. ํ์ง๋ง ์ด๊ฑด `Model`์ด `View`์ ์์กดํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค. ์ถ๋ ฅ ํ์์ด ๋ณ๊ฒฝ๋์์ ๋ `Model`์ ๋ฉ์๋๋ฅผ ๋ณ๊ฒฝํ๊ฒ ๋ ํ
๋๊น์. ๋ `Model`์ ์ญํ ์ ๋ฒ์ด๋๋ ๊ฒ์ด๊ธฐ๋ ํฉ๋๋ค.
๊ทธ๋์ ์ ๋ ์ด ๋ฉ์๋๋ฅผ ์ถ๋ ฅ์ ๋ด๋นํ๋ `View` ์ชฝ์ผ๋ก ์ฎ๊ธฐ๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ์๋ฐ, ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,6 @@
+export const OrderConstants = {
+ GIFT_THRESHOLD_AMOUNT: 120000,
+ GIFT_EVENT_TITLE: '์ฆ์ ์ด๋ฒคํธ',
+ GIFT_NAME: '์ดํ์ธ',
+ GIFT_QUANTITY: 1,
+}; | JavaScript | ์ง๊ธ์ ์ฆ์ ์ด๋ฒคํธ๊ฐ ์ดํ์ธ 1๊ฐ๋ง ์ฃผ๊ณ ์๋๋ฐ์. ๋ง์ฝ ์ด ์ด๋ฒคํธ๊ฐ ํ์ฅ๋๋ค๋ฉด, ๋ฐฐ์ง ์ด๋ฒคํธ์ฒ๋ผ ๊ธ์ก์ ๋ฐ๋ผ ๋ค๋ฅธ ์ ๋ฌผ์ ์ฆ์ ํ๊ฒ ๋ ์๋ ์์ ๊ฒ ๊ฐ์์. Strategy ํจํด์ ์ ํํ์ ์ด์ ๋ ์ ์ง๋ณด์์ ๋ณ๊ฒฝ์ ์ฉ์ดํด์๋ผ๊ณ ์๊ฐ๋๋๋ฐ์. ๊ทธ๋งํผ ์์๋ฅผ ์ ์ธํ ๋์๋ ํ์ฅ์ฑ์ ์ฑ๊ธฐ๋ฉด ๋ ์ข์ง ์์์๊น ์๊ฐํด๋ด
๋๋ค! |
@@ -0,0 +1,46 @@
+import ChristmasDiscountStrategy from './strategies/ChristmasDiscountStrategy';
+import WeekdayDiscountStrategy from './strategies/WeekdayDiscountStrategy';
+import WeekendDiscountStrategy from './strategies/WeekendDiscountStrategy';
+import SpecialDiscountStrategy from './strategies/SpecialDiscountStrategy';
+import GiftChampagneStrategy from './strategies/GiftChampagneStrategy';
+
+export default class DiscountService {
+ #strategies;
+
+ constructor() {
+ this.#strategies = {
+ christmas: new ChristmasDiscountStrategy(),
+ special: new SpecialDiscountStrategy(),
+ weekday: new WeekdayDiscountStrategy(),
+ weekend: new WeekendDiscountStrategy(),
+ giftChampagne: new GiftChampagneStrategy(),
+ };
+ }
+
+ applyDiscounts(order, date) {
+ const MINIMUM_AMOUNT_FOR_DISCOUNTS = 10000;
+ if (order.getTotalAmount() >= MINIMUM_AMOUNT_FOR_DISCOUNTS) {
+ const discountResults = this.calculateTotalDiscounts(order, date);
+ const totalDiscountAmount = this.calculateTotalDiscountAmount(discountResults);
+ order.setDiscountAmount(totalDiscountAmount);
+ return discountResults;
+ }
+ return {};
+ }
+
+ calculateTotalDiscounts(order, date) {
+ const discountResults = {};
+ Object.keys(this.#strategies).forEach((strategyKey) => {
+ const strategy = this.#strategies[strategyKey];
+ const discountResult = strategy.applyDiscount(order, date);
+ if (discountResult.amount > 0) {
+ discountResults[discountResult.name] = discountResult.amount;
+ }
+ });
+ return discountResults;
+ }
+
+ calculateTotalDiscountAmount(discountResults) {
+ return Object.values(discountResults).reduce((sum, amount) => sum + amount, 0);
+ }
+} | JavaScript | ์ด ๋ถ๋ถ์ ์ด๋ ๊ฒ ๋ฐ๊ฟ ์ ์์ ๊ฒ ๊ฐ์์!
```javascript
Object.values(this.#strategies).forEach((strategy) => {
const discountResult = strategy.applyDiscount(order, date);
// ...
});
``` |
@@ -0,0 +1,5 @@
+export default class IDiscountStrategy {
+ applyDiscount(order, date) {
+ throw new Error('[ERROR] ํ์ ํด๋์ค์์ applyDiscount ๋ฉ์๋๋ฅผ ๊ตฌํํด์ผ ํฉ๋๋ค.');
+ }
+} | JavaScript | ํ์ผ๋ช
๊ณผ ํด๋์ค๋ช
๋งจ ์์ `I`๊ฐ ๋ถ์ด ์๋๋ฐ, ํน์ ์๋ํ์ ๊ฑด๊ฐ์? ์๋ํ์ ๊ฑฐ๋ผ๋ฉด ์ด๋ค ์๋ฏธ์ธ์ง ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,16 @@
+import IDiscountStrategy from './IDiscountStrategy';
+import { DiscountStrategyConstants } from './constants/DiscountStrategyConstants';
+
+export default class SpecialDiscountStrategy extends IDiscountStrategy {
+ applyDiscount(order, date) {
+ const dayOfWeek = date.getDay();
+ const isSunday = dayOfWeek === 0;
+ const isChristmas = date.getDate() === 25;
+
+ if (isSunday || isChristmas) {
+ return { name: DiscountStrategyConstants.SPECIAL_DISCOUNT, amount: 1000 };
+ }
+
+ return { name: DiscountStrategyConstants.SPECIAL_DISCOUNT, amount: 0 };
+ }
+} | JavaScript | ํน๋ณ ํ ์ธ์ด ๋ชจ๋ ์ผ์์ผ (+25์ผ)์ด๋ผ๋ ์ ์ ์ด์ฉํ์
จ๋ค์!
์ ๋ ๋ณ ํ์๊ฐ ๋ ๋ ์ง๋ฅผ ํ๋ํ๋ ์์ ๋ฐฐ์ด์ ๋ด์์ ๊ด๋ฆฌํ๋๋ฐ์. ์ฎ๊ฒจ ์ ์ ๋ ์คํ๋ผ๋ ๋๋ค๋ฉด ํฐ์ผ์ด์ง๋ง๐
, ์ด๋ ๊ฒ ํ ์ด์ ๋ ํน๋ณ ํ ์ธ ๋ ์ง๊ฐ ๋ณ๊ฒฝ๋ ์ ์์ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์
๋๋ค. ์๊ตฌ์ฌํญ์์ "ํน๋ณ ํ ์ธ"์ ์ค๋ช
ํ ๋, '๋ฌ๋ ฅ์ ๋ณ์ด ํ์๋ ๋ ์ง'๋ผ๊ณ ์ค๋ช
ํ๋๋ผ๊ตฌ์. ๋ง์ฝ '๋ชจ๋ ์ผ์์ผ๊ณผ ํฌ๋ฆฌ์ค๋ง์ค ๋น์ผ'์ฒ๋ผ ์ค๋ช
ํ๋ค๋ฉด ์ ๋ ์ด๋ฐ ์ฝ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ์ ๊ฒ ๊ฐ๋ค์.
๊ตฌํ ๋ฐฉ์์ ์ ๋ต์ ์์ง๋ง ์ ์๊ฐ์ ํ ๋ฒ ๊ณต์ ๋๋ฆฌ๊ณ ์ถ์์ด์๐ |
@@ -0,0 +1,19 @@
+import IDiscountStrategy from './IDiscountStrategy';
+import { DiscountStrategyConstants } from './constants/DiscountStrategyConstants';
+
+export default class WeekdayDiscountStrategy extends IDiscountStrategy {
+ applyDiscount(order, date) {
+ const dayOfWeek = date.getDay();
+ const isWeekday = dayOfWeek >= 0 && dayOfWeek <= 4;
+
+ if (isWeekday) {
+ const DESSERT_DISCOUNT = 2023;
+ const discountAmount = order
+ .getItems()
+ .filter((item) => item.category === 'DESSERTS')
+ .reduce((total, item) => total + item.quantity * DESSERT_DISCOUNT, 0);
+ return { name: DiscountStrategyConstants.WEEKDAY_DISCOUNT, amount: discountAmount };
+ }
+ return { name: DiscountStrategyConstants.WEEKDAY_DISCOUNT, amount: 0 };
+ }
+} | JavaScript | `0`, `4`์ ๊ฐ์ ์ซ์๋ฅผ `SUNDAY`, `THURSDAY`์ฒ๋ผ ์์ํํด์ ์ฌ์ฉํ๋ฉด ์ฝ๋ ๊ฐ๋
์ฑ์ ๋ ์ฑ๊ธธ ์ ์์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,36 @@
+import { ValidatorConstants } from './constants/ValidatorConstants';
+
+export const InputValidator = {
+ Day: {
+ validateDay(input) {
+ const dayPattern = /^\d+$/;
+ if (!dayPattern.test(input)) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+ const day = parseInt(input, 10);
+ if (day < 1 || day > 31) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+
+ return day;
+ },
+ },
+
+ Menu: {
+ validateMenu(input) {
+ const menuSelections = input.split(',');
+ const selectionPattern = /^[๊ฐ-ํฃ]+-\d+$/;
+ const validSelections = menuSelections.map((selection) => {
+ const trimmedSelection = selection.trim();
+ if (!selectionPattern.test(trimmedSelection)) {
+ throw new Error(ValidatorConstants.INVALID_ORDER_ERROR);
+ }
+ const [name, quantity] = trimmedSelection.split('-');
+
+ return { name, quantity: parseInt(quantity, 10) };
+ });
+
+ return validSelections;
+ },
+ },
+}; | JavaScript | ๊ฐ๊ฐ์ validation(์ ๊ทํํ์ ํจํด & ๋ฒ์)์ ๋ ๊ฐ์ ํจ์๋ก ๋ถ๋ฆฌํด ์ ์ธํ๊ณ ํธ์ถํด์ ์ฌ์ฉํ๋ ๊ฑด ์ด๋จ๊น์? ์๋ํด์ ํ๊บผ๋ฒ์ ์์ฑํ์ ๊ฒ ๊ฐ์๋ฐ, ๋ง์ฝ ๋ง๋ค๋ฉด ์ด์ ๊ฐ ๊ถ๊ธํด์! |
@@ -0,0 +1,36 @@
+import { ValidatorConstants } from './constants/ValidatorConstants';
+
+export const InputValidator = {
+ Day: {
+ validateDay(input) {
+ const dayPattern = /^\d+$/;
+ if (!dayPattern.test(input)) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+ const day = parseInt(input, 10);
+ if (day < 1 || day > 31) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+
+ return day;
+ },
+ },
+
+ Menu: {
+ validateMenu(input) {
+ const menuSelections = input.split(',');
+ const selectionPattern = /^[๊ฐ-ํฃ]+-\d+$/;
+ const validSelections = menuSelections.map((selection) => {
+ const trimmedSelection = selection.trim();
+ if (!selectionPattern.test(trimmedSelection)) {
+ throw new Error(ValidatorConstants.INVALID_ORDER_ERROR);
+ }
+ const [name, quantity] = trimmedSelection.split('-');
+
+ return { name, quantity: parseInt(quantity, 10) };
+ });
+
+ return validSelections;
+ },
+ },
+}; | JavaScript | ์ด ๋ก์ง์ด๋ผ๋ฉด ์ด๋ฐ ์
๋ ฅ์ ๋ฃ์ด๋ ์ ์์ ์ผ๋ก ์๋ํ ๊ฒ ๊ฐ์์. ํน์ ๋ค๋ฅธ ๋ถ๋ถ์์ ๊ฒ์ฌํ๊ณ ์๋๋ฐ ์ ๊ฐ ๋์น ๊ฒ์ผ๊น์?
```
๋ฐ๋นํ๋ฆฝ-1,,,,,,,ํํ์ค-2
๋ฐ๋นํ๋ฆฝ-1,,,ํํ์ค-2,,
``` |
@@ -0,0 +1,87 @@
+const express = require('express')
+const http = require('http');
+const path = require('path');
+
+const bodyParser = require('body-parser');
+const static = require('serve-static');
+const multer = require("multer")
+
+const app = express();
+
+app.set('port', process.env.PORT || 3000);
+
+app.use(bodyParser.urlencoded({ extended: false }))
+app.use(bodyParser.json())
+
+app.use('/public', static(path.join(__dirname, 'public')));
+app.use('/uploads', static(path.join(__dirname, 'uploads')))
+
+const upload = multer({
+ storage: multer.diskStorage({
+ destination: function (req, file, cb) {
+ cb(null, './uploads/');
+ },
+ filename: function (req, file, cb) {
+ cb(null, file.originalname);
+ }
+ }),
+}).single('userfile');
+
+app.post("/save", function (req, res) {
+ try {
+ upload(req, res, function (err) {
+ var name = req.body.name;
+ var date = req.body.date;
+ var content = req.body.content;
+ var filename = req.file.filename;
+ console.log(filename);
+ res.writeHead(200, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write(`
+ <head>
+ <meta charset="UTF-8">
+ <link rel="stylesheet" href="/public/stylesheet/momo.css">
+ <title>Document</title>
+ </head>
+ <form method="GET" action="/" id="re-form">
+ <table class="header-table">
+ <thead>
+ <th class="table-head">๋์ ๋ฉ๋ชจ</th>
+ </thead>
+ <tbody class="table-body">
+ <tr>
+ <td>${name},${date},${content}๋ฉ๋ชจ๊ฐ ์ ์ฅ๋์์ต๋๋ค.</td>
+ </tr>
+ <tr>
+ <td colspan="2" class="upload-display">
+ <div class="upload-thumb-wrap"><img class="upload-thumb" src="/uploads/${filename}"></div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <table class="footer-table">
+ <tbody>
+ <tr><td id="re-layor"><button id="redirect" form = "re-form" type="submit" >๋ค์์์ฑ</button></td></tr>
+ </tbody>
+ </table>
+ </form>
+ `);
+ res.end();
+ });
+
+ } catch (err) {
+ console.dir(err.stack);
+
+ res.writeHead(400, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write('<div><p>๋ฉ๋ชจ ์ ์ฅ ์ ์๋ฌ ๋ฐ์</p></div>');
+ res.end();
+ }
+
+});
+
+app.get('/', function (req, res) {
+ res.sendFile(__dirname + "/view/memo/memo.html");
+});
+
+http.createServer(app).listen(app.get('port'), function () {
+ console.log("์๋ฒ์์");
+});
\ No newline at end of file | JavaScript | String์ด ์๋ html์ด๋ ejs ํ์ผ๋ก ๋ณด๋ด๋ ๊ฒ์ด ์ข์ต๋๋ค. (Feat. ์ฟ ๋ง์จฉ)
save.ejs๋ก ๋ถ๋ฆฌํด ์ฃผ์ธ์. |
@@ -0,0 +1,87 @@
+const express = require('express')
+const http = require('http');
+const path = require('path');
+
+const bodyParser = require('body-parser');
+const static = require('serve-static');
+const multer = require("multer")
+
+const app = express();
+
+app.set('port', process.env.PORT || 3000);
+
+app.use(bodyParser.urlencoded({ extended: false }))
+app.use(bodyParser.json())
+
+app.use('/public', static(path.join(__dirname, 'public')));
+app.use('/uploads', static(path.join(__dirname, 'uploads')))
+
+const upload = multer({
+ storage: multer.diskStorage({
+ destination: function (req, file, cb) {
+ cb(null, './uploads/');
+ },
+ filename: function (req, file, cb) {
+ cb(null, file.originalname);
+ }
+ }),
+}).single('userfile');
+
+app.post("/save", function (req, res) {
+ try {
+ upload(req, res, function (err) {
+ var name = req.body.name;
+ var date = req.body.date;
+ var content = req.body.content;
+ var filename = req.file.filename;
+ console.log(filename);
+ res.writeHead(200, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write(`
+ <head>
+ <meta charset="UTF-8">
+ <link rel="stylesheet" href="/public/stylesheet/momo.css">
+ <title>Document</title>
+ </head>
+ <form method="GET" action="/" id="re-form">
+ <table class="header-table">
+ <thead>
+ <th class="table-head">๋์ ๋ฉ๋ชจ</th>
+ </thead>
+ <tbody class="table-body">
+ <tr>
+ <td>${name},${date},${content}๋ฉ๋ชจ๊ฐ ์ ์ฅ๋์์ต๋๋ค.</td>
+ </tr>
+ <tr>
+ <td colspan="2" class="upload-display">
+ <div class="upload-thumb-wrap"><img class="upload-thumb" src="/uploads/${filename}"></div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <table class="footer-table">
+ <tbody>
+ <tr><td id="re-layor"><button id="redirect" form = "re-form" type="submit" >๋ค์์์ฑ</button></td></tr>
+ </tbody>
+ </table>
+ </form>
+ `);
+ res.end();
+ });
+
+ } catch (err) {
+ console.dir(err.stack);
+
+ res.writeHead(400, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write('<div><p>๋ฉ๋ชจ ์ ์ฅ ์ ์๋ฌ ๋ฐ์</p></div>');
+ res.end();
+ }
+
+});
+
+app.get('/', function (req, res) {
+ res.sendFile(__dirname + "/view/memo/memo.html");
+});
+
+http.createServer(app).listen(app.get('port'), function () {
+ console.log("์๋ฒ์์");
+});
\ No newline at end of file | JavaScript | ๋น ์ค๊ณผ ๋ค์ฌ์ฐ๊ธฐ ์ ๋ฆฌํด ์ฃผ์ธ์. |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ๊ฐ ๊ธฐ๋ฌผ ๋ค์ ๋์จ ์ซ์๊ฐ ์ ์์ธ ๊ฒ์ผ๋ก ๋ณด์ด๋๋ฐ,
์ ์ ๊ณ์ฐ์ ๋ํ ๊ฒ๋ ๊ธฐ๋ฅ ๋ชฉ๋ก์ผ๋ก ๋นผ๋ฉด ์ด๋จ๊น์?
ํด๋น ์ฝ๋๋ง ๋ณด๊ณ ์ดํดํ๋ ์ฌ๋์๊ฒ๋ ์ด๋ค ์ซ์๋ฅผ ์๋ฏธํ๋์ง ์๊ธฐ๊ฐ ์ด๋ ค์ธ ๊ฒ ๊ฐ์์. |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ํธ์ ์ด๋๋ฐฉํฅ์ ์ํ์ข์ฐ๋๊ฐ์ ๋ชจ๋ ์ํ๋๋งํผ ์ด๋์ธ ๊ฒ์ผ๋ก ์๊ณ ์๋๋ฐ,
์ํ์ข์ฐ๋ 1์นธ์ฉ๋ฐ์ ์ด๋ํ์ง ๋ชปํ๋๊ฑด๊ฐ์?
ํธ์ ์ด๋ ๊ท์น์ ํ ๋ฒ ๋ค์ ๋ด์ฃผ์๊ฒ ์ด์? |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ๋ต! Player ๊ธฐ๋ฅ๋ชฉ๋ก์ ์ ์ ๊ณ์ฐ๋ ์ถ๊ฐํ์ต๋๋ค |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ๋ต ํธ ์ด๋ ๊ท์น์ ์์ ํ ์ฐฉ๊ฐํด๋ฒ๋ ธ์ด์ใ
ใ
์์ ํ์ต๋๋ค! |
@@ -0,0 +1,123 @@
+import { FOOD_MENU } from '../constants/FoodMenu.js';
+import {
+ EVENT_CONST,
+ DAY_OF_WEEK,
+ UTILS_CONST,
+} from '../constants/Constants.js';
+
+class PlannerUtils {
+ #userOrder;
+
+ #userDate;
+
+ #userDay;
+
+ #userEvent;
+
+ constructor(userOrder, userDate) {
+ this.#userOrder = userOrder;
+ this.#userDate = userDate;
+ this.#userDay = new Date(UTILS_CONST.userDay(this.#userDate)).getDay();
+ this.#userEvent = { ...EVENT_CONST };
+ }
+
+ getTotalAmount() {
+ const MENU_COST = {};
+ Object.values(FOOD_MENU).forEach((course) => {
+ Object.values(course).forEach((menu) => {
+ MENU_COST[menu[0]] = menu[1];
+ });
+ });
+ return this.#sumAmount(MENU_COST);
+ }
+
+ #sumAmount(MENU_COST) {
+ const totalAmount = [];
+ this.#userOrder.forEach((order) => {
+ totalAmount.push(MENU_COST[order[0]] * Number(order[1]));
+ });
+ return totalAmount.reduce((total, cost) => total + cost);
+ }
+
+ benefitCheck() {
+ if (this.getTotalAmount() >= UTILS_CONST.minGetBenefit) {
+ this.#userEvent.christmas = this.#christmasCheck();
+ this.#userEvent.weekDay = this.#weekDaysCheck();
+ this.#userEvent.weekendDay = this.#weekendDayCheck();
+ this.#userEvent.specialDay = this.#specialDayCheck();
+ this.#userEvent.benefitEvent = this.#giftCheck();
+ }
+ return this.#userEvent;
+ }
+
+ #christmasCheck() {
+ if (this.#userDate > UTILS_CONST.christmasEventEnd) {
+ return UTILS_CONST.noBenefit;
+ }
+ return UTILS_CONST.christmasBenefit(this.#userDate);
+ }
+
+ #weekDaysCheck() {
+ if (DAY_OF_WEEK.weekDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekDayEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #weekendDayCheck() {
+ if (DAY_OF_WEEK.weekendDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekendEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #specialDayCheck() {
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDay)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDate)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #giftCheck() {
+ if (this.getTotalAmount() > UTILS_CONST.minGetGift) {
+ return UTILS_CONST.giftCost;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #checkEventMenu(event) {
+ const numberOfMenu = [0];
+ const eventMenu = Object.values(FOOD_MENU[event]).map((menu) => menu[0]);
+ this.#userOrder.forEach((menu) => {
+ if (eventMenu.includes(menu[0])) {
+ numberOfMenu.push(Number(menu[1]));
+ }
+ });
+ return numberOfMenu.reduce((total, amount) => total + amount);
+ }
+
+ calcBenefitAmount() {
+ const totalBenefit = Object.values(this.#userEvent).reduce(
+ (total, amount) => total + amount,
+ );
+ return totalBenefit;
+ }
+
+ calcTotalPayment() {
+ if (this.#userEvent.benefitEvent !== 0) {
+ return (
+ this.getTotalAmount() - this.calcBenefitAmount() + UTILS_CONST.giftCost
+ );
+ }
+ return this.getTotalAmount() - this.calcBenefitAmount();
+ }
+}
+
+export default PlannerUtils; | JavaScript | ์ด๊ฑด ์ ๋ง ์ ์ ๊ฐ์ธ์ ์ธ ์๊ฐ์
๋๋ค๋ง, ํ๋์ ํด๋์ค์์ ๋๋ฌด ๋ง์ ์ผ์ ๋ด๋นํ๊ณ ์๋ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์์ต๋๋ค..! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | ์ด๊ฑด ์ง์ง ์ฌ์ํ ๊ฑฐ๊ธดํ๋ฐ, ๋ณ์ ์ค์ #regax ๊ฐ ์๋๋ฐ ์ ๊ทํํ์์ ๋ํ๋ด๋ ๊ฑฐ๋ผ๊ณ ์๊ฐํ๋๋ฐ, ํน์ ๋ง๋ค๋ฉด regular expression => regex ๊ฐ ์ข์ง ์์๊น! ์๊ฐํด๋ดค์ต๋๋ค! ์๋ง ์คํ์ด์ ๊ฑฐ ๊ฐ๊ธฐ๋ํ๊ตฌ..!? |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | Number.isInteger ๋ง ์์์ง, Number.isSafeInteger ๋ผ๋ ๋ฉ์๋๊ฐ ์๋ ์ค์ ์ ๋ง ๋ชฐ๋๋๋ฐ, ๋๋ถ์ ์ด๋ ๊ฒ ๋ ํ๋ ์์๊ฐ์! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | rangeCheck๋ฉ์๋์์ ๋ ์ง๋ฅผ ๋ํ๋ด๋ ์ซ์ 0, 31๋ ์์์ฒ๋ฆฌํด์ ๊ฐ์ ธ์ค๋ฉด ๋์ค์ ๋ณ๊ฒฝํ ๋ ๋ ํธ๋ฆฌํ์ง ์์๊น ์ถ์์ต๋๋ค! |
@@ -0,0 +1,125 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+import { FOOD_MENU } from '../../constants/FoodMenu.js';
+
+class MenuValidate {
+ #canOrder;
+
+ #userMenu;
+
+ #menu;
+
+ constructor(menu, canOrder = [], userMenu = []) {
+ this.#menu = menu;
+ this.#canOrder = canOrder;
+ this.#userMenu = userMenu;
+ }
+
+ menuCheck() {
+ this.#findingMenu(this.#canOrder, this.#userMenu, this.#menu);
+ this.#userMenu.forEach((order) => {
+ if (!this.#canOrder.includes(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ });
+ }
+
+ #findingMenu() {
+ Object.keys(FOOD_MENU).map((course) =>
+ this.#makeCanOrder(course, this.#canOrder),
+ );
+
+ this.#menu.forEach((order) => this.#userMenu.push(order.split('-')[0]));
+ }
+
+ #makeCanOrder(course) {
+ Object.values(FOOD_MENU[`${course}`]).map((food) =>
+ this.#canOrder.push(food[0]),
+ );
+ }
+
+ menuAmountCheck(regax) {
+ const totalMenuAmount = [];
+ this.#menu.forEach((order) => {
+ this.#amountCheck(order.split('-')[1], regax);
+ totalMenuAmount.push(Number(order.split('-')[1]));
+ });
+
+ this.#totalAmountCheck(totalMenuAmount);
+ }
+
+ #amountCheck(amount, regax) {
+ if (regax.test(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ if (Number(amount) <= 0) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+
+ if (!Number.isSafeInteger(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ #totalAmountCheck(total) {
+ const checkTotal = total.reduce((sum, amount) => sum + amount);
+ if (checkTotal > 20) {
+ throw new Error(ERROR_MSG.totalError);
+ }
+ }
+
+ formCheck() {
+ const form = /^[๊ฐ-ํฃ]+-[0-9]+$/;
+ this.#menu.forEach((order) => this.#formRegaxCheck(order, form));
+ }
+
+ #formRegaxCheck(order, form) {
+ if (!form.test(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ duplicateCheck() {
+ if (this.#userMenu.length !== new Set(this.#userMenu).size) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ drinkCheck() {
+ const menuObject = this.#makingMenuObject();
+ if (this.#objectCheck(menuObject)) {
+ throw new Error(ERROR_MSG.drinkError);
+ }
+ }
+
+ #makingMenuObject() {
+ const menuObject = {};
+ Object.keys(FOOD_MENU).forEach((course) => {
+ menuObject[course] = this.#userMenuCourses(course);
+ });
+ return menuObject;
+ }
+
+ #userMenuCourses(course) {
+ const includeCourse = [];
+ Object.values(FOOD_MENU[course]).forEach((eachMenu) => {
+ if (this.#menuIncludes(eachMenu)) {
+ includeCourse.push(eachMenu[0]);
+ }
+ });
+ return includeCourse.length;
+ }
+
+ #menuIncludes(eachMenu) {
+ return this.#userMenu.includes(eachMenu[0]);
+ }
+
+ #objectCheck(menuObject) {
+ const { appetizer, main, dessert, drink } = menuObject;
+ if (appetizer === 0 && main === 0 && dessert === 0 && drink !== 0) {
+ return true;
+ }
+ return false;
+ }
+}
+
+export default MenuValidate; | JavaScript | ๋ฐฐ์ด์ ์์ฃผ ์ฌ์ฉํ์ ๊ฒ ๊ฐ์์! ์ ๋ ์ด๋ฒ์ ๋ฏธ์
ํ๋ฉด์ Array ๋ Map ์ค์์ ์ด๋ค ๊ฑธ ์ฌ์ฉํ ์ง ๊ณ ๋ฏผํ์๋๋ฐ์, ์ ํํ
๋ ์ฌ์ค Map ์ด ์ต์ํ ๊ฐ๋
์ ์๋์ฌ์ ๋ฐฑ์๋๋ถ๋คํํ
๋ฌผ์ด๋ดค๋๋ฐ ๋ชจ๋ ๋ฐฐ์ด๊ณผ ๋งต ๋ ์ค์ ๊ณจ๋ผ์ผํ๋ค๋ฉด ๋งต์ด ๋ ํจ์จ์ ์ด๋ผ๊ณ ํ์๋๋ผ๊ตฌ์! ๋ฐฐ์ด๋ index๋ก ๊ฐ์ ๊ฐ์ ธ์ฌ ์ ์๊ณ , Map ๋ key๋ก ๊ฐ์ ๊ฐ์ ธ์ค๋๋ฐ, ๋ฐฐ์ด์ ํด๋นindex๊น์ง 0๋ถํฐ ์์ํด์ผํ๋ค๊ณ ํ๋๋ผ๊ตฌ์. ๋ฐ๋ฉด์ ๋งต์ ํ๋ฒ์ ๊ฐ์ ๊ฐ์ ธ์์ ์๊ฐ๋ณต์ก๋๊ฐ O(1) ์ด๋ผ๊ณ ํฉ๋๋ค! |
@@ -0,0 +1,132 @@
+/* eslint-disable max-lines-per-function */
+import PlannerUtils from '../../src/domain/utils/PlannerUtills.js';
+import PlannerData from '../../src/domain/model/PlannerData.js';
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const testCases = [
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5'], day: 25, expected: 275000 },
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ ๋ก์ฝ๋ผ-5', '์์ด์คํฌ๋ฆผ-5'],
+ day: 1,
+ expected: 275000 + 15000 + 25000,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`์ด ๊ธ์ก ํ
์คํธ : ${testCase.menu}`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ expect(plannerUtil.getTotalAmount()).toBe(testCase.expected);
+ });
+ });
+});
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const expectedObj = {
+ christmas: 3400,
+ weekDay: 4046,
+ weekendDay: 0,
+ specialDay: 1000,
+ benefitEvent: 25000,
+ };
+
+ const testCases = [
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: 25,
+ expected: expectedObj,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`ํํ ํ
์คํธ : ${testCase.menu}`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ expect(plannerUtil.benefitCheck()).toStrictEqual(testCase.expected);
+ });
+ });
+});
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const testCases = [
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '25',
+ expected: 3400 + 4046 + 1000 + 25000,
+ },
+ {
+ menu: ['์์ด์คํฌ๋ฆผ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '21',
+ expected: 3000 + 14161,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`์ด ํํ๊ธ์ก ํ
์คํธ : ${testCase.day}์ผ`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ plannerUtil.benefitCheck();
+ expect(plannerUtil.calcBenefitAmount()).toBe(testCase.expected);
+ });
+ });
+});
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const testCases = [
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '25',
+ discount: 3400 + 4046 + 1000,
+ },
+ {
+ menu: ['์์ด์คํฌ๋ฆผ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '21',
+ discount: 3000 + 14161,
+ },
+ {
+ menu: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1', '๋ ๋์์ธ-1', '์ด์ฝ์ผ์ดํฌ-1'],
+ day: '12',
+ discount: 2100 + 2023,
+ },
+ {
+ menu: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1', '๋ ๋์์ธ-1', '์ด์ฝ์ผ์ดํฌ-1'],
+ day: '26',
+ discount: 2023,
+ },
+ {
+ menu: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1', '๋ ๋์์ธ-1'],
+ day: '26',
+ discount: 0,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก : ${testCase.day}์ผ`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ plannerUtil.benefitCheck();
+ const expected = plannerUtil.getTotalAmount() - testCase.discount;
+ expect(plannerUtil.calcTotalPayment()).toBe(expected);
+ });
+ });
+}); | JavaScript | ์ ๋ ํ
์คํธ์ฝ๋๋ฅผ ์ง๋๊ฒ ๋๋ฌด ์ด๋ ค์ ์ด์,, ๋ง์ ์ฐธ๊ณ ๊ฐ ๋ผ์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,123 @@
+import { FOOD_MENU } from '../constants/FoodMenu.js';
+import {
+ EVENT_CONST,
+ DAY_OF_WEEK,
+ UTILS_CONST,
+} from '../constants/Constants.js';
+
+class PlannerUtils {
+ #userOrder;
+
+ #userDate;
+
+ #userDay;
+
+ #userEvent;
+
+ constructor(userOrder, userDate) {
+ this.#userOrder = userOrder;
+ this.#userDate = userDate;
+ this.#userDay = new Date(UTILS_CONST.userDay(this.#userDate)).getDay();
+ this.#userEvent = { ...EVENT_CONST };
+ }
+
+ getTotalAmount() {
+ const MENU_COST = {};
+ Object.values(FOOD_MENU).forEach((course) => {
+ Object.values(course).forEach((menu) => {
+ MENU_COST[menu[0]] = menu[1];
+ });
+ });
+ return this.#sumAmount(MENU_COST);
+ }
+
+ #sumAmount(MENU_COST) {
+ const totalAmount = [];
+ this.#userOrder.forEach((order) => {
+ totalAmount.push(MENU_COST[order[0]] * Number(order[1]));
+ });
+ return totalAmount.reduce((total, cost) => total + cost);
+ }
+
+ benefitCheck() {
+ if (this.getTotalAmount() >= UTILS_CONST.minGetBenefit) {
+ this.#userEvent.christmas = this.#christmasCheck();
+ this.#userEvent.weekDay = this.#weekDaysCheck();
+ this.#userEvent.weekendDay = this.#weekendDayCheck();
+ this.#userEvent.specialDay = this.#specialDayCheck();
+ this.#userEvent.benefitEvent = this.#giftCheck();
+ }
+ return this.#userEvent;
+ }
+
+ #christmasCheck() {
+ if (this.#userDate > UTILS_CONST.christmasEventEnd) {
+ return UTILS_CONST.noBenefit;
+ }
+ return UTILS_CONST.christmasBenefit(this.#userDate);
+ }
+
+ #weekDaysCheck() {
+ if (DAY_OF_WEEK.weekDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekDayEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #weekendDayCheck() {
+ if (DAY_OF_WEEK.weekendDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekendEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #specialDayCheck() {
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDay)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDate)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #giftCheck() {
+ if (this.getTotalAmount() > UTILS_CONST.minGetGift) {
+ return UTILS_CONST.giftCost;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #checkEventMenu(event) {
+ const numberOfMenu = [0];
+ const eventMenu = Object.values(FOOD_MENU[event]).map((menu) => menu[0]);
+ this.#userOrder.forEach((menu) => {
+ if (eventMenu.includes(menu[0])) {
+ numberOfMenu.push(Number(menu[1]));
+ }
+ });
+ return numberOfMenu.reduce((total, amount) => total + amount);
+ }
+
+ calcBenefitAmount() {
+ const totalBenefit = Object.values(this.#userEvent).reduce(
+ (total, amount) => total + amount,
+ );
+ return totalBenefit;
+ }
+
+ calcTotalPayment() {
+ if (this.#userEvent.benefitEvent !== 0) {
+ return (
+ this.getTotalAmount() - this.calcBenefitAmount() + UTILS_CONST.giftCost
+ );
+ }
+ return this.getTotalAmount() - this.calcBenefitAmount();
+ }
+}
+
+export default PlannerUtils; | JavaScript | ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค!
`์ฌ๊ธฐ์ ํ์ผ์ด ๋ฐ๋ก ์ ๋ณด์ด๋๋ฐ, ์ ์ PR ๋ก ๋ดค์์ ๋, App.js ์์ #PLANNER ์ด๋ ๊ฒ ์ฌ์ฉํ์
จ๋๋ฐ, ํน์ ๋๋ฌธ์๋ก ใ
ํ์ ์ด์ ๊ฐ ์์ผ์ ๊ฐ์๏ผ๏ผ`
๊ฐ์ธ์ ์ผ๋ก ์์ฑ์์์ ์ ์๋๋ ํด๋์ค๋ ๊ตฌ๋ถ์ ๋ช
ํํ ํ๊ธฐ์ํด ๋๋ฌธ์๋ฅผ ์ฌ์ฉํ์ต๋๋ค! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | ์ MVCํจํด ์์์๋ง ์์ํ๋ฅผ ์๊ฐํ์ง ์ด๋ถ๋ถ์ ๊น๋นกํ๋ค์..! ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,28 @@
+import DateValidate from './validator/DateValidate.js';
+import MenuValidate from './validator/MenuValidate.js';
+
+class InputValidator {
+ #REGAX;
+
+ constructor() {
+ this.#REGAX = /\s|[!@#$%^&*(),?":{}|<>]|[a-zA-Z]/;
+ }
+
+ async dateValidate(date) {
+ const dateValidator = new DateValidate(this.#REGAX, date);
+ dateValidator.regaxCheck();
+ dateValidator.safeCheck();
+ dateValidator.rangeCheck();
+ }
+
+ async menuValidate(menu) {
+ const menuValidator = new MenuValidate(menu);
+ menuValidator.menuCheck();
+ menuValidator.menuAmountCheck(this.#REGAX);
+ menuValidator.formCheck();
+ menuValidator.duplicateCheck();
+ menuValidator.drinkCheck();
+ }
+}
+
+export default InputValidator; | JavaScript | ์ ๊ท์์ผ๋ก ์ ํจ์ฑ ๊ฒ์ฌ ๋ก์ง์ ๊ฐ๊ฒฐํ๊ฒ ํํํ์ผ๋ฉด ์ข์์ ๊ฑฐ๋ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ์ ์
์ฅ์ผ๋ก์.. ์ ๊ท์ ์ฌ์ฉ์ ๊น๋ํ์ ์ ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค ๐๐ป |
@@ -0,0 +1,34 @@
+export const EVENT_CONST = {
+ christmas: 0,
+ weekDay: 0,
+ weekendDay: 0,
+ specialDay: 0,
+ benefitEvent: 0,
+};
+
+export const DAY_OF_WEEK = {
+ sun: 0,
+ mon: 1,
+ tue: 2,
+ wed: 3,
+ thu: 4,
+ fri: 5,
+ sat: 6,
+ weekDay: [0, 1, 2, 3, 4],
+ weekendDay: [5, 6],
+ specialDay: [0, 25],
+};
+
+export const UTILS_CONST = {
+ userDay: (userDate) => `2023-12-${userDate}`,
+ christmasBenefit: (userDate) => 1000 + (userDate - 1) * 100,
+ minGetBenefit: 10000,
+ christmasEventEnd: 25,
+ noBenefit: 0,
+ discount: 2023,
+ weekDayEvent: 'dessert',
+ weekendEvent: 'main',
+ specialDiscount: 1000,
+ minGetGift: 120000,
+ giftCost: 25000,
+}; | JavaScript | ์ด๋ฏธ ์์ ์ ์ธ์ผ๋ก const ๋ผ๋ ๋จ์ด๋ ๋ดํฌํ ์ ์๋ค๊ณ ์๊ฐํด์! UTILS, EVENT ๋ก ์ ์ธํ๊ณ ๋ด๋ถ ์์๋ค์ ๋ช
์นญ์ ๋ ๊ตฌ์ฒด์ ์ผ๋ก ์์ฑํ์๋ ๋ฐฉ๋ฒ๋ ์ข์์๊ฑฐ๋ผ๊ตฌ ์๊ฐํฉ๋๋ค ใ
ใ
|
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ธํ์ ๋ฐ๋ ๊ตฌ์กฐ๊ฐ ์ ์ฌํ๋, ์ธํ ํธ๋ค๋ง๊ณผ ํธ๋ผ์ด ์บ์น ์ฌ์ฉ์ ์ค๋ณต์ ํ๋์ ๋ฉ์๋๋ก ๋ฐ๋ก ์ ์ธํ๊ณ ํ์ฉํ๋ ๋ฐฉ์๋ ์ข์ ๋ฐฉ๋ฒ์ด๋๋ผ๊ตฌ์ ์ถ์ฒ๋๋ฆฌ๊ตฌ ๊ฐ๋๋ค ๐๐ป |
@@ -0,0 +1,21 @@
+import { Console } from '@woowacourse/mission-utils';
+import { INPUT_MSG } from '../constants/PlannerMsg.js';
+import InputValidator from '../utils/InputValidator.js';
+
+const InputView = {
+ INPUT_VAL: new InputValidator(),
+
+ async readDate() {
+ const userDate = await Console.readLineAsync(INPUT_MSG.inputVisitDay);
+ await this.INPUT_VAL.dateValidate(userDate);
+ return userDate;
+ },
+
+ async readMenu() {
+ const userMenu = await Console.readLineAsync(INPUT_MSG.orderMenu);
+ await this.INPUT_VAL.menuValidate(userMenu.split(','));
+ return userMenu.split(',');
+ },
+};
+
+export default InputView; | JavaScript | ์ธํ ์ ํจ์ฑ ๊ฒ์ฌ์ ๋ํ ํด๋์ค๋ฅผ ๋ฐ๋ก ์ ์ธํ์
์ ๋ทฐ์์ ํธ์ถํ๋ ๋ฐฉ์์ด ๋ ์๋กญ๋ค์ !! ์ ๋ ์ธํ ๋ฐ๋ ๋ด๋ถ์์ ๊ตฌํํ๊ณ , ๋ถ๋ฆฌํด์ผ ํ๋ค๋ ์๊ฐ๋ง ํ์๋๋ฐ ์ด ๋ฐฉ์๋ ํจ์จ์ ์ธ๊ฑฐ ๊ฐ์์ โบ๏ธ |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ฌ๊ฒฝ๋ ์ฝ๋๋ณด๊ณ ์ ๋ ์ญ์ ์ค์ฌ์ผ๊ฒ ๋ค ์๊ฐํ์ต๋๋ค!
์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ ๋ ์ ๋ฒ์๋ catch๋ถ๋ฌธ์ ๋ค์ inputVisitDay๋ฅผ ์คํํ๋ฉด ์ฌ๊ท์ ์ผ๋ก ์ฒ๋ฆฌ๋์ด ํ
์คํธ๊ฐ ํต๊ณผ๊ฐ ์ ๋๋๋ฐ @JonghyunLEE12 ๋์ inputVisitDay๋ฅผ ๋ฐ๋ก returnํ๋๊ฑธ๋ก ํด๊ฒฐํ์
จ๋ค์. ์ด๋ฒ์ ์ ๋ while(true) ๊ตฌ๋ฌธ ์์์ validํ ์
๋ ฅ๊ฐ์ ๋ฐ์ผ๋ฉด while์ ๋๊ฐ๋ ๊ฒ์ผ๋ก ์์ฑํด๋ดค๋๋ฐ ๊ฐ์ธ์ ์ผ๋ก ๋ ๊น๋ํ ์ฒ๋ฆฌ๋ผ๊ณ ์๊ฐ์ด ๋ค๋๋ผ๊ณ ์ ํ๋ฒ ์ฐธ๊ณ ํด๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,125 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+import { FOOD_MENU } from '../../constants/FoodMenu.js';
+
+class MenuValidate {
+ #canOrder;
+
+ #userMenu;
+
+ #menu;
+
+ constructor(menu, canOrder = [], userMenu = []) {
+ this.#menu = menu;
+ this.#canOrder = canOrder;
+ this.#userMenu = userMenu;
+ }
+
+ menuCheck() {
+ this.#findingMenu(this.#canOrder, this.#userMenu, this.#menu);
+ this.#userMenu.forEach((order) => {
+ if (!this.#canOrder.includes(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ });
+ }
+
+ #findingMenu() {
+ Object.keys(FOOD_MENU).map((course) =>
+ this.#makeCanOrder(course, this.#canOrder),
+ );
+
+ this.#menu.forEach((order) => this.#userMenu.push(order.split('-')[0]));
+ }
+
+ #makeCanOrder(course) {
+ Object.values(FOOD_MENU[`${course}`]).map((food) =>
+ this.#canOrder.push(food[0]),
+ );
+ }
+
+ menuAmountCheck(regax) {
+ const totalMenuAmount = [];
+ this.#menu.forEach((order) => {
+ this.#amountCheck(order.split('-')[1], regax);
+ totalMenuAmount.push(Number(order.split('-')[1]));
+ });
+
+ this.#totalAmountCheck(totalMenuAmount);
+ }
+
+ #amountCheck(amount, regax) {
+ if (regax.test(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ if (Number(amount) <= 0) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+
+ if (!Number.isSafeInteger(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ #totalAmountCheck(total) {
+ const checkTotal = total.reduce((sum, amount) => sum + amount);
+ if (checkTotal > 20) {
+ throw new Error(ERROR_MSG.totalError);
+ }
+ }
+
+ formCheck() {
+ const form = /^[๊ฐ-ํฃ]+-[0-9]+$/;
+ this.#menu.forEach((order) => this.#formRegaxCheck(order, form));
+ }
+
+ #formRegaxCheck(order, form) {
+ if (!form.test(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ duplicateCheck() {
+ if (this.#userMenu.length !== new Set(this.#userMenu).size) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ drinkCheck() {
+ const menuObject = this.#makingMenuObject();
+ if (this.#objectCheck(menuObject)) {
+ throw new Error(ERROR_MSG.drinkError);
+ }
+ }
+
+ #makingMenuObject() {
+ const menuObject = {};
+ Object.keys(FOOD_MENU).forEach((course) => {
+ menuObject[course] = this.#userMenuCourses(course);
+ });
+ return menuObject;
+ }
+
+ #userMenuCourses(course) {
+ const includeCourse = [];
+ Object.values(FOOD_MENU[course]).forEach((eachMenu) => {
+ if (this.#menuIncludes(eachMenu)) {
+ includeCourse.push(eachMenu[0]);
+ }
+ });
+ return includeCourse.length;
+ }
+
+ #menuIncludes(eachMenu) {
+ return this.#userMenu.includes(eachMenu[0]);
+ }
+
+ #objectCheck(menuObject) {
+ const { appetizer, main, dessert, drink } = menuObject;
+ if (appetizer === 0 && main === 0 && dessert === 0 && drink !== 0) {
+ return true;
+ }
+ return false;
+ }
+}
+
+export default MenuValidate; | JavaScript | ๋ฉ๋ด ์ ๊ทํํ์์ ์ ์์ฑํ์
จ๋๋ฐ ๋ฉ๋ด๊ฐฏ์๋ ์ฒซ ์ซ์๋ก 0์ด ๋ค์ด๊ฐ๋๊ฑธ ๋ฐฉ์งํ๊ธฐ ์ํด [0-9]+๋ ๋ณด๋ค [1-9]\d*๊ฐ ๋ ์ ์ ํ์ง ์์๊น ์ถ์ต๋๋ค. (์ฒซ ์ซ์๋ 1์์9๋ง ๊ฐ๋ฅํ๊ณ ๋ท ์ซ์๋ ๋ญ ๋ 0๊ฐ ์ด์ ์ด๋ฐ์์ผ๋ก์) |
@@ -0,0 +1,60 @@
+/* eslint-disable max-lines-per-function */
+import InputValidator from '../../src/domain/utils/InputValidator.js';
+
+describe('๋ ์ง ํ
์คํธ', () => {
+ const userInput = new InputValidator();
+ const testCases = [
+ { date: 'a', expectedError: '[ERROR]' },
+ { date: ' ', expectedError: '[ERROR]' },
+ { date: '์ด์ญ์ค์ผ', expectedError: '[ERROR]' },
+ { date: '32', expectedError: '[ERROR]' },
+ { date: '0', expectedError: '[ERROR]' },
+ { date: '25.5', expectedError: '[ERROR]' },
+ { date: '-1', expectedError: '[ERROR]' },
+ { date: ' 12', expectedError: '[ERROR]' },
+ { date: '1 2', expectedError: '[ERROR]' },
+ { date: '12 ', expectedError: '[ERROR]' },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`๋ ์ง ํ
์คํธ, ๋ ์ง: ${testCase.date}`, async () => {
+ await expect(userInput.dateValidate(testCase.date)).rejects.toThrow(
+ testCases.expectedError,
+ );
+ });
+ });
+});
+
+describe('๋ฉ๋ด ํ
์คํธ', () => {
+ const menuValidate = new InputValidator();
+ const testCases = [
+ { menu: ['์งฌ๋ฝ-1'], expectedError: '[ERROR]' },
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-0'], expectedError: '[ERROR]' },
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-1.5'], expectedError: '[ERROR]' },
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-a'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ1', '๋ ๋์์ธ1'], expectedError: '[ERROR]' },
+ { menu: ['๊น๋ฐฅ-1', '๋ก๋ณถ์ด-1'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ-์ผ', '๋ ๋์์ธ-์ด'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ-a', '๋ ๋์์ธ-b'], expectedError: '[ERROR]' },
+ { menu: ['ํด์ฐ๋ฌผํ์คํ-2', 'ํด์ฐ๋ฌผํ์คํ-1'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ-1'], expectedError: '[ERROR]' },
+ { menu: ['๋ ๋์์ธ-1', '์ ๋ก์ฝ๋ผ-1'], expectedError: '[ERROR]' },
+ { menu: ['์์ ์๋ฌ๋- 1', '์ ๋ก์ฝ๋ผ- 1'], expectedError: '[ERROR]' },
+ {
+ menu: ['๋ ๋์์ธ-2', '์ ๋ก์ฝ๋ผ-2', '์ดํ์ธ-2'],
+ expectedError: '[ERROR]',
+ },
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-10', '๋ ๋์์ธ-20', '์ ๋ก์ฝ๋ผ-20'],
+ expectedError: '[ERROR]',
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`๋ฉ๋ด ํ
์คํธ, ๋ฉ๋ด: ${testCase.menu}`, async () => {
+ await expect(menuValidate.menuValidate(testCase.menu)).rejects.toThrow(
+ testCase.expectedError,
+ );
+ });
+ });
+}); | JavaScript | ์ด์ญ์ค์ผใ
ใ
ํ
์คํธ์ฝ๋๋ฅผ ์ ๋ง ์์ธํ๊ฒ ์ง์
จ๋ค์ ๋ง์ด ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | ๊ฐ์ธ์ ์ผ๋ก this.#regax๋ฅผ ํ๋๋ก ๋์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค. ์์ํํด์ ๋ฐ๋ก ๊ฐ์ ธ์ ์ฐ์์ง์๊ณ new DateValidate()ํ ๋ regex๋ฅผ ์ ๋ฌํ์ ๋ค๋ฅธ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,125 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+import { FOOD_MENU } from '../../constants/FoodMenu.js';
+
+class MenuValidate {
+ #canOrder;
+
+ #userMenu;
+
+ #menu;
+
+ constructor(menu, canOrder = [], userMenu = []) {
+ this.#menu = menu;
+ this.#canOrder = canOrder;
+ this.#userMenu = userMenu;
+ }
+
+ menuCheck() {
+ this.#findingMenu(this.#canOrder, this.#userMenu, this.#menu);
+ this.#userMenu.forEach((order) => {
+ if (!this.#canOrder.includes(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ });
+ }
+
+ #findingMenu() {
+ Object.keys(FOOD_MENU).map((course) =>
+ this.#makeCanOrder(course, this.#canOrder),
+ );
+
+ this.#menu.forEach((order) => this.#userMenu.push(order.split('-')[0]));
+ }
+
+ #makeCanOrder(course) {
+ Object.values(FOOD_MENU[`${course}`]).map((food) =>
+ this.#canOrder.push(food[0]),
+ );
+ }
+
+ menuAmountCheck(regax) {
+ const totalMenuAmount = [];
+ this.#menu.forEach((order) => {
+ this.#amountCheck(order.split('-')[1], regax);
+ totalMenuAmount.push(Number(order.split('-')[1]));
+ });
+
+ this.#totalAmountCheck(totalMenuAmount);
+ }
+
+ #amountCheck(amount, regax) {
+ if (regax.test(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ if (Number(amount) <= 0) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+
+ if (!Number.isSafeInteger(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ #totalAmountCheck(total) {
+ const checkTotal = total.reduce((sum, amount) => sum + amount);
+ if (checkTotal > 20) {
+ throw new Error(ERROR_MSG.totalError);
+ }
+ }
+
+ formCheck() {
+ const form = /^[๊ฐ-ํฃ]+-[0-9]+$/;
+ this.#menu.forEach((order) => this.#formRegaxCheck(order, form));
+ }
+
+ #formRegaxCheck(order, form) {
+ if (!form.test(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ duplicateCheck() {
+ if (this.#userMenu.length !== new Set(this.#userMenu).size) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ drinkCheck() {
+ const menuObject = this.#makingMenuObject();
+ if (this.#objectCheck(menuObject)) {
+ throw new Error(ERROR_MSG.drinkError);
+ }
+ }
+
+ #makingMenuObject() {
+ const menuObject = {};
+ Object.keys(FOOD_MENU).forEach((course) => {
+ menuObject[course] = this.#userMenuCourses(course);
+ });
+ return menuObject;
+ }
+
+ #userMenuCourses(course) {
+ const includeCourse = [];
+ Object.values(FOOD_MENU[course]).forEach((eachMenu) => {
+ if (this.#menuIncludes(eachMenu)) {
+ includeCourse.push(eachMenu[0]);
+ }
+ });
+ return includeCourse.length;
+ }
+
+ #menuIncludes(eachMenu) {
+ return this.#userMenu.includes(eachMenu[0]);
+ }
+
+ #objectCheck(menuObject) {
+ const { appetizer, main, dessert, drink } = menuObject;
+ if (appetizer === 0 && main === 0 && dessert === 0 && drink !== 0) {
+ return true;
+ }
+ return false;
+ }
+}
+
+export default MenuValidate; | JavaScript | ์ ์ด๋ถ๋ถ์ ์ ๊ฐ ์ ์ถํ๊ณ ๋์ ๊นจ๋ฌ์๋ค์ใ
ใ
์ ๋ ์ฐธ ์์ฝ์ต๋๋ค. ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | InputValidate ํด๋์ค์์ Date ์ Menu ์ ๋ํด ๋๊ฐ์ง ๊ฒ์ฌ๋ฅผ ์ ์ํด์คฌ์ต๋๋ค!
์ฐ์ ์ ์ฒด์ ์ธ ์ ๊ทํํ์์ ์์์์ ์ ์ํ๊ณ ํ์ ๊ฐ์ฒด๋ค์๊ฒ ์ ๋ฌํด์ฃผ๋ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ๋๋ฐ์.
MenuValidate ์์๋ form ์ด๋ผ๋ ์ ๊ทํํ์์ด ๋ ์กด์ฌํ๊ธฐ ๋๋ฌธ์, ํ ๊ฐ์ฒด ์์ ๋ค๋ฅธ ์ ๊ทํํ์์ด ์กด์ฌํ๋๊ฒ ๋ณด๋ค๋
๋ฐ๋ก ์ ์๋ฅผ ํด์ฃผ๋๊ฒ ๋ ์๋ป๋ณด์ฌ์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ์ต๋๋ค! |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ฒ์ ์์์์๋ถํฐ ํ๋์ ๋ฉ์๋๊ฐ ๋๋๋ฉด ๋ค์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ์์ผ๋ก ๋ง๋ฌด๋ฆฌ๋ฅผ ํ์ฌ controller์ชฝ์ ๋ชจ๋ ๋ฉ์๋๊ฐ ์ฐ๊ฒฐ๋์ด ์๋๋ฐ ๊ทธ๋ ๊ฒ ๋ชจ๋ ๋ฉ์๋๋ฅผ ์ฐ๊ฒฐ์ ์ง์ผ์ ์ด์ ๊ฐ ์์ผ์ค๊น์? |
@@ -0,0 +1,21 @@
+import { Console } from '@woowacourse/mission-utils';
+import { INPUT_MSG } from '../constants/PlannerMsg.js';
+import InputValidator from '../utils/InputValidator.js';
+
+const InputView = {
+ INPUT_VAL: new InputValidator(),
+
+ async readDate() {
+ const userDate = await Console.readLineAsync(INPUT_MSG.inputVisitDay);
+ await this.INPUT_VAL.dateValidate(userDate);
+ return userDate;
+ },
+
+ async readMenu() {
+ const userMenu = await Console.readLineAsync(INPUT_MSG.orderMenu);
+ await this.INPUT_VAL.menuValidate(userMenu.split(','));
+ return userMenu.split(',');
+ },
+};
+
+export default InputView; | JavaScript | ๋ ์ง๋ฅผ ๋ฐ์์ค์๋ง์ ๋ฐ๋ก validate๋ฅผ ํด์ฃผ๋ ๊ฒ์ด ๊ด์ฐฎ๋ค๊ณ ์๊ฐํ์ต๋๋ค. controller๋ก ๋ฐ์์ค๋ ๊ฒ๋ณด๋ค ์ด ํธ์ด ํจ์ฌ ๋ณด๊ธฐ ์ข์ ๊ฒ ๊ฐ๋ค์ |
@@ -0,0 +1,28 @@
+import DateValidate from './validator/DateValidate.js';
+import MenuValidate from './validator/MenuValidate.js';
+
+class InputValidator {
+ #REGAX;
+
+ constructor() {
+ this.#REGAX = /\s|[!@#$%^&*(),?":{}|<>]|[a-zA-Z]/;
+ }
+
+ async dateValidate(date) {
+ const dateValidator = new DateValidate(this.#REGAX, date);
+ dateValidator.regaxCheck();
+ dateValidator.safeCheck();
+ dateValidator.rangeCheck();
+ }
+
+ async menuValidate(menu) {
+ const menuValidator = new MenuValidate(menu);
+ menuValidator.menuCheck();
+ menuValidator.menuAmountCheck(this.#REGAX);
+ menuValidator.formCheck();
+ menuValidator.duplicateCheck();
+ menuValidator.drinkCheck();
+ }
+}
+
+export default InputValidator; | JavaScript | ๋ฐ์์จ ๊ฐ์ ๊ฒ์ฌํ ๋ ํ๋ฒ ๋ณด๋ด์ ์ ๊ท์ ํด์ ๊ทธ๊ฒ์ ๋ค์ ๊ฒ์ฌํ๋ ์์ผ๋ก ํ์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ ๊ฒ ์ ๊ท์์ ํ ๋จ๊ณ๋ก ๋ฐ๋ก ๋นผ์ ์ด์ ๊ฐ ์์ ์ง ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | Controller์๋ ์ด๋ฒคํธ ํ๋ ๋์ ์
๋ ฅ,์ถ๋ ฅ๋ฑ์ ์์๋ฅผ ์ ์ํ์ต๋๋ค.
๊ฐ๊ฐ์ ์์๋ค์ ํ๋์ ๋ฉ์๋๋ก ์ ์ํ๊ณ , ์ด๋ฅผ ์ฐ๊ฒฐ์์ผ์ฃผ๋ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ์ต๋๋ค |
@@ -0,0 +1,28 @@
+import DateValidate from './validator/DateValidate.js';
+import MenuValidate from './validator/MenuValidate.js';
+
+class InputValidator {
+ #REGAX;
+
+ constructor() {
+ this.#REGAX = /\s|[!@#$%^&*(),?":{}|<>]|[a-zA-Z]/;
+ }
+
+ async dateValidate(date) {
+ const dateValidator = new DateValidate(this.#REGAX, date);
+ dateValidator.regaxCheck();
+ dateValidator.safeCheck();
+ dateValidator.rangeCheck();
+ }
+
+ async menuValidate(menu) {
+ const menuValidator = new MenuValidate(menu);
+ menuValidator.menuCheck();
+ menuValidator.menuAmountCheck(this.#REGAX);
+ menuValidator.formCheck();
+ menuValidator.duplicateCheck();
+ menuValidator.drinkCheck();
+ }
+}
+
+export default InputValidator; | JavaScript | ์ ํจ์ฑ ๊ฒ์ฌ๋ InputValidate ์์์, MenuValidate, DateValidate ์ ๊ฐ์ฒด๋ค๋ก ๋๋๊ฒ ๋ฉ๋๋ค.
์์์์ ์ ๊ท์์ ์ ์ํด์ฃผ๊ณ , ์ ๊ท์์ ์จ์ผํ๋ ๊ฒ์ฌ ํ์์, ํ์ ๊ฐ์ฒด๋ค์๊ฒ ๋ด๋ ค์ฃผ๋ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+/* eslint-disable max-lines-per-function */
+import { OUTPUT_MSG } from '../../src/domain/constants/PlannerMsg.js';
+
+describe('๋ฐฐ์ง ํ
์คํธ', () => {
+ const testCases = [
+ { amount: 1000, expected: '์์' },
+ { amount: 4900, expected: '์์' },
+ { amount: 5000, expected: '๋ณ' },
+ { amount: 9900, expected: '๋ณ' },
+ { amount: 10000, expected: 'ํธ๋ฆฌ' },
+ { amount: 19999, expected: 'ํธ๋ฆฌ' },
+ { amount: 20000, expected: '์ฐํ' },
+ { amount: 50000, expected: '์ฐํ' },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`๋ฐฐ์ง ํ
์คํธ : ${testCase.amount}`, () => {
+ expect(OUTPUT_MSG.userBadge(testCase.amount)).toBe(testCase.expected);
+ });
+ });
+}); | JavaScript | ์ด๋ ๊ฒ ์ฒ๋ฆฌํ ์ ์๊ตฐ์! |
@@ -0,0 +1,37 @@
+/**
+ *
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+ */
+
+export const FOOD_MENU = {
+ appetizer: {
+ soup: ['์์ก์ด์ํ', 6000],
+ tapas: ['ํํ์ค', 5500],
+ salad: ['์์ ์๋ฌ๋', 8000],
+ },
+ main: {
+ stake: ['ํฐ๋ณธ์คํ
์ดํฌ', 55000],
+ barbeque: ['๋ฐ๋นํ๋ฆฝ', 54000],
+ seafood: ['ํด์ฐ๋ฌผํ์คํ', 35000],
+ christmas: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ', 25000],
+ },
+ dessert: {
+ cake: ['์ด์ฝ์ผ์ดํฌ', 15000],
+ iceCream: ['์์ด์คํฌ๋ฆผ', 5000],
+ },
+ drink: {
+ coke: ['์ ๋ก์ฝ๋ผ', 3000],
+ wine: ['๋ ๋์์ธ', 60000],
+ champane: ['์ดํ์ธ', 25000],
+ },
+}; | JavaScript | FOOD_MENU ๊ฐ์ฒด๋ฅผ ๊น์ ๋๊ฒฐํ๋ ๊ฑด ์ด๋ ์ ๊ฐ์? |
@@ -0,0 +1,37 @@
+/**
+ *
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+ */
+
+export const FOOD_MENU = {
+ appetizer: {
+ soup: ['์์ก์ด์ํ', 6000],
+ tapas: ['ํํ์ค', 5500],
+ salad: ['์์ ์๋ฌ๋', 8000],
+ },
+ main: {
+ stake: ['ํฐ๋ณธ์คํ
์ดํฌ', 55000],
+ barbeque: ['๋ฐ๋นํ๋ฆฝ', 54000],
+ seafood: ['ํด์ฐ๋ฌผํ์คํ', 35000],
+ christmas: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ', 25000],
+ },
+ dessert: {
+ cake: ['์ด์ฝ์ผ์ดํฌ', 15000],
+ iceCream: ['์์ด์คํฌ๋ฆผ', 5000],
+ },
+ drink: {
+ coke: ['์ ๋ก์ฝ๋ผ', 3000],
+ wine: ['๋ ๋์์ธ', 60000],
+ champane: ['์ดํ์ธ', 25000],
+ },
+}; | JavaScript | ์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค! @joywhy pr ๋งํฌ ๋จ๊ฒจ์ฃผ์๋ฉด ๋ง๋ฆฌ๋ทฐ ๊ฐ๊ฒ์!! |
@@ -0,0 +1,37 @@
+package christmas.service;
+
+import christmas.domain.Order;
+import christmas.domain.constant.Message;
+import christmas.domain.constant.dish.Appetizer;
+import christmas.domain.constant.dish.Beverage;
+import christmas.domain.constant.dish.Dessert;
+import christmas.domain.constant.dish.MainDish;
+import christmas.domain.constant.dish.Orderable;
+import java.util.Map;
+import java.util.Objects;
+
+public class OrderMaker {
+ public Order make(Map<String, Integer> parsedOrder) {
+ Order order = new Order();
+ parsedOrder.forEach((dishLabel, count) -> order.addMenu(findDish(dishLabel), count));
+ order.validate();
+ return order;
+ }
+
+ private Orderable findDish(String input) {
+ if (Objects.nonNull(Appetizer.valueOfLabel(input))) {
+ return Appetizer.valueOfLabel(input);
+ }
+ if (Objects.nonNull(Beverage.valueOfLabel(input))) {
+ return Beverage.valueOfLabel(input);
+ }
+ if (Objects.nonNull(Dessert.valueOfLabel(input))) {
+ return Dessert.valueOfLabel(input);
+ }
+ if (Objects.nonNull(MainDish.valueOfLabel(input))) {
+ return MainDish.valueOfLabel(input);
+ }
+ throw new IllegalArgumentException(Message.INVALID_ORDER.getContent());
+ }
+
+} | Java | ๋ฉ๋ด enum ํ์
์ด ์์์ผ๋ฉด ํ ๋ฒ์ ์ฐพ์ ์ ์์๊ฑฐ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,38 @@
+package christmas.domain.constant.dish;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public enum MainDish implements Orderable {
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55000),
+ BARBEQUE_RIBS("๋ฐ๋นํ๋ฆฝ", 54000),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35000),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000);
+
+ private static final Map<String, MainDish> BY_LABEL =
+ Stream.of(MainDish.values()).collect(Collectors.toMap(MainDish::getLabel, e -> e));
+
+ private final String label;
+ private final int price;
+
+ MainDish(String label, int price) {
+ this.label = label;
+ this.price = price;
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public int getPrice() {
+ return price;
+ }
+
+ public static MainDish valueOfLabel(String label) {
+ return BY_LABEL.get(label);
+ }
+
+} | Java | static์ผ๋ก Map์ ์์ฑํด๋ ๊ฑฐ ์ข์ ๊ฑฐ ๊ฐ์ต๋๋ค.
๊ทธ๋ฐ๋ฐ BY_LABEL ์ด๋ฆ์ ๋๋ฌธ์๋ก ํ๋ ๊ฒ์ด ์ปจ๋ฒค์
์ธ์ง ์ ๋ ์ ๋ชจ๋ฅด๊ฒ ๋๋ผ๊ณ ์.
์์๋ ์๋๋ฐ static final์ด๊ธฐ๋ ํ๊ณ ๋ญ๊ฐ ๋ง์๊น์? |
@@ -0,0 +1,31 @@
+package christmas.service;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.constant.Discount;
+import christmas.domain.constant.dish.Orderable;
+import christmas.domain.dto.BenefitDto;
+import christmas.service.discountcalculator.SpecialDiscountCalculator;
+import christmas.service.discountcalculator.WeekDiscountCalculator;
+import christmas.service.discountcalculator.XmasDdayDiscountCalculator;
+import java.util.Map;
+
+public class DiscountManager {
+ public BenefitDto applyDiscount(Map<Orderable, Integer> menus, DecemberDate visitDate) {
+ int totalCost = getTotalCost(menus);
+ BenefitDto benefitDto = new BenefitDto(menus, totalCost);
+ if (totalCost < Discount.DISCOUNT_APPLY_LOWER_BOUND.getValue()) {
+ return benefitDto;
+ }
+ XmasDdayDiscountCalculator.apply(benefitDto, visitDate);
+ WeekDiscountCalculator.apply(menus, benefitDto, visitDate);
+ SpecialDiscountCalculator.apply(benefitDto, visitDate);
+ return benefitDto;
+ }
+
+ private int getTotalCost(Map<Orderable, Integer> menus) {
+ return menus.entrySet().stream()
+ .mapToInt(entry -> entry.getKey().getPrice() * entry.getValue())
+ .sum();
+ }
+
+} | Java | menus๋ณด๋ค Order๋ฅผ ์ธ์๋ก ๋ฐ๋ ๊ฒ์ด ๋ ๊ฐ์ฒด์งํฅ์ ๋ง๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ Order ๋ด๋ถ์ getTotalCost ๋ฉ์๋๊ฐ ์๋ ๊ฒ์ด ์ด๋จ๊น์? ๊ทธ๋ฌ๋ฉด ์์ ์ ๋ฐ์ดํฐ๋ก ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค. |
@@ -0,0 +1,21 @@
+package christmas.service;
+
+import christmas.domain.constant.Benefit;
+import christmas.domain.dto.BenefitDto;
+
+public class PresentationManager {
+ private static final int PRESENTATION_THRESHOLD = 120000;
+ private static final int PRESENTATION_PRICE = 25000;
+
+ private PresentationManager() {
+
+ }
+
+ public static void present(BenefitDto benefitDto) {
+ if (benefitDto.getTotalCost() >= PRESENTATION_THRESHOLD) {
+ benefitDto.addBenefit(Benefit.PRESENTATION, PRESENTATION_PRICE);
+ benefitDto.presentChampagne();
+ }
+ }
+
+} | Java | 120_000 ์ฒ๋ผ _ ์ ๋ถ์ผ ์ ์์ต๋๋ค! |
@@ -0,0 +1,21 @@
+package christmas.service;
+
+import christmas.domain.constant.Benefit;
+import christmas.domain.dto.BenefitDto;
+
+public class PresentationManager {
+ private static final int PRESENTATION_THRESHOLD = 120000;
+ private static final int PRESENTATION_PRICE = 25000;
+
+ private PresentationManager() {
+
+ }
+
+ public static void present(BenefitDto benefitDto) {
+ if (benefitDto.getTotalCost() >= PRESENTATION_THRESHOLD) {
+ benefitDto.addBenefit(Benefit.PRESENTATION, PRESENTATION_PRICE);
+ benefitDto.presentChampagne();
+ }
+ }
+
+} | Java | private์ผ๋ก ์์ฑ์ ๋ง์์ค๋ ๊ฒ ์ข์ต๋๋ค! ๋ค๋ง ๋ด์ฉ์ด ์์ผ๋ฉด ๋น์ค๋ ์๋ ๊ฒ์ด ์ข์ต๋๋ค. |
@@ -0,0 +1,24 @@
+package christmas.service.discountcalculator;
+
+import static christmas.domain.constant.Discount.DATE_OF_CHRISTMAS;
+import static christmas.domain.constant.Discount.ONE_WEEK;
+import static christmas.domain.constant.Discount.SPECIAL_DISCOUNT_AMOUNT;
+import static christmas.domain.constant.Discount.THREE;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.constant.Benefit;
+import christmas.domain.dto.BenefitDto;
+
+public class SpecialDiscountCalculator {
+ private SpecialDiscountCalculator() {
+
+ }
+
+ public static void apply(BenefitDto benefitDto, DecemberDate visitDate) {
+ if (visitDate.date() == DATE_OF_CHRISTMAS.getValue()
+ || visitDate.date() % ONE_WEEK.getValue() == THREE.getValue()) {
+ benefitDto.addBenefit(Benefit.SPECIAL_DISCOUNT, SPECIAL_DISCOUNT_AMOUNT.getValue());
+ }
+ }
+
+} | Java | ๊ธด ์กฐ๊ฑด์์ ๋ฉ์๋๋ก ๋ฝ๋ ๊ฒ์ด ๊ฐ๋
์ฑ์ ์ข์ต๋๋ค! |
@@ -0,0 +1,70 @@
+package christmas.service.discountcalculator;
+
+import static christmas.domain.constant.Discount.ONE;
+import static christmas.domain.constant.Discount.ONE_WEEK;
+import static christmas.domain.constant.Discount.TWO;
+import static christmas.domain.constant.Discount.WEEK_DISCOUNT_UNIT;
+import static christmas.domain.constant.Discount.ZERO;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.constant.Benefit;
+import christmas.domain.constant.dish.Dessert;
+import christmas.domain.constant.dish.MainDish;
+import christmas.domain.constant.dish.Orderable;
+import christmas.domain.dto.BenefitDto;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class WeekDiscountCalculator {
+ private WeekDiscountCalculator() {
+
+ }
+
+ public static void apply(Map<Orderable, Integer> menus, BenefitDto benefitDto, DecemberDate visitDate) {
+ if (isWeekend(visitDate)) {
+ applyWeekendDiscount(menus, benefitDto);
+ return;
+ }
+ applyWeekdayDiscount(menus, benefitDto);
+ }
+
+ private static void applyWeekendDiscount(Map<Orderable, Integer> menus, BenefitDto benefitDto) {
+ if (getMainDishCount(menus) == ZERO.getValue()) {
+ return;
+ }
+ benefitDto.addBenefit(Benefit.WEEK_END_DISCOUNT, getMainDishCount(menus) * WEEK_DISCOUNT_UNIT.getValue());
+ }
+
+ private static void applyWeekdayDiscount(Map<Orderable, Integer> menus, BenefitDto benefitDto) {
+ if (getDessertCount(menus) == ZERO.getValue()) {
+ return;
+ }
+ benefitDto.addBenefit(Benefit.WEEK_DAY_DISCOUNT, getDessertCount(menus) * WEEK_DISCOUNT_UNIT.getValue());
+ }
+
+ private static int getDessertCount(Map<Orderable, Integer> menus) {
+ return countDishesOfCertainCategory(menus, Dessert.class);
+ }
+
+ private static int getMainDishCount(Map<Orderable, Integer> menus) {
+ return countDishesOfCertainCategory(menus, MainDish.class);
+ }
+
+ private static int countDishesOfCertainCategory(Map<Orderable, Integer> menus,
+ Class<? extends Orderable> category) {
+ int count = ZERO.getValue();
+ for (Entry<Orderable, Integer> entry : menus.entrySet()) {
+ if (entry.getKey().getClass() == category) {
+ count += entry.getValue();
+ }
+ }
+ return count;
+ }
+
+ private static boolean isWeekend(DecemberDate visitDate) {
+ int dateNumber = visitDate.date();
+ return dateNumber % ONE_WEEK.getValue() == ONE.getValue()
+ || dateNumber % ONE_WEEK.getValue() == TWO.getValue();
+ }
+
+} | Java | dto์ addํ๋ ๊ฒ๋ณด๋ค ๊ฒฐ๊ณผ๊ฐ์ ๋ฐํํ๋ฉด Dto์ ์์กด์ฑ์ ๋จ์ด๋จ๋ฆฌ๊ณ ๋ค๋ฅธ Dto์๋ ์ ๋ฌ ํ ์ ์์ต๋๋ค. |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | addPosition ๋ ๋ฐ์ดํฐ ๋ณ๊ฒฝ์ ๋ํ ์ค๋ช
์ด ๋๋ ๊ฒ ๊ฐ์ง๋ง,
run ์ด๋ผ๋ ํ์๋ฅผ ํํํ๋ ๋จ์ด๋ก ๋ฉ์๋๋ช
์ ์ง์ด๋ณด๋ฉด ์ด๋จ๊น์?
์ถํ์ ์๋์ฐจ ๊ธฐ๋ณธ ์ด๋ ์กฐ๊ฑด์ด +2 ๋ก ๋ฐ๋๋ค๊ณ ๊ฐ์ ํ์ ๋
addPosition ์ด๋ฉด ํด๋น ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ ์
์ฅ์์ position+1 ์ผ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋๋๋ฐ
run ์ผ๋ก ์ถ์ํ ๋์ด์์ผ๋ฉด +2 ๋ฅผ ํ๋ +1 ์ ํ๋ ์๋์ฐจ๊ฐ ์ด๋ํ๋ค๋ ํ์๋ฅผ ๋ํ๋ด์ ํผ๋์ด ์์ ๊ฒ ๊ฐ์ต๋๋ค ~ |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ฃผ๋ View ์ ์ญํ ์ ResultView ์ ์์ํ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | ์ถํ์ ์ฝ์์ด ์๋ GUI ํ๋ก๊ทธ๋จ์ผ๋ก ํ์ฅ๋๋ค๊ณ ํ์ ๋ Car ์ด๋ผ๋ pure ํด์ผํ๋ ๋ชจ๋ธ ํด๋์ค๊ฐ ๋๋ฝํ์ง์ง ์์๊น์~? |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | ์กฐ์์ ๋ธ๋กํฌ์ effective java ์๋ '๊ฐ์ฒด๋ ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํด ์ฐธ์กฐํ๋ผ.'
๋ผ๋ ๋ถ๋ถ์ด ์์ต๋๋ค.
ํ๋ฒ ์ฝ์ด๋ณด์๊ณ ๊ฐ์ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ ~
jaehun2841.github.io/2019/03/01/effective-java-item64/#%EC%9C%A0%EC%97%B0%ED%95%9C-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9D%84-%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4-%ED%83%80%EC%9E%85-%EB%B3%80%EC%88%98 |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | ๋ฐฐ์ด ์ฌ์ฉ์ ์ง์ํ๊ณ List ๋ก ์ต๋ํ ๋๊ฒจ๋ฐ์ผ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,18 @@
+import java.util.List;
+
+public class Main {
+ public static void main(String[] args) {
+ InputView inputView = new InputView();
+ RacingGame racingGame = new RacingGame();
+ GameWinner gameWinner = new GameWinner();
+ ResultView resultView = new ResultView();
+
+ List<Car> cars = inputView.registerCar(inputView.inputCarName());
+ int time = inputView.inputTime();
+ for (int i = 0; i < time; i++) {
+ racingGame.raceByTime(cars);
+ resultView.showResultByTime(cars);
+ }
+ resultView.showFinalResult(gameWinner.findWinner(cars));
+ }
+} | Java | Main ์ ์ฝ์ ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ ๋ณด๋ฉด ์ด๋จ๊น์~? |
@@ -0,0 +1,29 @@
+import java.util.Random;
+import java.util.List;
+
+public class RacingGame {
+ private static final int RANDOM_RANGE = 10;
+ private static final int MIN_MOVE_STANDARD = 4;
+
+ public void raceByTime(List<Car> cars) {
+ for (Car car : cars) {
+ int randomValue = giveRandomValue();
+ move(car, randomValue);
+ }
+ }
+
+ private int giveRandomValue() {
+ Random random = new Random();
+ return random.nextInt(RANDOM_RANGE);
+ }
+
+ private void move(Car car, int randomValue) {
+ if (canMove(randomValue)) {
+ car.run();
+ }
+ }
+
+ private boolean canMove(int number) {
+ return number >= MIN_MOVE_STANDARD;
+ }
+}
\ No newline at end of file | Java | ์ ๊ทผ์ ์ด์๋ฅผ ์๋ตํ์ ์ด์ ๊ฐ ์์๊น์? ์๋ตํ๋ฉด ์ด๋ค ์ ๊ทผ์ ์ด์๊ฐ ๋ถ์๊น์? |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | ๋ฉ์๋๋ช
์ ์ง์ ๋ ์กฐ๊ฑด ๋ณ๊ฒฝ์ ๊ฐ๋ฅ์ฑ์ ๊ผญ ๊ณ ๋ คํ๋๋ก ํ๊ฒ ์ต๋๋ค! ๋จ๋ฒ์ ์ดํด๋๋ ์ข์ ์์ ์ ์ํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | GUI ํ๋ก๊ทธ๋จ์ผ๋ก ํ์ฅ๋ ๊ฒฝ์ฐ๋ ๊ณ ๋ คํด์ผ ํ๋ค๋ ์ ๋ช
์ฌํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,29 @@
+import java.util.Random;
+import java.util.List;
+
+public class RacingGame {
+ private static final int RANDOM_RANGE = 10;
+ private static final int MIN_MOVE_STANDARD = 4;
+
+ public void raceByTime(List<Car> cars) {
+ for (Car car : cars) {
+ int randomValue = giveRandomValue();
+ move(car, randomValue);
+ }
+ }
+
+ private int giveRandomValue() {
+ Random random = new Random();
+ return random.nextInt(RANDOM_RANGE);
+ }
+
+ private void move(Car car, int randomValue) {
+ if (canMove(randomValue)) {
+ car.run();
+ }
+ }
+
+ private boolean canMove(int number) {
+ return number >= MIN_MOVE_STANDARD;
+ }
+}
\ No newline at end of file | Java | ๋ฉ์๋์ ์ ๊ทผ์ ์ด์์ ๋ชฐ๋ํ ๋๋จธ์ง ๋ณ์์ ์ ๊ทผ์ ์ด์๋ ๋ฏธ์ฒ ๊ณ ๋ คํ์ง ๋ชปํ๋ ๊ฒ ๊ฐ์ต๋๋ค. ์๋ตํ ๊ฒฝ์ฐ default ์ ๊ทผ์ ์ด์๊ฐ ๋์ด ํด๋น **ํจํค์ง** ๋ด์์ ์ ๊ทผ๊ฐ๋ฅํ๊ฒ ํฉ๋๋ค. ์ฌ๊ธฐ์์๋ ํด๋น ํด๋์ค ๋ด์์๋ง์ ์ ๊ทผ์ด ํ์ํ๋ฏ๋ก private๋ฅผ ๋ถ์ฌ ์์ ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | ์๋ฃ ๊ฐ์ฌํฉ๋๋ค๐ List์ธํฐํ์ด์ค ๊ตฌํํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค. |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | car ์ ์ํ๊ฐ ์ธ๋ถ์์ ์ ๊ทผ๊ฐ๋ฅํ public ์ธ๋ฐ์~
private ์ผ๋ก ๋ณ๊ฒฝํด์ฃผ์
์ผํ ๊ฒ ๊ฐ์ต๋๋ค ! |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | Winner ๊ฐ์ฒด์์ ๋ค๊ณ ์์ผ๋ฉด ์ข์๋งํ ์ํ(ํ๋ ๋ณ์)๋ค์ ์ ์ํ๊ณ ์ฑ
์์ ๋ถ์ฌํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | ๊ฐ์ฒด์งํฅ์์๋ ๊ฐ์ฒด์ ์ํ์ ์ง์ ์ ๊ทผํด์๋ ์๋ฉ๋๋ค.
private ์ผ๋ก ๋ณ๊ฒฝํ์๋ฉด getter ๋ก ๋ณ๊ฒฝํ์
์ผํ ๊ฒ ๊ฐ์์~ |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | java8 ์ stream api ๋ฅผ ์ ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์~? |
@@ -0,0 +1,50 @@
+import java.util.Scanner;
+import java.util.List;
+import java.util.ArrayList;
+
+public class InputView {
+ private static final int INITIAL_POSITION = 0;
+ private static final int MIN_NAME_LENGTH = 1;
+ private static final int MAX_NAME_LENGTH = 5;
+
+ public String inputCarName() {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ).");
+ return scanner.nextLine();
+ }
+
+ public List<Car> registerCar(String inputName) {
+ String[] names = inputName.split(",");
+ List<Car> cars = new ArrayList<>();
+ for (int i = 0; i < names.length; i++) {
+ checkValidName(names[i]);
+ cars.add(new Car());
+ cars.get(i).name = names[i];
+ cars.get(i).position = INITIAL_POSITION;
+ }
+ return cars;
+ }
+
+ public int inputTime() {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("์๋ํ ํ์๋ ๋ช ํ์ธ๊ฐ์?");
+ return scanner.nextInt();
+ }
+
+ private void checkValidName(String name) {
+ try {
+ checkNameLength(name);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private void checkNameLength(String name) throws Exception {
+ if (name.length() < MIN_NAME_LENGTH || name.length() > MAX_NAME_LENGTH) {
+ throw new InputNameException(name);
+ }
+ if (name.trim().isEmpty()) {
+ throw new InputNameException();
+ }
+ }
+} | Java | InputView ์๋ ์ํ๊ฐ์ด ์๋๋ฐ์,
util ํด๋์ค๋ก ํ์ฉ๋ ์ ์์ ๊ฒ ๊ฐ์์ ๋ชจ๋ ๋ฉ์๋๋ค์ static ์ ํ์ฉํด๋ณด์๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,29 @@
+import java.util.Random;
+import java.util.List;
+
+public class RacingGame {
+ private static final int RANDOM_RANGE = 10;
+ private static final int MIN_MOVE_STANDARD = 4;
+
+ public void raceByTime(List<Car> cars) {
+ for (Car car : cars) {
+ int randomValue = giveRandomValue();
+ move(car, randomValue);
+ }
+ }
+
+ private int giveRandomValue() {
+ Random random = new Random();
+ return random.nextInt(RANDOM_RANGE);
+ }
+
+ private void move(Car car, int randomValue) {
+ if (canMove(randomValue)) {
+ car.run();
+ }
+ }
+
+ private boolean canMove(int number) {
+ return number >= MIN_MOVE_STANDARD;
+ }
+}
\ No newline at end of file | Java | random ์ผ๋ก ์ธํด ๊ฒ์์ ํต์ฌ pulbic ๋ฉ์๋๊ฐ ํ
์คํธ ๋ถ๊ฐ๋ฅํด์ก๋๋ฐ
์ด๋ป๊ฒ ๊ฐ์ ํด ๋ณผ ์ ์์๊น์? |
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | ๊ท์น : setter ๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค (getter ์ฌ์ฉ์ ์ง์ํ๋ค)
๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ์์ setter ์ getter ์ฌ์ฉ์ ๋๋๋ก ์ง์ํ๋ผ๊ณ ํ๋ ์ด์ ๊ฐ ๋ฌด์์ผ๊น์? |
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | ๋๋ค์ ํตํด ํน์ ์กฐ๊ฑด์์ ์ ์งํ๋ ๊ฒ์์ ๋ฃฐ์ ์๋์ฐจ๋ผ๋ ๋ชจ๋ธ ํด๋์ค๊ฐ ์๊ณ ์์ ํ์๊ฐ ์์๊น์?
์๋ฅผ ๋ค์ด ๊ฒ์์ ๋ชจ๋๊ฐ ์ถ๊ฐ๋์ด์ ๋๋ค ๋ฃฐ์ด ์๋ ๋ค๋ฅธ ๊ฒ์ ๋ฃฐ์ด ์๊ธด๋ค๊ณ ํ์ ๋,
๋ชจ๋ธ์ด ๊ฒ์์ ๋ฃฐ์ ๊ด๊ณ์์ด pure ํ๊ฒ ์ง์ฌ์ ธ ์์ผ๋ฉด ๋ชจ๋ธ์ ์์ ํ์ง ์์๋ ๋์ง ์์๊น์?
moveForward ๊ฐ ๋จ์ํ car ์ position ์ ++ ํ๋ ๋ก์ง๋ง ๊ฐ์ง๊ณ ์์ผ๋ฉด ์ด๋ค์ง ์๊ฒฌ๋๋ ค๋ด
๋๋ค ~ |
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | ๋ค์์๋ code formatting ์ ํ ๋ค์ ์ ์ถํ๋ ์ต๊ด์ ๋ค์ด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ ~ :) |
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | 10, 4 ๊ฐ ์ด๋ค ์๋ฏธ๋ฅผ ์ง๋๊ณ ์๋์ง 2๋
๋ค์ ์ด ์ฝ๋๋ฅผ ๋ณด๊ฑฐ๋ ํ์ธ์ด ๋ณด๋ฉด ์ดํด๊ฐ ์ ์๋ ์ ์์ ๊ฒ ๊ฐ์์.
์ด๋ฐ magic number ๋ฅผ ์์๋ก ์ถ์ถํด๋ณด๋๊ฒ ์ด๋จ๊น์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | primitive type ์ด ์๋๋ผ wrapper type ์ผ๋ก ์ ์ธํ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | ์ ๊ทผ์ ์ด์๊ฐ ๋น ์ง ์ด์ ๊ฐ ์์๊น์?
์ ๊ทผ์ ์ด์๋ฅผ ์๋ตํ๋ฉด ์ด๋ค ์ ๊ทผ์ ์ด์๊ฐ ์ ์ฉ๋ ๊น์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | InputView ๊ฐ์ฒด๋ ์ํ๋ฅผ ๊ฐ์ง์ง ์๋ util ํด๋์ค์ฒ๋ผ ๋น์ถฐ์ง๋๋ฐ
static ๋ฉ์๋๋ค๋ก ๊ตฌ์ฑํ์ฌ ๊ฐ์ฒด ์์ฑ ๋น์ฉ์ ์ ๊ฐ์์ผ๋ณด๋๊ฑด ์ด๋ค๊ฐ์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | ์ฌ์ฉํ์ง ์๋ ์ฝ๋๋ ๊ณผ๊ฐํ ์ญ์ ํ์๋๊ฒ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | ์ค๋ฐ๊ฟ, ์คํ์ด์ค๋ ์ปจ๋ฒค์
์
๋๋ค.
๋ฌธ๋งฅ์ด ๋ฌ๋ผ์ง๋ค๋๊ฐ, ํ๋์ ๋ฉ์๋ ์ฌ์ด ๋ฑ์ ํ๋ฒ์ ์ค๋ฐ๊ฟ์ผ๋ก ๊ตฌ๋ถ ์ง์ด์ ๊ฐ๋
์ฑ์ ๋์ฌ๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | ์ด ๋ถ๋ถ์ java 8 ์ stream api ๋ฅผ ์ฌ์ฉํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | ์ ์ธ๊ณผ ํ ๋น์ด ๋ถ๋ฆฌ๋ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,27 @@
+import java.util.List;
+
+public class OutputView {
+ private static final String DRIVE = "-";
+
+ public void resultMessage() {
+ System.out.println("\n์คํ ๊ฒฐ๊ณผ");
+ }
+
+ public void oneTrialMessage(List<Car> cars) {
+ for(Car car: cars) {
+ System.out.println(car.getName() + ": " + raceOneTrial(car));
+ }
+ }
+
+ private StringBuilder raceOneTrial(Car car) {
+ StringBuilder goSignal = new StringBuilder();
+ for(int i = 0; i<car.getPosition(); i++) {
+ goSignal.append(DRIVE);
+ }
+ return goSignal;
+ }
+
+ public void getWinnerMessage(List<String> winnernames) {
+ System.out.println(String.join(",", winnernames + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค."));
+ }
+} | Java | ๊ฒ์ ์์์ ์ํ input ๊ณผ ๊ด๋ จ๋ print ๋ inputview ์ ์๋๊ฒ ์ด๋จ๊น์? |
@@ -0,0 +1,27 @@
+import java.util.List;
+
+public class OutputView {
+ private static final String DRIVE = "-";
+
+ public void resultMessage() {
+ System.out.println("\n์คํ ๊ฒฐ๊ณผ");
+ }
+
+ public void oneTrialMessage(List<Car> cars) {
+ for(Car car: cars) {
+ System.out.println(car.getName() + ": " + raceOneTrial(car));
+ }
+ }
+
+ private StringBuilder raceOneTrial(Car car) {
+ StringBuilder goSignal = new StringBuilder();
+ for(int i = 0; i<car.getPosition(); i++) {
+ goSignal.append(DRIVE);
+ }
+ return goSignal;
+ }
+
+ public void getWinnerMessage(List<String> winnernames) {
+ System.out.println(String.join(",", winnernames + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค."));
+ }
+} | Java | ๋ฉ์๋ ์ด๋ฆ์ด ๋๋ฌธ์๋ก ์์ํ๊ณ ๋ช
์ฌ๋ค์ ~ |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | ๋ฆฌํด์ ์ด๋ ๊ฒ ์ ์ผ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | trim ๊ณผ checkNameLength ๋๊ฐ์ ์ญํ ์ ์ํํ๋ ๋ฉ์๋๋ค์
๋ฉ์๋๋ค์ ์ฌ์ฌ์ฉํ ์ ์๊ฒ ๋ค์ด๋ฐ ๋ณ๊ฒฝ, ๋จ์ผ์ฑ
์์์น์ ์ง์ผ์ ๋ฆฌํฉํ ๋ง ํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,68 @@
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+public class InputView {
+ private static final int MAX_LENGTH = 6;
+ private static final Scanner scanner = new Scanner(System.in);
+
+ public static List<Car> inputCarName() {
+ String name = scanner.nextLine();
+ String[] splittedInputCarName = splitInputCarName(name);
+ String[] trimmedInputCarName = trimInputCarName(splittedInputCarName);
+
+ try {
+ processStreamAboutCheckName(trimmedInputCarName);
+ } catch(IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ inputCarName();
+ }
+
+ List<Car> cars = new ArrayList<>();
+ for(int i = 0; i< splittedInputCarName.length; i++) {
+ cars.add(new Car(trimmedInputCarName[i]));
+ }
+ return cars;
+ }
+
+ private static String[] splitInputCarName(String name) {
+ return name.split(",");
+ }
+
+ private static String[] trimInputCarName(String[] name) {
+ for(int i = 0; i<name.length; i++) {
+ name[i] = name[i].trim();
+ }
+ return name;
+ }
+
+ private static void checkNameLength(String name) {
+ if(name.length() >= MAX_LENGTH) {
+ throw new IllegalArgumentException("์ด๋ฆ์ 5์ ์ดํ๋ง ๊ฐ๋ฅํฉ๋๋ค.");
+ }
+ }
+
+ private static void processStreamAboutCheckName(String[] trimmedInputCarName) {
+ Stream<String> stream = Arrays.stream(trimmedInputCarName);
+ stream.forEach(e -> checkNameLength(e));
+ }
+
+ public static int inputTrial() {
+ return scanner.nextInt();
+ }
+
+ public static void inputCarNamesMessage() {
+ System.out.println("๊ฒฝ์ฃผํ ์๋์ฐจ ์ด๋ฆ์ ์
๋ ฅํ์ธ์.(์ด๋ฆ์ ์ผํ(,) ๊ธฐ์ค์ผ๋ก ๊ตฌ๋ถ)");
+ }
+
+ public static void inputCountMessage() {
+ System.out.println("์๋ํ ํ์๋ ๋ชํ์ธ๊ฐ์?");
+ }
+}
+
+
+
+
+ | Java | return scanner.nextInt(); ๋ก ์ถฉ๋ถํ ๊ฒ ๊ฐ์ต๋๋ค ~
๊ทธ๋ฆฌ๊ณ input() ๋ฉ์๋๊ฐ inputCount() ๋ฉ์๋๋ฅผ ํฌํจํ๋ ๋ฏํ ๋ค์ด๋ฐ์ธ ๊ฒ ๊ฐ์ต๋๋ค
๋์ ๊ตฌ๋ถ์ ์ํด ๋ฉ์๋ ์ด๋ฆ์ ์ข ๋ณ๊ฒฝํด๋ณด์๋ฉด ์ด๋จ๊น์?
(Count ๋ผ๋ ๋ค์ด๋ฐ์ ๋๋ฌด ๊ด๋ฒ์ํ ๋จ์ด์ธ ๊ฒ ๊ฐ์ต๋๋ค. ์๋ ํ์๋ฅผ ๋ํ๋ด๋ ๋ ๊ด์ฐฎ์ ๋ค์ด๋ฐ์ ์์๊น์?) |
@@ -0,0 +1,27 @@
+import java.util.List;
+
+public class OutputView {
+ private static final String DRIVE = "-";
+
+ public void resultMessage() {
+ System.out.println("\n์คํ ๊ฒฐ๊ณผ");
+ }
+
+ public void oneTrialMessage(List<Car> cars) {
+ for(Car car: cars) {
+ System.out.println(car.getName() + ": " + raceOneTrial(car));
+ }
+ }
+
+ private StringBuilder raceOneTrial(Car car) {
+ StringBuilder goSignal = new StringBuilder();
+ for(int i = 0; i<car.getPosition(); i++) {
+ goSignal.append(DRIVE);
+ }
+ return goSignal;
+ }
+
+ public void getWinnerMessage(List<String> winnernames) {
+ System.out.println(String.join(",", winnernames + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค."));
+ }
+} | Java | ์ฌ๊ธฐ์๋ StringBuilder ๋ก ๋ฐ๋ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,39 @@
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class RacingGame {
+ private List<String> winnernames = new ArrayList<>();
+
+ public void race(List<Car> cars) {
+ for(Car car: cars) {
+ goOrStay(car);
+ }
+ }
+
+ private void goOrStay(Car car) {
+ if(Rule.isGoForward()) {
+ car.goForward();
+ }
+ }
+
+ public List<String> getWinner(List<Car> cars) {
+ int positionOfWinner = findPositionOfWinner(cars);
+ cars = cars.stream().filter(car -> (car.getPosition() == positionOfWinner)).collect(Collectors.toList());
+ for (Car car : cars) {
+ this.winnernames.add(car.getName());
+ }
+ return winnernames;
+ }
+
+ private int findPositionOfWinner(List<Car> cars) {
+ List<Integer> position = new ArrayList<>();
+ int positionOfWinner;
+ for(Car car: cars) {
+ position.add(car.getPosition());
+ }
+ positionOfWinner = Collections.max(position);
+ return positionOfWinner;
+ }
+}
\ No newline at end of file | Java | ์ ์ฒด์ ์ผ๋ก ํ
์คํธ ์ฝ๋๊ฐ ์์ด์ ์์ฝ๋ค์ ใ
ใ
|
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | ๋ถํ์ํ setter/getter๋ ๊ฐ์ฒด์ ์์ฑ์ ์ธ์ ๋ ๋ณ๊ฒฝํ ์ ์๋ ์ํ๊ฐ ๋๊ธฐ ๋๋ฌธ์ ์ง์ํ๋๋ก ํ๋ ๊ฒ ๊ฐ์ต๋๋ค! ๊ตณ์ด ์ฌ์ฉํ์ง ์์๋ ๋๋ค๋ฉด ๋ฐ์ํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | ๊ฒ์์ ๋ฃฐ์ ์๋์ฐจ ๋ชจ๋ธ ํด๋์ค๊ฐ ๊ฐ์ง๊ณ ์์ ํ์๋ ์๋ค๊ณ ์๊ฐํ๋๋ฐ ๋ณด๋ค ๋ ์ข์ ๋ฐฉ๋ฒ์ ์์ง ์๊ฐํด๋ณด์ง ๋ชปํ ๊ฒ ๊ฐ์ต๋๋ค. ์๋๋ Rule ํด๋์ค๋ฅผ ๋ฐ๋ก ๋ง๋ค์ด ๊ตฌํํ๋ ค๊ณ ํ์ผ๋ ์์ง ๋ฐฉ๋ฒ์ ๊ณ ๋ฏผ ์ค์ ์์ต๋๋ค! ๊ณ ๋ฏผํด์ ๋ฐ์ํ ์ ์๋๋ก ๋
ธ๋ ฅํด๋ณด๊ฒ ์ต๋๋ค |
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | ๋ต code formatting ํ๋ ์ต๊ด์ ๋ค์ด๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+public class Car {
+ private String name;
+ private int position;
+
+ Car(String name) {
+ this.name = name;
+ this.position = 0;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void goForward() {
+ this.position++;
+ }
+} | Java | magic number ์ญ์ ์ถํ์ ๋ดค์ ๋ ์ดํดํ ์ ์๋๋ก ์์๋ก ์ ์ธํ๋ ์ต๊ด์ ๋ค์ด๊ฒ ์ต๋๋ค! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.