code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -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 ์ญ์ ์ถํ์ ๋ดค์ ๋ ์ดํดํ ์ ์๋๋ก ์์๋ก ์ ์ธํ๋ ์ต๊ด์ ๋ค์ด๊ฒ ์ต๋๋ค! |
@@ -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 | ๋ฉ์๋ ์ฒด์ด๋์ ์ ์ฉํด์ Arrays.stream(trimmedInputCarName).forEach(~~)
๋ก ์ด์ด ๋ถ์ด์๋ฉด ์ด๋จ๊น์ |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ๋ฉ์๋๋ค์ด static ์ธ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ๋ชจ๋ ๋ฉ์๋๊ฐ public ์ผ๋ก ๊ณต๊ฐ๋์ด์๋ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | RacingGame ์์ Cars ์ ๋ํ ์ํ๋ฅผ ๋ค๊ณ ์์ผ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,12 @@
+import java.util.ArrayList;
+
+public class Main {
+ public static void main(String[] args) {
+ RacingGame racing = new RacingGame();
+ ArrayList<Car> cars = new ArrayList<>();
+ cars = racing.registerCarNames(cars, racing.nameSet(InputView.setNames()));
+ int number = InputView.inputNumber();
+ ResultView result = new ResultView();
+ result.resultRacing(number, cars);
+ }
+} | 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,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ๋ฉ์๋๋ช
์ด ๋๋ถ๋ถ ๋ช
์ฌ์ธ ๊ฒ ๊ฐ์๋ฐ ๋์ฌํ์ผ๋ก ๋ฐ๊ฟ๋ณด๋ฉด ์ด๋จ๊น์~
๊ทธ๋ฆฌ๊ณ cnt ๊ฐ์ ๊ฒฝ์ฐ์๋ ํ๋ค์์ผ๋ก ์ ์ด์ฃผ๋ฉด ์คํฐ๋ ๊ท์น์ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,136 @@
+import java.util.Random;
+import java.util.ArrayList;
+
+public class RacingGame {
+ static final int MAX_LENGTH = 6;
+ static final int CAN_GO_NUMBER = 4;
+ static final int ORIGINAL_POSITION = 0;
+
+ public String[] nameSet(String inputNames) {
+ String[] names = inputNames.split(",");
+ for (int i = 0; i < names.length; i++) {
+ names = nameLengthCheck(names, i);
+ }
+ return names;
+ }
+
+ public ArrayList<Car> registerCarNames(ArrayList<Car> cars, String[] nameSet) {
+ for (int i = 0; i < nameSet.length; i++) {
+ cars.add(new Car(nameSet[i], ORIGINAL_POSITION));
+ }
+ return cars;
+ }
+
+ public String[] nameLengthCheck(String[] names, int i) {
+ if (names[i].length() >= MAX_LENGTH) {
+ String inputNames = InputView.overNames();
+ names = inputNames.split(",");
+ }
+ return names;
+ }
+
+ public String getInputNames(String names) {
+ String[] carNames = nameSet(names);
+ String cars = "";
+ for (int i = 0; i < carNames.length; i++) {
+ cars += carNames[i] + "";
+ }
+ return cars;
+ }
+
+ public static int randomValue() {
+ Random random = new Random();
+ return random.nextInt(10);
+ }
+
+ public static ArrayList<Car> valueCheck(ArrayList<Car> cars, int randomValue, int i) {
+ if (randomValue >= CAN_GO_NUMBER) {
+ cars.get(i).move();
+ }
+ return cars;
+ }
+
+ public static ArrayList<Car> randomToNumber(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ valueCheck(cars, randomValue(), i);
+ }
+ return cars;
+ }
+
+ public static Car winnerJudge(ArrayList<Car> cars, int max, int i, String winner) {
+ if (max < cars.get(i).getPosition()) {
+ max = cars.get(i).getPosition();
+ winner = cars.get(i).getName();
+ }
+ Car passInfo = new Car(winner, max);
+ return passInfo;
+ }
+
+ public static int sameScoreCount(int cnt, int max, ArrayList<Car> cars, int i) {
+ if (max == cars.get(i).getPosition()) {
+ cnt += 1;
+ }
+ return cnt;
+ }
+
+ public static ArrayList<String> winnersNameSet(ArrayList<String> winners, int max, ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ winners = sameScoreWinners(max, cars, winners, i);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> sameScoreWinners(int max, ArrayList<Car> cars, ArrayList<String> winners, int i) {
+ if (max == cars.get(i).getPosition()) {
+ winners.add(cars.get(i).getName());
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnerNameReturn(int cnt, String winner) {
+ ArrayList<String> winners = new ArrayList<>();
+ if (cnt == 0) {
+ winners.add(winner);
+ }
+ return winners;
+ }
+
+ public static ArrayList<String> winnersNameReturn(int cnt, int max, ArrayList<Car> cars) {
+ ArrayList<String> winners = new ArrayList<>(cnt);
+ winners = winnersNameSet(winners, max, cars);
+ return winners;
+ }
+
+ public static ArrayList<String> findWinner(ArrayList<Car> cars) {
+ int max = cars.get(0).getPosition();
+ String winner = cars.get(0).getName();
+ for (int i = 1; i < cars.size(); i++) {
+ max = winnerJudge(cars, max, i, winner).getPosition();
+ winner = winnerJudge(cars, max, i, winner).getName();
+ }
+ int cnt = 0;
+ for (int i = 0; i < cars.size(); i++) {
+ cnt = sameScoreCount(cnt, max, cars, i);
+ }
+ ArrayList<String> winners;
+ winners = winnerNameReturn(cnt, winner);
+ if (cnt > 0) {
+ winners = winnersNameReturn(cnt, max, cars);
+ }
+ return winners;
+ }
+
+ public String getWinner(ArrayList<Car> cars, int[] randomNumbers) {
+ ResultView v = new ResultView();
+
+ for (int i = 0; i < cars.size(); i++) {
+ cars = valueCheck(cars, randomNumbers[i], i);
+ }
+ ArrayList<String> winners = findWinner(cars);
+ String winner = "";
+ for (int i = 0; i < winners.size(); i++) {
+ winner += winners.get(i) + " ";
+ }
+ return winner;
+ }
+} | Java | ํ ํด๋์ค์์ ์ฑ
์์ ๋ง์ด ๋ค๊ณ ์๊ธฐ ๋๋ฌธ์ ํด๋์ค ๊ธธ์ด๊ฐ ๋์ด๋ ๊ฒ ๊ฐ์๋ฐ์,
winner ์ ๋ํ ๋ก์ง์ ๋ค๋ฅธ ํด๋์ค๋ฅผ ๋ง๋ค์ด ์์ํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,39 @@
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+
+public class RacingGameTest {
+ RacingGame r;
+ ResultView v;
+
+ @Before
+ public void setUp() {
+ r = new RacingGame();
+ v = new ResultView();
+ }
+
+ @Test
+ public void carNamesInputTest() {
+ String input = "์์ก, ์๋์ฐ, ๊ตฌ๋ฆ, ๊ทธ๋ฆฌ์ฆ, ํค์บฃ";
+ assertEquals("์์ก ์๋์ฐ ๊ตฌ๋ฆ ๊ทธ๋ฆฌ์ฆ ํค์บฃ", r.getInputNames(input));
+ }
+
+ @Test
+ public void winnerTest() {
+ ArrayList<Car> cars = new ArrayList<>();
+ String input = "์์ก, ์๋์ฐ, ๊ตฌ๋ฆ, ๊ทธ๋ฆฌ์ฆ, ํค์บฃ";
+ int number = 1;
+ int[] randomNumbers = {1, 3, 5, 8, 2};
+ cars = r.registerCarNames(cars, r.nameSet(input));
+ assertEquals(" ๊ตฌ๋ฆ ๊ทธ๋ฆฌ์ฆ ", r.getWinner(cars, randomNumbers));
+ }
+
+ @After
+ public void tearDown() {
+ r = null;
+ }
+}
\ No newline at end of file | Java | ์คํฐ๋ ๊ท์น : ๋ณ์๋ช
์ ์ค์ฌ์ฐ์ง ์๋๋ค |
@@ -0,0 +1,40 @@
+import java.util.ArrayList;
+
+public class ResultView {
+ public static void resultRacing(int number, ArrayList<Car> cars) {
+ System.out.println("์คํ ๊ฒฐ๊ณผ");
+ for (int i = 0; i < number; i++) {
+ RacingGame.randomToNumber(cars);
+ resultRacing(cars);
+ System.out.println("");
+ }
+ ArrayList<String> winners = RacingGame.findWinner(cars);
+ finalResultView(winners);
+ }
+
+ public static void resultRacing(ArrayList<Car> cars) {
+ for (int i = 0; i < cars.size(); i++) {
+ System.out.println(cars.get(i).getName() + ":" + racingView(cars.get(i).getPosition()));
+ }
+ }
+
+ public static String racingView(int n) {
+ String car = "";
+ for (int i = 0; i < n; i++) {
+ car += "-";
+ }
+ return car;
+ }
+
+ public static void finalResultView(ArrayList<String> winners) {
+ if (winners.size() == 1) {
+ System.out.println(winners.get(0) + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค.");
+ }
+ if (winners.size() > 1) {
+ for (int i = 0; i < winners.size() - 1; i++) {
+ System.out.print(winners.get(i) + ",");
+ }
+ System.out.println(winners.get(winners.size() - 1) + "๊ฐ ์ต์ข
์ฐ์นํ์ต๋๋ค.");
+ }
+ }
+} | Java | ResultView ๋ ์ดํ๋ฆฌ์ผ์ด์
์ ํ๋ฆ์ด๋ ๋ก์ง์ ์ ํ์ ์์ด ๊ทธ๋ฅ ๋ค์ด์จ input ์ ๋ํด์ ์ถ๋ ฅ๋ง ํด์ฃผ๋ ์ ๋์ ์ญํ ์ ํ๋๋ก ๋ณ๊ฒฝํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -5,6 +5,7 @@
import com.project.Project.domain.interaction.ReviewLike;
import com.project.Project.domain.member.Member;
import com.project.Project.domain.member.RecentMapLocation;
+import com.project.Project.domain.review.Review;
import java.util.List;
import java.util.Optional;
@@ -21,4 +22,9 @@ public interface MemberService {
public List<ReviewLike> getReviewLikeList(Member member);
Long delete(Member member);
+
+
+
+
+
} | Java | ์ด ๋ฉ์๋๋ฅผ ReviewService๋ก ์ฎ๊ธฐ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค!
๊ฐ๋ง๋ณด๋ ์ด์ ์ ์์ฑํ๋ ์์ getReviewLikeList๋ ์๋ชป ์์นํด ์๋ ๊ฒ ๊ฐ๋ค์ |
@@ -7,6 +7,7 @@
import com.project.Project.domain.interaction.ReviewLike;
import com.project.Project.domain.member.Member;
import com.project.Project.domain.member.RecentMapLocation;
+import com.project.Project.domain.review.Review;
import com.project.Project.repository.interaction.FavoriteRepository;
import com.project.Project.repository.interaction.ReviewLikeRepository;
import com.project.Project.repository.member.MemberCustomRepository;
@@ -79,4 +80,6 @@ public Integer getReviewCnt(Member member) {
public List<ReviewLike> getReviewLikeList(Member member) {
return reviewLikeRepository.findByReviewLikeStatusAndMember(ReviewLikeStatus.LIKED, member);
}
+
+
} | Java | ๋ง์ฐฌ๊ฐ์ง๋ก ReviewServiceImpl์ชฝ์ผ๋ก ์ฎ๊ธฐ๋ฉด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -2,6 +2,7 @@
import com.project.Project.domain.member.Member;
import com.project.Project.domain.review.Review;
+import com.querydsl.core.types.dsl.BooleanExpression;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;
@@ -40,4 +41,6 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {
@Query("select review from Review review where review.author.id = :memberId and review.id = :reviewId")
Optional<Review> findReviewByAuthorAndReview(Long memberId, Long reviewId);
+
+ List<Review> findReviewsByAuthor(Member member);
} | Java | ์ด ๋ฉ์๋๋ deleted ํ๋ ์ ์ธํ๋ ๊ฒ ๋ฐ์ํ์๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | `@Enumerated` ๋ถ์ฌ์ฃผ์ค๊บผ์ฃ ? ๐ |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | ์ด๊ฑธ ๋์ณค๋ค์;;ใ
ใ
|
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | ๊ฒจ์ฐ ํ๋ ์ฐพ์์ต๋๋ค๐ |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | extension์ ์ด๋ค ๋ณ์ ์ธ๊ฐ์..?! ์ ๋ ํด๋, ํ์ผ ๊ด๋ จ ์ํฐํฐ ์ค๊ณ ์ค์ธ๋ฐ ์นผ๋ผ ์ค์ ์ ์ ๋ง ์ํ์ ๊ฒ ๊ฐ์์ ๊ณ ์ํ์
จ์ต๋๋ค!! ๐ |
@@ -0,0 +1,40 @@
+package com.mybox.domain.storage;
+
+import com.mybox.domain.common.BaseTimeEntity;
+import java.time.LocalDateTime;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import lombok.Getter;
+import org.springframework.data.annotation.LastModifiedDate;
+
+@Getter
+@Entity
+public class StorageObjectMetaData extends BaseTimeEntity {
+
+ @Id
+ @GeneratedValue(strategy = GenerationType.IDENTITY)
+ private Long id;
+
+ private String name;
+ private StorageObjectType type;
+ private String extension;
+ private Long size;
+ private String path;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "namespace_id")
+ private Namespace namespace;
+
+ @ManyToOne(fetch = FetchType.LAZY)
+ @JoinColumn(name = "parent_id")
+ private StorageObjectMetaData parentDirectory;
+
+ @LastModifiedDate
+ private LocalDateTime lastModifiedAt;
+
+} | Java | ํ์ผ ํ์ฅ์์
๋๋ค! |
@@ -0,0 +1,29 @@
+import { Console } from '@woowacourse/mission-utils';
+import parseInput from './parseInput';
+
+const inputHandler = {
+ async dateHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ validate(Number(input));
+ return Number(input);
+ } catch (e) {
+ Console.print(e.message);
+ return this.dateHandler(userInput, validate);
+ }
+ },
+
+ async orderHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ const menu = parseInput(input);
+ validate(menu);
+ return Object.fromEntries(menu);
+ } catch (e) {
+ Console.print(e.message);
+ return this.orderHandler(userInput, validate);
+ }
+ },
+};
+
+export default inputHandler; | JavaScript | ์์ ์
๋ ฅ ๋ฐ๊ณ ๋์ ๋ฐ๋ก ๋ถ๋ฆฌํ๋ ๋ฐฉ๋ฒ๋ ์์๋ค์ ์ด ๋ฐฉ๋ฒ์ ์๊ฐํ์ง ๋ชปํ๋ ๊ฒ ๊ฐ์ต๋๋ค ใ
..
์ถ๊ฐ๋ก trim,split,map์ ๊ฒฐํฉํด์ ์ฐ๋ ๊ฒ๋ณด๋ค ์ ๊ทํํ์์ ์ฌ์ฉํด๋ณด๋๊ฑด ์ด๋จ๊น์? |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ํน์ new Date() ๋ง๊ณ ๋๋จธ์ง ๊ฐ์ ์ฌ์ฉํ์ ์ด์ ๊ฐ ์์๊น์?? |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ํด๋น ๋ถ๋ถ๋ ์ ๊ทํํ์์ ์ฐ๋ฉด if๋ฅผ ํ๋๋ง ์จ๋ ๋ ๊ฒ ๊ฐ์ต๋๋ค ! |
@@ -0,0 +1,29 @@
+import { Console } from '@woowacourse/mission-utils';
+import parseInput from './parseInput';
+
+const inputHandler = {
+ async dateHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ validate(Number(input));
+ return Number(input);
+ } catch (e) {
+ Console.print(e.message);
+ return this.dateHandler(userInput, validate);
+ }
+ },
+
+ async orderHandler(userInput, validate) {
+ try {
+ const input = await Console.readLineAsync(userInput);
+ const menu = parseInput(input);
+ validate(menu);
+ return Object.fromEntries(menu);
+ } catch (e) {
+ Console.print(e.message);
+ return this.orderHandler(userInput, validate);
+ }
+ },
+};
+
+export default inputHandler; | JavaScript | ์ ๊ท ํํ์์ ํ์ฉํ์ผ๋ฉด ๊ตณ์ด ํ์ฑํ๋ ์์
์ด ํ์ํ์ง ์์์ ์๋ ์๊ฒ ๋ค์ ์ข์ ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค ใ
ใ
๐คฃ |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๋ฏธ์
์์ 2023๋
2์๋ก ์ ํํ ๊ธฐ๊ฐ์ ๋ช
์ํด์ฃผ์๊ธฐ์ ๊ด๋ จ๋ ๊ฑด ์ต๋ํ Date ๊ฐ์ฒด ์์ฑ์ด ์๋ ๊ตฌํ์ผ๋ก ํด๊ฒฐํ๊ณ ์ถ๋ค๋ ์ ์์ ์ฌ์ฉ์ ํ์ง ์์ผ๋ ค๊ณ ํ์ต๋๋ค ! ๋ ๊ทธ๋ฌ๋ค๋ณด๋ ์ถฉ๋ถํ ๋ค๋ฅธ ํํ์์ผ๋ก ์ผ์๋ฅผ ํ๋ณํ ์ ์๋ค๊ณ ์๊ฐํ์ฌ ๊ทธ๋ ๊ฒ ๊ตฌํํ๋ ๊ฑฐ ๊ฐ๋ค์ ๐ค |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ๋ฏธ์
์ ์งํํ๋ฉด์ ๊ฐ์ธ์ ์ผ๋ก key๊ฐ์ ํ๊ธ๋ก ํ๋๊ฒ ๋ง๋๊ฐ? ํ๋ ์๋ฌธ์ด ๋ค์์ต๋๋ค!
์ฌ๊ฒฝ๋ ์๊ฐ์ด ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,28 @@
+import InputView from '../View/InputView';
+import OutputView from '../View/OutputView';
+import Client from './Client';
+
+class PromotionController {
+ async insertInput() {
+ const client = new Client(
+ await InputView.readDate(),
+ await InputView.readOrder(),
+ );
+ const date = client.getDate();
+ this.printOutput(client, date);
+ }
+
+ printOutput(client, date) {
+ OutputView.printIntro();
+ OutputView.printPreview(date);
+ OutputView.printMenuTitle(client);
+ OutputView.printBeforeDiscount(client);
+ OutputView.printGift(client);
+ OutputView.printBenefit(client);
+ OutputView.printDiscountAmount(client);
+ OutputView.printAfterDiscount(client);
+ OutputView.printEventBadge(client);
+ }
+}
+
+export default PromotionController; | JavaScript | Controller ๋ก์ง์ด ๊น๋ํด์ ๋ณด๊ธฐ ์ข๋ค์ ๋ฐฐ์๊ฐ๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ ๋ ์ด๋ถ๋ถ ๋๋ฌธ์ ๊ณคํน์ ์น๋ค๋๋ฐ ๋ค๋ค ๋น์ทํ ์๊ฐ์ด์
จ๋๋ด์ ๐ค ํนํ ์ดํ์ธ ์ฆ์ ์ฌ๋ถ๋ฅผ ํ๋ณํ ๋ `์ดํ์ธ.price` ์์ผ๋ก ํธ์ถํด์ผํ๋ ์ ๋๋ฌธ์ ์ดํ์ธ์ ๊ฐ๊ฒฉ๊ณผ ๋ช
์นญ์ ๋ฐ๋ก ์ฆ์ ๋ฉ๋ด์ ๋ํ ์์๋ก ์ ์ธํ๊ธฐ๋ ํ์ต๋๋ค..
๋ก์ง์์์๋ ํธ์ถ๋์ง ์์ง๋ง, ํ
์คํธ ์ฝ๋์์๋ ๋ ํธ์ถํด์ผํ๋ ๋ถ๋ถ๋ค์ด ์์ด ๊ณ ๋ฏผ์ด ๋ง์๋ค์ ใ
ใ
์ฌ์ค..
```js
SOUP : { name: ์์ก์ด ์ํ, price : 6000, ... }
```
์๋ฐ ์์ผ๋ก ์ ์ธ ํํ๋ฅผ ๋ฐ๊พธ๊ฑฐ๋ id ๋ก SOUP๋ฅผ ์ ์ธํด์ ํค๊ฐ์ ํ๋ณํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋ค๋ฉด ํ๊ธ๋ก ์์ฑํ๋ ๋ก์ง์ ๋์ด๋ผ ์ ์์์ ๊ฑฐ๋ ์๊ฐ์ ํ์์ด์...ใ
ใ
์
๋ ฅ์ ๋ํ ๋ณํ์ด ์ฌ์ด ํํ๋ฅผ ์ฑํํ๊ณ ์ ํ๋ ๊ฑฐ ๊ฐ์ต๋๋ค ๐คฃ |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | Object.freeze() ๋ ์์ ๋๊ฒฐ์ ํด์ฃผ๊ธฐ ๋๋ฌธ์ deepFreeze์ ๋ํด์ ์์๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์!!
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze#%EB%B0%B0%EC%97%B4_%EB%8F%99%EA%B2%B0 |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ด๋ฒ์ ๊ธ์ก์ ๊ดํ ์ซ์๋ฅผ ๋ค๋ฃจ๋ฉด์ `numeric seperator` ๋ผ๋ ๋ฐฉ์์ ์๊ฒ๋์๋๋ฐ
๊ฐ์ธ์ ์ผ๋ก ์ซ์ ๋จ์๊ฐ ํ๋์ ๋ค์ด์์ ์ข๋๋ผ๊ตฌ์!
```suggestion
GIFT_CONDITION: 120_000,
``` |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ํจ์ ๋ก์ง์ด ์ฌ๋ฌ์ค์ด๋ผ ์๋์ฒ๋ผ ์์ ํ๋๊ฑด ์ด๋จ๊น์??
```suggestion
const parseInput = (userInput) => {
return userInput
.trim()
.split(",")
.map((item) => {
const [name, quantity] = item.trim().split("-");
return [name, Number(quantity)];
});
};
```
https://github.com/airbnb/javascript#whitespace--implicit-arrow-linebreak
https://github.com/airbnb/javascript#arrows--paren-wrap |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ์ฌ์ฉํ์ง ์๋ ํ๋ผ๋ฏธํฐ๋ ์ธ๋๋ฐ๋ก ํํํ๋ ๊ด์ต์ด ์๋ค๊ณ ํฉ๋๋ค!
```suggestion
const total = menu.reduce((acc, [_, count]) => acc + count, 0);
``` |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ์ค ์ข์ ๋ฐฉ๋ฒ์ด๋ค์. |
@@ -0,0 +1,208 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
๊ธฐ๋ฅ ๋ชฉ๋ก ์ ๋ฆฌ ๐
+
+### ํด๋์ค, ํจ์ ์ ๋ฆฌ
+
+1. Domain
+- 1-1. `PromotionController`
+ - ์ ์ฒด ํ๋ก๋ชจ์
์ ํ๋ก์ธ์ค ๋ฐ ์
์ถ๋ ฅ์ ๋ด๋นํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค
+- 1-2. `Discount`
+ - ๋ ์ง์ ๋ํ ํํ๋ค์ ํ์ธํ๊ณ , ํํ์ ๊ณ์ฐํ๋ ํด๋์ค
+- 1-3. `Client`
+ - ์ฃผ๋ฌธ๊ณผ ๋ ์ง ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ ๊ฐ์ ํ ์ธ ํํ๊ณผ ์ฃผ๋ฌธ ๊ฐ๊ฒฉ์ ๊ณ์ฐํ๋ ํด๋์ค
+
+2. View
+- 2-1. `InputView`
+ - ์ฌ์ฉ์๋ก๋ถํฐ ์
๋ ฅ์ ๋ฐ์ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํ๊ณ , ์
๋ ฅ๋ ๋ฐ์ดํฐ ๋ฐํํ๋ ํจ์
+- 2-2. `OutputView`
+ - ํ๋ก์ธ์ค ๊ฒฐ๊ณผ ๋ฐ ์ค๋ฅ ๋ฉ์ธ์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ์ถ๋ ฅํ๋ ํจ์
+
+
+3. Util
+- 3-1. `constants`
+ - ์ฌ์ฉ๋๋ ๋งค์ง๋๋ฒ, ์๋ฌ๋ฉ์ธ์ง, ์
์ถ๋ ฅ ๋ฉ์์ง, ์ถ๋ ฅ ํ์ดํ ๋ฑ ์์ ์ ์
+- 3-2. `inputHandler`
+ - InputView ๋ด์์ ์
๋ ฅ์ ๋ฐ๋ ๋ก์ง ํธ๋ค๋ฌ ์ ์
+- 3-3. `parseInput`
+ - ๊ณ ๊ฐ์ ๋ฉ๋ด ์
๋ ฅ์ ๋ฉ๋ด ์ฃผ๋ฌธ ๋ฆฌ์คํธ ํํ๋ก ๋ณํํ๋ ํจ์ ์ ์
+- 3-4. `validateInput`
+ - ๊ณ ๊ฐ์ ์
๋ ฅ์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ ํจ์ ์ ์
+4. `App`
+ - ํ๋ก๋ชจ์
์ปจํธ๋กค๋ฌ ํด๋์ค๋ฅผ ์คํ์ํค๋ ์ ์ฒด
+5. `index`
+ - ๋ก์ง์ ์ํํ๋ App์ ์คํํ๋ ์ง์
์
+
+
+### ๊ตฌํ ๊ธฐ๋ฅ ์ ๋ฆฌ
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- [x] ์ด๋ฒคํธ ํ๋๋ ๋ฉํธ ์ถ๋ ฅ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง(์ผ) ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- [x] 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- [x] `<์ฃผ๋ฌธ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ ์ถ๋ ฅ
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- [x] `<์ฆ์ ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ดํ์ธ 1๊ฐ` ๋๋ `์์` ์ถ๋ ฅ
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- [x] `<ํํ ๋ด์ญ>` ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํ์ผ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํน๋ณ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅ
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<์ดํํ ๊ธ์ก>` ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก ์ถ๋ ฅ
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- [x] `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ์ถ๋ ฅ
+- [x] ์ด๋ฒคํธ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง ์ถ๋ ฅ
+
+
+### ์ด๋ฒคํธ ์ ๋ฆฌ
+
+1-1. 2023.12.1 ~ 2023.12.25 ํ ์ธ
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - 12.1 ๊ธฐ์ค 1,000์ ํ ์ธ ~
+ - 12.25 ๊ธฐ์ค 3400์ ํ์ธ
+
+1-2. 2023.12.1 ~ 2023.12.31 ํ ์ธ
+
+- ํ์ผ ํ ์ธ (์ผ, ์, ํ, ์, ๋ชฉ)
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ (๊ธ, ํ )
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ (3(์ผ), 10(์ผ), 17(์ผ), 24(์ผ), 25(์), 31(์ผ))
+ - ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ 1000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ
+ - **ํ ์ธ ์ ์ด ์ฃผ๋ฌธ๊ธ์ก**์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+1-3. ์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ
+
+- ์ด ํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง
+ - ๋ฏธ์ถฉ์กฑ : ์์
+ - 5์ฒ์ ์ด์ : ๋ณ
+ - 1๋ง์ ์ด์ : ํธ๋ฆฌ
+ - 2๋ง์ ์ด์ : ์ฐํ
+
+1-4. ์ฃผ์ ์ฌํญ
+
+- 'ํ ์ธ'์ด๋ผ๋ ๋จ์ด๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง, ๊ธ์ก '์ฐจ๊ฐ'์ ๋ ๊ฐ๊น์. %๋ก ํ ์ธ์ด ์๋ - ํ์
+- ์ด ์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์์ธ์ง ํ์ธํ๊ณ ์ด๋ฒคํธ ์ ์ฉ ํ์
+- ์๋ฃ๋ง, ์ฃผ๋ฌธ ์ ์ฃผ๋ฌธ ์์ฒด๊ฐ ๋ถ๊ฐ
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ ๊น์ง ์ฃผ๋ฌธ ๊ฐ๋ฅ
+
+
+### ํ๋ฆ ์ ๋ฆฌ
+
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- 1-1. ์ด๋ฒคํธ ํ๋๋ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 1-2. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง(์ผ)๋ฅผ ์ซ์๋ก๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+ -1-2-1. ์
๋ ฅ ๋ฐ์ ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- 2-1. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ค.
+- 2-2. `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ๋๋ค.
+ - 2-2-1. ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- 3-1. 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- 4-1. `<์ฃผ๋ฌธ๋ฉ๋ด>`๋ฅผ ์ถ๋ ฅํ๋ค.
+- 4-2. `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ์ `์ฃผ๋ฌธ ๋ฉ๋ด (๋ฉ๋ด๊ฐ์)๊ฐ\n` ๋ก ์ถ๋ ฅํ๋ค.
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- 5-1. `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ ์ถ๋ ฅํ๋ค.
+- 5-2. ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+ - 5-2-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- 6-1. `์ดํ์ธ (๊ฐ์)๊ฐ` ์ถ๋ ฅํ๋ค.
+ - 6-2-1. ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์ ๊ฒฝ์ฐ ๋น ์ดํ์ธ์ด 1๊ฐ์ฉ ์ฆ์ ๋๋ค.
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- 7-1. `<ํํ ๋ด์ญ>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 7-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 7-2. ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-3. ํ์ผ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-4. ํน๋ณ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-5. ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅํ๋ค.
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- 8-1. `<์ดํํ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 8-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 8-2. *7. ํํ๋ด์ญ ์ถ๋ ฅ* ์ `7-2 ~ 7-5` ์ ๊ธ์ก์ ๋ชจ๋ ๋ํด์ ์ถ๋ ฅํ๋ค.
+
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- 9-1. `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 9-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅํ๋ค.
+- 9-2. **5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ** ์์ **8. ์ด ํํ ๊ธ์ก ์ถ๋ ฅ** ์ ๋บ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- 10-1. `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 10-2. ์ถ๋ ฅํ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ฒฝ์ฐ `์์`์ ์ถ๋ ฅํ๋ค.
+
+
+### ๐ ํ์ผ ๊ตฌ์กฐ
+
+```
+โ src
+ โฃ Domain
+ โ โฃ PromotionController.js
+ โ โฃ Client.js
+ โ โ Discount.js
+ โฃ View
+ โ โฃ InputView.js
+ โ โ OutputView.js
+ โฃ Util
+ โ โฃ constants.js
+ โ โฃ parseInput.js
+ โ โฃ inputHandler.js
+ โ โ validateInput.js
+ โฃ App.js
+ โ index.js
+```
\ No newline at end of file | Unknown | UserFlow๊ฐ ๋ช
ํํ๊ฒ ์์ฑ๋ ๊ฒ ๊ฐ์์ :)
userflow๋ฅผ ์์ฑํ๋ฉด์ ์ค๊ณ๋ฅผ ํ๋ฉด, ์์ธ์ฒ๋ฆฌ๋ flow๋ฅผ ์ค๊ณํจ์ ์์ด์ ๋ง์ ๋์์ด ๋ ๊ฒ ๊ฐ๋ค์! |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ์ด ํจํด ์์ฒด๋ ์๋นํ ์ข๋ค์. ๊ทธ๋ฐ๋ฐ ์๋์ ๊ฐ์ ๊ฒฝ์ฐ๋ ์ปค๋ฒ๊ฐ ์ ๋ ๊ฒ ๊ฐ๊ธฐ๋ ํฉ๋๋ค.
```javascript
const item = 'ํํ์ค-1-'
const [name, menu] = item.trim().split('-')
console.log(name, menu) // ํํ์ค, 1
``` |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๋งค์ฐ ์ฌ์ํ ๋ถ๋ถ์ด์ง๋ง, 7๊ณผ 1,2๋ ์์ํ๋ฅผ ์งํํ๋ฉด ์ด๋จ๊น ์ถ๋ค์!
1๊ณผ 2๊ฐ ๋ฌด์์ ์๋ฏธํ๋์ง ํท๊ฐ๋ฆด ์๋ ์๊ณ , ๋์ผํ๊ฒ ์์ ํ ์ ์๋๋ก์ :) |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ```javascript
getOrderList() {
Object.entries(this.#order).map(([name, count]) =>`${name} ${count}${INFO.COUNT}`);
return output.join('\n)';
}
```
```javascript
Object.entries(this.#order)
.map(([name, count]) => MENU[name].price * count)
.reduce((acc, cur) => acc+cur, 0)
```
์ฌ์ํ ์คํ์ผ ์ฐจ์ด์ง๋ง ์ด๋ ๊ฒ ๊ณ ์น ์๋ ์๊ฒ ๋ค์. |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ๊ฐ์ธ์ ์ธ ์๊ฒฌ์ด์ง๋ง ์ด ๊ฒฝ์ฐ๋ `model`์ด `view`์ ์ง์์ ๋๋ฌด ๋ง์ด ์๊ณ ์๋ ๊ฒ ๊ฐ์ต๋๋ค. ์ด๋ค `view`์์๋ "{ํ ์ธ}: {๊ธ์ก}์"ํ์์ผ๋ก ๋ฐ๊ธธ ์ํ ์๋ ์์ง๋ง ๋ค๋ฅธ `view`์์๋ "{๊ธ์ก}๋งํผ {ํ ์ธ}์ ๋ฐ์ผ์
จ์ด์"์ ๊ฐ์ด ์ถ๋ ฅํ๊ธฐ๋ฅผ ์ํ ์ ์๋ค๋ ์๊ฐ์ด ๋ค๊ณ , ๋ฐ๋ผ์ `domain` ์์ญ์ด `view` ์์ญ์์ ์ฒ๋ฆฌ๋์ด์ผ ํ๋ ๊ฒ ์๋๊น ์๊ฐ์ด ๋๋ค์. |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๊ฐ case๋ง๋ค ๋ฐ๋ก ๊ตฌ๋ถ์ ์ง์ด ์ฃผ์ ๊ฑฐ๋ผ๋ฉด,
```javascript
let specialDayDiscount = 0;
specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
```
์ ๊ฐ์ ๋ฐฉ์๋ ์ข์ง๋ง, ์๋์ ๊ฐ์ ๋ฐฉ๋ฒ์ผ๋ก ํ๋ฒ์ ์ ์ธํด ๋ฒ๋ ค๋ ๊ด์ฐฎ์ง ์์๊น ์ถ์ด์!
```javascript
const specialDayDiscount = -DATE.SPECIAL_DISCOUNT;
``` |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ ๋ ์ด๋ฐ ๋ฐฉ๋ฒ์ ๋ชฐ๋ผ์ ๋๊ฐ๋ก ๋๋ ์ ์ผ์๋๋ฐ, ์ข์ ๋ฐฉ๋ฒ์ด ์์๊ตฐ์!
์ข์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค :) |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค ใ
ใ
โบ๏ธ |
@@ -0,0 +1,90 @@
+const MENU_KIND = Object.freeze({
+ APPETIZER: '์ ํผํ์ด์ ',
+ MAIN: '๋ฉ์ธ',
+ DESSERT: '๋์ ํธ',
+ DRINK: '์๋ฃ',
+});
+
+const MENU = Object.freeze({
+ ์์ก์ด์ํ: { price: 6000, kind: MENU_KIND.APPETIZER },
+ ํํ์ค: { price: 5500, kind: MENU_KIND.APPETIZER },
+ ์์ ์๋ฌ๋: { price: 8000, kind: MENU_KIND.APPETIZER },
+ ํฐ๋ณธ์คํ
์ดํฌ: { price: 55000, kind: MENU_KIND.MAIN },
+ ๋ฐ๋นํ๋ฆฝ: { price: 54000, kind: MENU_KIND.MAIN },
+ ํด์ฐ๋ฌผํ์คํ: { price: 35000, kind: MENU_KIND.MAIN },
+ ํฌ๋ฆฌ์ค๋ง์คํ์คํ: { price: 25000, kind: MENU_KIND.MAIN },
+ ์ด์ฝ์ผ์ดํฌ: { price: 15000, kind: MENU_KIND.DESSERT },
+ ์์ด์คํฌ๋ฆผ: { price: 5000, kind: MENU_KIND.DESSERT },
+ ์ ๋ก์ฝ๋ผ: { price: 3000, kind: MENU_KIND.DRINK },
+ ๋ ๋์์ธ: { price: 60000, kind: MENU_KIND.DRINK },
+ ์ดํ์ธ: { price: 25000, kind: MENU_KIND.DRINK },
+});
+
+const DATE = Object.freeze({
+ EVENT_START: 1,
+ EVENT_END: 25,
+ PERIOD_DISCOUNT: 1000,
+ SPECIAL_DISCOUNT: 1000,
+ SPECIAL_DATE: [3, 10, 17, 24, 25, 31],
+ PER_DAY_DISCOUNT: 100,
+});
+
+const INFO = Object.freeze({
+ UNIT: '์',
+ COUNT: '๊ฐ',
+ WEEK_DISCOUNT: 2023,
+ ORDER_MINIMUM: 10000,
+ GIFT_CONDITION: 120000,
+ GIFT_PRICE: 25000,
+ GIFT: '์ดํ์ธ 1๊ฐ',
+ NONE: '์์',
+ BADGE: {
+ SANTA: { PRICE: 20000, NAME: '์ฐํ' },
+ TREE: { PRICE: 10000, NAME: 'ํธ๋ฆฌ' },
+ STAR: { PRICE: 5000, NAME: '๋ณ' },
+ },
+});
+
+const DISCOUNT = Object.freeze({
+ CHRISTMAS: 'ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ',
+ WEEK: 'ํ์ผ ํ ์ธ',
+ WEEKEND: '์ฃผ๋ง ํ ์ธ',
+ SPECIAL: 'ํน๋ณ ํ ์ธ',
+ GIFTS: '์ฆ์ ์ด๋ฒคํธ',
+});
+
+const INPUT_MESSAGE = Object.freeze({
+ DATE: '12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)\n',
+ ORDER:
+ '์ฃผ๋ฌธํ์ค ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)\n',
+});
+
+const OUTPUT_MESSAGE = Object.freeze({
+ INTRO: '์๋
ํ์ธ์! ์ฐํ
์ฝ ์๋น 12์ ์ด๋ฒคํธ ํ๋๋์
๋๋ค.\n',
+ TITLE: {
+ PREVIEW: (date) => `12์ ${date}์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ๋ณด๊ธฐ!\n`,
+ ORDER_MENU: '<์ฃผ๋ฌธ ๋ฉ๋ด>',
+ BEFORE_DISCOUNT: '<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>',
+ AFTER_DISCOUNT: '<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>',
+ GIFT: '<์ฆ์ ๋ฉ๋ด>',
+ BENEFIT: '<ํํ ๋ด์ญ>',
+ BENEFIT_AMOUNT: '<์ดํํ ๊ธ์ก>',
+ BADGE: '<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>',
+ },
+});
+
+const ERROR_MESSAGE = Object.freeze({
+ INVALID_DATE: '[ERROR] ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+ INVALID_ORDER: '[ERROR] ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.',
+});
+
+export {
+ MENU_KIND,
+ MENU,
+ DATE,
+ INFO,
+ DISCOUNT,
+ INPUT_MESSAGE,
+ OUTPUT_MESSAGE,
+ ERROR_MESSAGE,
+}; | JavaScript | ์ค ๊ธ์ก์ด ํฐ ๊ฒฝ์ฐ ๋ ์ ์ฉํ๊ฒ ๋ค์ ์ ๋ณด ๊ฐ์ฌํฉ๋๋ค ! |
@@ -0,0 +1,60 @@
+import { ERROR_MESSAGE, MENU, MENU_KIND } from './constants';
+
+const validateDate = date => {
+ if (!(date >= 1 && date <= 31)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+ if (typeof date !== 'number' || !Number.isInteger(date)) {
+ throw new Error(ERROR_MESSAGE.INVALID_DATE);
+ }
+};
+
+const validateName = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (!Object.keys(MENU).includes(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateDuplicate = menu => {
+ const checkedName = new Set();
+ menu.forEach(([name]) => {
+ if (checkedName.has(name)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+ checkedName.add(name);
+ });
+};
+
+const validateOnlyDrink = menu => {
+ const types = new Set(menu.map(([name]) => MENU[name].type));
+ if (types.size === 1 && types.has(MENU_KIND.DRINK)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateCount = menu => {
+ if (!menu.every(([, count]) => count >= 1)) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateTotalCount = menu => {
+ const total = menu.reduce((acc, [, count]) => acc + count, 0);
+ if (total > 20) {
+ throw new Error(ERROR_MESSAGE.INVALID_ORDER);
+ }
+};
+
+const validateOrder = order => {
+ validateName(order);
+ validateDuplicate(order);
+ validateOnlyDrink(order);
+ validateCount(order);
+ validateTotalCount(order);
+};
+
+export { validateDate, validateOrder }; | JavaScript | ์์ด๋น์ค๋น ์ปจ๋ฒค์
์์ ์ง์ํ๋ ๊ฑฐ ๊ฐ๋๋ผ๊ตฌ์.. ๊ทธ๋์ ํน์๋ ํด์ ๋ป๋๋ฐ ์ฌ์ฉํ๋๊ฒ ์ข์๋ ๊ฑฐ ๊ฐ๋ค์ ๐ค |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ์๋ง ์ ๋ฐ ์
๋ ฅ์ด ๋ค์ด์จ๋ค๋ฉด ์ ํจ์ฑ ๊ฒ์ฌ์์ ๊ฑธ๋ฌ๋ด์ค ์ ์์ ๊ฑฐ ๊ฐ์ต๋๋ค ! ๊ทธ๋๋ ํ์ฑํ๋ ๊ณผ์ ์์ ๋ฐ์ํ ์ ์๋ ์๋ฌ ๊ฒฝ์ฐ๋ฅผ ์๋ ค์ฃผ์
์ ์ข ๋ ๊ณ ๋ฏผํด๋ณผ ์ ์๋ ๊ณ๊ธฐ๊ฐ ๋ ๊ฑฐ ๊ฐ์์ ๊ฐ์ฌํฉ๋๋ค โบ๏ธ |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ์ค ํจ์ฌ ๊น๋ํ ๊ฑฐ ๊ฐ์ ์ข๋ค์ ํผ๋๋ฐฑ ๊ฐ์ฌํฉ๋๋ค โบ๏ธ |
@@ -0,0 +1,96 @@
+import { DISCOUNT, INFO, MENU } from '../Util/constants';
+import Discount from './Discount';
+
+class Client {
+ #date;
+ #order;
+
+ constructor(date, order) {
+ this.#date = date;
+ this.#order = order;
+ }
+
+ calculateBenefits() {
+ const discount = new Discount();
+ return discount.calculateDiscount(this.#date, this.#order);
+ }
+
+ getDate() {
+ return this.#date;
+ }
+
+ getOrderList() {
+ let output = '';
+ Object.entries(this.#order).forEach(([name, count]) => {
+ output += `${name} ${count}${INFO.COUNT}\n`;
+ });
+ return output;
+ }
+
+ getBeforeDiscount() {
+ let cost = 0;
+ Object.entries(this.#order).forEach(([name, count]) => {
+ cost += MENU[name].price * count;
+ });
+ return cost;
+ }
+
+ getGift() {
+ const isGift = this.getBeforeDiscount() >= INFO.GIFT_CONDITION;
+ return (isGift && INFO.GIFT) || INFO.NONE;
+ }
+
+ getBenefitList() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) {
+ return INFO.NONE;
+ }
+ let output = '';
+ Object.entries(benefit).forEach(([discount, cost]) => {
+ output += `${discount}: ${cost.toLocaleString()}${INFO.UNIT}\n`;
+ });
+ if (this.getGift() !== INFO.NONE)
+ output += `${DISCOUNT.GIFTS}: -${INFO.GIFT_PRICE.toLocaleString()}${
+ INFO.UNIT
+ }\n`;
+ return output;
+ }
+
+ getDiscountAmount() {
+ const benefit = this.calculateBenefits();
+ if (!benefit || Object.keys(benefit).length === 0) return 0;
+
+ let totalAmount = Object.values(benefit).reduce((acc, cur) => acc + cur);
+ if (this.getGift() !== INFO.NONE) totalAmount += -INFO.GIFT_PRICE;
+ return totalAmount;
+ }
+
+ getAfterDiscount() {
+ const beforeDiscount = this.getBeforeDiscount();
+ const discountAmount = this.getDiscountAmount();
+ let gift = 0;
+
+ if (this.getGift() !== INFO.NONE) {
+ gift = INFO.GIFT_PRICE;
+ }
+
+ const total = beforeDiscount + discountAmount + gift;
+ return total;
+ }
+
+ getEventBadge() {
+ const benefit = this.getDiscountAmount();
+
+ switch (true) {
+ case benefit <= -INFO.BADGE.SANTA.PRICE:
+ return INFO.BADGE.SANTA.NAME;
+ case benefit <= -INFO.BADGE.TREE.PRICE:
+ return INFO.BADGE.TREE.NAME;
+ case benefit <= -INFO.BADGE.STAR.PRICE:
+ return INFO.BADGE.STAR.NAME;
+ default:
+ return INFO.NONE;
+ }
+ }
+}
+export default Client; | JavaScript | ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค. ๋ง์ํ์ ๊ฑฐ์ฒ๋ผ ๋ชจ๋ธ์ด ๋ทฐ์ ์ธ๋ถ์ฌํญ์ ๊ณผ๋ํ๊ฒ ์๊ณ ์๋ ํํ๋ผ๋ฉด ํํ๋ฐฉ์์ด ํผํฉ๋ ๋๋์ด ๋ค์ด ์ ์ฐ์ฑ์ด ๋จ์ด์ง ๊ฑฐ ๊ฐ๋ค์ ใ
ใ
์ฌ์ค mvc ํจํด์ ์ง์ฐฉํ์ง ์๊ณ ํด๋์ค ์์ฒด๊ฐ ๊ฐ์ง ์ ์๋ ์ญํ ์ ์๊ฐํ๊ณ , ๊ด๋ จ๋ ๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๋ฐฉ์์ ๊ณ ๋ คํ๋ค๋ณด๋ ํจํด์์ ์ค๋ ์ฒ๋ฆฌ๊ธฐ์ค๊ณผ๋ ์ด๊ธ๋๋ ์ํฉ์ด ๋ฐ์ํ๋ ๊ฑฐ ๊ฐ๋ค์ ... ๋ฒ ๋ฆฌ์์ด์
์ด ๋ค์ํ๊ฒ ์กด์ฌํ๋ ์ํฉ์์๋ ์ ์ฐํ๊ฒ ์ฌ์ฉํ ์ ์๋ ๊ตฌ์กฐ๊ฐ ๋ฌด์์ธ์ง ์ข๋ ๊ณ ๋ฏผํด๋ด์ผ๊ฒ ๋ค์ ์กฐ์ธ ๊ฐ์ฌํฉ๋๋ค โบ๏ธ |
@@ -0,0 +1,10 @@
+const parseInput = userInput =>
+ userInput
+ .trim()
+ .split(',')
+ .map(item => {
+ const [name, quantity] = item.trim().split('-');
+ return [name, Number(quantity)];
+ });
+
+export default parseInput; | JavaScript | ํธ๋ค ์ธํ์์ ๋ฐ์์ ๋ฐ๋ก ํ์ฑํ์๋ ๊ฒ ๊ฐ์๋ฐ ์ ํจ์ฑ ๊ฒ์ฌ์์ ๋๋ฝ๋์ง ์์๊น์? |
@@ -0,0 +1,208 @@
+## ํฌ๋ฆฌ์ค๋ง์ค ํ๋ก๋ชจ์
๊ธฐ๋ฅ ๋ชฉ๋ก ์ ๋ฆฌ ๐
+
+### ํด๋์ค, ํจ์ ์ ๋ฆฌ
+
+1. Domain
+- 1-1. `PromotionController`
+ - ์ ์ฒด ํ๋ก๋ชจ์
์ ํ๋ก์ธ์ค ๋ฐ ์
์ถ๋ ฅ์ ๋ด๋นํ๋ ์ปจํธ๋กค๋ฌ ํด๋์ค
+- 1-2. `Discount`
+ - ๋ ์ง์ ๋ํ ํํ๋ค์ ํ์ธํ๊ณ , ํํ์ ๊ณ์ฐํ๋ ํด๋์ค
+- 1-3. `Client`
+ - ์ฃผ๋ฌธ๊ณผ ๋ ์ง ์ ๋ณด๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ณ ๊ฐ์ ํ ์ธ ํํ๊ณผ ์ฃผ๋ฌธ ๊ฐ๊ฒฉ์ ๊ณ์ฐํ๋ ํด๋์ค
+
+2. View
+- 2-1. `InputView`
+ - ์ฌ์ฉ์๋ก๋ถํฐ ์
๋ ฅ์ ๋ฐ์ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ํ๊ณ , ์
๋ ฅ๋ ๋ฐ์ดํฐ ๋ฐํํ๋ ํจ์
+- 2-2. `OutputView`
+ - ํ๋ก์ธ์ค ๊ฒฐ๊ณผ ๋ฐ ์ค๋ฅ ๋ฉ์ธ์ง๋ฅผ ์ฌ์ฉ์์๊ฒ ์ถ๋ ฅํ๋ ํจ์
+
+
+3. Util
+- 3-1. `constants`
+ - ์ฌ์ฉ๋๋ ๋งค์ง๋๋ฒ, ์๋ฌ๋ฉ์ธ์ง, ์
์ถ๋ ฅ ๋ฉ์์ง, ์ถ๋ ฅ ํ์ดํ ๋ฑ ์์ ์ ์
+- 3-2. `inputHandler`
+ - InputView ๋ด์์ ์
๋ ฅ์ ๋ฐ๋ ๋ก์ง ํธ๋ค๋ฌ ์ ์
+- 3-3. `parseInput`
+ - ๊ณ ๊ฐ์ ๋ฉ๋ด ์
๋ ฅ์ ๋ฉ๋ด ์ฃผ๋ฌธ ๋ฆฌ์คํธ ํํ๋ก ๋ณํํ๋ ํจ์ ์ ์
+- 3-4. `validateInput`
+ - ๊ณ ๊ฐ์ ์
๋ ฅ์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ ํจ์ ์ ์
+4. `App`
+ - ํ๋ก๋ชจ์
์ปจํธ๋กค๋ฌ ํด๋์ค๋ฅผ ์คํ์ํค๋ ์ ์ฒด
+5. `index`
+ - ๋ก์ง์ ์ํํ๋ App์ ์คํํ๋ ์ง์
์
+
+
+### ๊ตฌํ ๊ธฐ๋ฅ ์ ๋ฆฌ
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- [x] ์ด๋ฒคํธ ํ๋๋ ๋ฉํธ ์ถ๋ ฅ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง(์ผ) ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์๋น ์์ ๋ฐฉ๋ฌธ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- [x] ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ ์
๋ ฅ ๋ฐ๊ธฐ
+- [x] ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฆ
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- [x] 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฌธ๊ตฌ ์ถ๋ ฅ
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- [x] `<์ฃผ๋ฌธ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ ์ถ๋ ฅ
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- [x] `<์ฆ์ ๋ฉ๋ด>` ์ถ๋ ฅ
+- [x] `์ดํ์ธ 1๊ฐ` ๋๋ `์์` ์ถ๋ ฅ
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- [x] `<ํํ ๋ด์ญ>` ์ถ๋ ฅ
+- [x] ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํ์ผ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ํน๋ณ ํ ์ธ ๊ธ์ก ์ถ๋ ฅ
+- [x] ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅ
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<์ดํํ ๊ธ์ก>` ์ถ๋ ฅ
+- [x] ์ด ํํ ๊ธ์ก ์ถ๋ ฅ
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- [x] `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>`์ถ๋ ฅ
+- [x] ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- [x] `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ์ถ๋ ฅ
+- [x] ์ด๋ฒคํธ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง ์ถ๋ ฅ
+
+
+### ์ด๋ฒคํธ ์ ๋ฆฌ
+
+1-1. 2023.12.1 ~ 2023.12.25 ํ ์ธ
+
+- ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ
+ - 12.1 ๊ธฐ์ค 1,000์ ํ ์ธ ~
+ - 12.25 ๊ธฐ์ค 3400์ ํ์ธ
+
+1-2. 2023.12.1 ~ 2023.12.31 ํ ์ธ
+
+- ํ์ผ ํ ์ธ (์ผ, ์, ํ, ์, ๋ชฉ)
+ - ๋์ ํธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ์ฃผ๋ง ํ ์ธ (๊ธ, ํ )
+ - ๋ฉ์ธ ๋ฉ๋ด 1๊ฐ๋น 2023์ ํ ์ธ
+- ํน๋ณ ํ ์ธ (3(์ผ), 10(์ผ), 17(์ผ), 24(์ผ), 25(์), 31(์ผ))
+ - ์ด ์ฃผ๋ฌธ ๊ธ์ก์์ 1000์ ํ ์ธ
+- ์ฆ์ ์ด๋ฒคํธ
+ - **ํ ์ธ ์ ์ด ์ฃผ๋ฌธ๊ธ์ก**์ด 12๋ง์ ์ด์์ผ ๋, ์ดํ์ธ 1๊ฐ ์ฆ์
+
+1-3. ์ด๋ฒคํธ ๋ฐฐ์ง ๋ถ์ฌ
+
+- ์ด ํํ ๊ธ์ก์ ๋ฐ๋ฅธ ์ด๋ฒคํธ ๋ฐฐ์ง
+ - ๋ฏธ์ถฉ์กฑ : ์์
+ - 5์ฒ์ ์ด์ : ๋ณ
+ - 1๋ง์ ์ด์ : ํธ๋ฆฌ
+ - 2๋ง์ ์ด์ : ์ฐํ
+
+1-4. ์ฃผ์ ์ฌํญ
+
+- 'ํ ์ธ'์ด๋ผ๋ ๋จ์ด๋ฅผ ์ฌ์ฉํ๊ณ ์์ง๋ง, ๊ธ์ก '์ฐจ๊ฐ'์ ๋ ๊ฐ๊น์. %๋ก ํ ์ธ์ด ์๋ - ํ์
+- ์ด ์ฃผ๋ฌธ ๊ธ์ก 10,000์ ์ด์์ธ์ง ํ์ธํ๊ณ ์ด๋ฒคํธ ์ ์ฉ ํ์
+- ์๋ฃ๋ง, ์ฃผ๋ฌธ ์ ์ฃผ๋ฌธ ์์ฒด๊ฐ ๋ถ๊ฐ
+- ๋ฉ๋ด๋ ํ๋ฒ์ ์ต๋ 20๊ฐ ๊น์ง ์ฃผ๋ฌธ ๊ฐ๋ฅ
+
+
+### ํ๋ฆ ์ ๋ฆฌ
+
+
+**1. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง ์
๋ ฅ**
+
+- 1-1. ์ด๋ฒคํธ ํ๋๋ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 1-2. ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง(์ผ)๋ฅผ ์ซ์๋ก๋ง ์
๋ ฅ ๋ฐ๋๋ค.
+ -1-2-1. ์
๋ ฅ ๋ฐ์ ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**2. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๊ฐ์ ์
๋ ฅ**
+
+- 2-1. ์ฃผ๋ฌธํ ๋ฉ๋ด์ ๋ฉ๋ด ๊ฐ์๋ฅผ ์
๋ ฅ ๋ฐ๋ ๋ฉ์ธ์ง๋ฅผ ์ถ๋ ฅํ๋ค.
+- 2-2. `์ฃผ๋ฌธํ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ๋๋ค.
+ - 2-2-1. ์
๋ ฅ ๋ฐ์ ์ฃผ๋ฌธ ๋ฉ๋ด์ ๊ฐ์์ ๋ํ ์ ํจ์ฑ ๊ฒ์ฌ๋ฅผ ์งํํ๋ค.
+
+**3. ๋ฐฉ๋ฌธ ๋ ์ง์ ๋ํ ํํ ์์ ๋ฉํธ ์ถ๋ ฅ**
+
+- 3-1. 12์ (1.์์ ์
๋ ฅ๋ฐ์ ๋ ์ง)์ผ ์ ๋ํ ํํ ์๊ฐ ๋ฉํธ๋ฅผ ์ถ๋ ฅํ๋ค.
+
+**4. ์ฃผ๋ฌธ ๋ฉ๋ด ์ถ๋ ฅ**
+
+- 4-1. `<์ฃผ๋ฌธ๋ฉ๋ด>`๋ฅผ ์ถ๋ ฅํ๋ค.
+- 4-2. `์ฃผ๋ฌธ ๋ฉ๋ด-๋ฉ๋ด ๊ฐ์` ํํ๋ก ์
๋ ฅ ๋ฐ์ ๋ด์ฉ์ `์ฃผ๋ฌธ ๋ฉ๋ด (๋ฉ๋ด๊ฐ์)๊ฐ\n` ๋ก ์ถ๋ ฅํ๋ค.
+
+**5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ**
+
+- 5-1. `<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>`์ ์ถ๋ ฅํ๋ค.
+- 5-2. ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+ - 5-2-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+
+**6. ์ฆ์ ๋ฉ๋ด ์ฆ์ ์ฌ๋ถ ์ถ๋ ฅ**
+
+- 6-1. `์ดํ์ธ (๊ฐ์)๊ฐ` ์ถ๋ ฅํ๋ค.
+ - 6-2-1. ์ด ์ฃผ๋ฌธ ๊ธ์ก์ด 12๋ง์ ์ด์ ๊ฒฝ์ฐ ๋น ์ดํ์ธ์ด 1๊ฐ์ฉ ์ฆ์ ๋๋ค.
+
+**7. ํํ ๋ด์ญ ์ถ๋ ฅ**
+
+- 7-1. `<ํํ ๋ด์ญ>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 7-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 7-2. ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ธ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-3. ํ์ผ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-4. ํน๋ณ ํ ์ธ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+- 7-5. ์ฆ์ ์ด๋ฒคํธ ํ ์ธ ์ด๋ฒคํธ ์ถ๋ ฅํ๋ค.
+
+**8. ์ดํํ ๊ธ์ก ์ถ๋ ฅ**
+
+- 8-1. `<์ดํํ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `-(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 8-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅ ํ๋ค.
+- 8-2. *7. ํํ๋ด์ญ ์ถ๋ ฅ* ์ `7-2 ~ 7-5` ์ ๊ธ์ก์ ๋ชจ๋ ๋ํด์ ์ถ๋ ฅํ๋ค.
+
+
+**9. ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก ์ถ๋ ฅ**
+
+- 9-1. `<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>` ์ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ธ์ก์ `(๊ธ์ก)์` ํํ๋ก ์ถ๋ ฅํ๋ค.
+ - 9-1-1. 1,000 ๋จ์๋น `,` ์ ๋ถ์ฌ ์ถ๋ ฅํ๋ค.
+- 9-2. **5. ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก ์ถ๋ ฅ** ์์ **8. ์ด ํํ ๊ธ์ก ์ถ๋ ฅ** ์ ๋บ ๊ธ์ก์ ์ถ๋ ฅํ๋ค.
+
+**10. 12์ ์ด๋ฒคํธ ๋ฐฐ์ง ์ถ๋ ฅ**
+
+- 10-1. `<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>` ๋ฅผ ์ถ๋ ฅํ๋ค.
+- 10-2. ์ถ๋ ฅํ ๋ฐฐ์ง๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ๋ฐฐ์ง๋ฅผ ์ถ๋ ฅํ๋ฉฐ, ์๋ ๊ฒฝ์ฐ `์์`์ ์ถ๋ ฅํ๋ค.
+
+
+### ๐ ํ์ผ ๊ตฌ์กฐ
+
+```
+โ src
+ โฃ Domain
+ โ โฃ PromotionController.js
+ โ โฃ Client.js
+ โ โ Discount.js
+ โฃ View
+ โ โฃ InputView.js
+ โ โ OutputView.js
+ โฃ Util
+ โ โฃ constants.js
+ โ โฃ parseInput.js
+ โ โฃ inputHandler.js
+ โ โ validateInput.js
+ โฃ App.js
+ โ index.js
+```
\ No newline at end of file | Unknown | ์ฒ์ ๊ธฐ๋ฅ ๊ตฌํ ๋ชฉ๋ก ์์ฑ์ ์ ํ๋ฆ์ ๋ฆฌ๋ฅผ ๋จผ์ ํ๋ ๋ฐฉ์์ผ๋ก 4์ฃผ๊ฐ ์งํํ์ด์ !! ์ด๋ ๋ญ ๊ตฌํํด์ผํ ์ง๊ฐ ์ ๋ณด์ฌ์ ๋์์ด ๋ง์ด ๋์๋ ๊ฑฐ ๊ฐ์์ ์ถ์ฒ๋๋ฆฝ๋๋ค ใ
ใ
|
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ๋ ์ง ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ ๊ด๋ จ ์์๋ฅผ ์ ์ํด๋์ ๋ถ๋ค์ด ๋ง์ด ๋ณด์ด๋๋ผ๊ตฌ์ ! ์ ๋ ๊ด๋ จ๋ ๋ณ์๋ ์ ์ํ๋๊ฒ ์ข์ ๊ฑฐ ๊ฐ๋ค๊ณ ์๊ฐ์ด ๋๋ค์ ใ
ใ
์ถ์ฒ ๊ฐ์ฌํฉ๋๋ค ~ โบ๏ธ |
@@ -0,0 +1,58 @@
+import { DATE, DISCOUNT, INFO, MENU, MENU_KIND } from '../Util/constants';
+
+class Discount {
+ calculateDiscount(date, menu) {
+ const discount = {};
+ const addDisCount = (key, value) => {
+ if (value !== 0) discount[key] = value;
+ };
+
+ addDisCount(DISCOUNT.CHRISTMAS, this.isPeriod(date));
+ addDisCount(DISCOUNT.WEEK, this.isWeekday(date, menu));
+ addDisCount(DISCOUNT.WEEKEND, this.isWeekend(date, menu));
+ addDisCount(DISCOUNT.SPECIAL, this.isSpecialDay(date));
+ return discount;
+ }
+
+ isPeriod(date) {
+ let periodDiscount = 0;
+ if (date >= DATE.EVENT_START && date <= DATE.EVENT_END) {
+ periodDiscount +=
+ -DATE.PERIOD_DISCOUNT + (date - 1) * -DATE.PER_DAY_DISCOUNT;
+ }
+ return periodDiscount;
+ }
+
+ isWeekday(date, menu) {
+ let weekDisCount = 0;
+ if (!(date % 7 === 1 || date % 7 === 2)) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.DESSERT) count += menu[name];
+ });
+ weekDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekDisCount;
+ }
+
+ isWeekend(date, menu) {
+ let weekendDisCount = 0;
+ if (date % 7 === 1 || date % 7 === 2) {
+ let count = 0;
+ Object.keys(menu).forEach(name => {
+ if (MENU[name].kind === MENU_KIND.MAIN) count += menu[name];
+ });
+ weekendDisCount += -INFO.WEEK_DISCOUNT * count;
+ }
+ return weekendDisCount;
+ }
+
+ isSpecialDay(date) {
+ let specialDayDiscount = 0;
+ if (DATE.SPECIAL_DATE.includes(date))
+ specialDayDiscount += -DATE.SPECIAL_DISCOUNT;
+ return specialDayDiscount;
+ }
+}
+
+export default Discount; | JavaScript | ์ค ๋ณ์ ์ ์ธ์ ๊ฐ๊ฒฐํ๊ฒ ํ ์ ์์ด์ ์ข์ ๋ฐฉ๋ฒ์ธ๊ฑฐ ๊ฐ์์ ๊ฐ์ฌํฉ๋๋ค ใ
ใ
!! |
@@ -0,0 +1,26 @@
+package christmas.config;
+
+import java.util.Arrays;
+
+public enum EventBadge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NONE("์์", 0);
+
+ private final String name;
+ private final int limitPrice;
+
+ EventBadge(String name, int limitPrice) {
+ this.name = name;
+ this.limitPrice = limitPrice;
+ }
+
+ public static String findBadgeByTotalDiscount(int totalDiscount) {
+ return Arrays.stream(values())
+ .filter(badge -> totalDiscount >= badge.limitPrice)
+ .findFirst()
+ .orElse(NONE)
+ .name;
+ }
+} | Java | ์ด ๋ฉ์๋๋ EvenBadge์ ๋ฉค๋ฒ์ ์ ์ธ ์์์ ์์กด์ ์ธ ๊ฒ ๊ฐ์์. ๋ ์ข๊ฒ ๊ฐ์ ํ ๋ฐฉ๋ฒ์ ์์๊น์? |
@@ -0,0 +1,25 @@
+package christmas.config;
+
+public class Message {
+ public static final String INPUT_DATE = "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)";
+ public static final String INPUT_ORDER = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
+
+ public static final String OUTPUT_VISIT_DATE = "12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!\n";
+ public static final String OUTPUT_MENU_TITLE = "\n<์ฃผ๋ฌธ ๋ฉ๋ด>";
+ public static final String OUTPUT_ITEM = "%s %d๊ฐ%n";
+ public static final String OUTPUT_WON = "%s์%n";
+ public static final String OUTPUT_MINUS_WON = "-" + OUTPUT_WON;
+ public static final String OUTPUT_TOTAL_PRICE = "%n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_GIFT_TITLE = "\n<์ฆ์ ๋ฉ๋ด>";
+ public static final String OUTPUT_PROMOTION_TITLE = "\n<ํํ ๋ด์ญ>";
+ public static final String OUTPUT_PROMOTION_ITEM = "%s: " + OUTPUT_MINUS_WON;
+ public static final String OUTPUT_TOTAL_DISCOUNT = "%n<์ดํํ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_PAYMENT_PRICE = "%n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_BADGE = "%n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>%n%s%n";
+ public static final String OUTPUT_NONE = "์์";
+
+
+ public static final String ERROR_MESSAGE_PREFIX = "[ERROR]";
+ public static final String ERROR_INPUT_DATE = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ public static final String ERROR_INPUT_ORDER = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+} | Java | ํ๋ก๊ทธ๋จ ์ ์ญ์์ ์ฌ์ฉํ์ง ์๊ณ Output์์๋ง ์ฌ์ฉํ๋ ๋ณ์๋ ๋ฐ๋ก ํด๋์ค๋ก ๋ง๋ค์ง ์๊ณ Output๊ฐ์ฒด ์์ ์์ ํ๋๋ก ์ ์ธํด๋ ์ข์ ๊ฒ ๊ฐ์์:smile:
์ถ๊ฐ์ ์ผ๋ก Message ์์ ์๋ฌ๋ฉ์์ง์ Output์์ ์ฌ์ฉํ๋ ์์๊ฐ ํผํฉ๋์ด ์์ด์ ๋ถ๋ฆฌํ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,25 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.VisitDate;
+import christmas.view.InputView;
+
+public class InputController {
+ public static VisitDate setVisitDate() {
+ try {
+ return new VisitDate(InputView.readDate());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setVisitDate();
+ }
+ }
+
+ public static Order setOrder() {
+ try {
+ return new Order(InputView.readOrder());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setOrder();
+ }
+ }
+} | Java | MVC ํจํด์์ Controller๋ผ๋ฆฌ ์๋ก ์์กดํ๋ ๊ฒ์ ๋ณ๋ก ์ข์ง ์๋ค๊ณ ์๊ณ ์๋๋ฐ InputController๋ฅผ ๋ฐ๋ก ๋ง๋ค๊ณ PromotionController์์ ์ฌ์ฉํ ์ด์ ๊ฐ ๋ฐ๋ก ์์๊น์? |
@@ -0,0 +1,25 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.VisitDate;
+import christmas.view.InputView;
+
+public class InputController {
+ public static VisitDate setVisitDate() {
+ try {
+ return new VisitDate(InputView.readDate());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setVisitDate();
+ }
+ }
+
+ public static Order setOrder() {
+ try {
+ return new Order(InputView.readOrder());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setOrder();
+ }
+ }
+} | Java | setOrder, setVisitDate ๊ฐ๊ฐ VisitDate, Order ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ ์๋ ๊ฒ ๊ฐ์์.
set์ด๋ผ๋ ์ ๋์ด๋ณด๋ค generate๊ฐ ์ข ๋ ์ด์ธ๋ฆฐ๋ค๊ณ ์๊ฐํ๋๋ฐ ์ด๋ ์ ๊ฐ์? |
@@ -0,0 +1,49 @@
+package christmas.controller;
+
+import christmas.config.Constant;
+import christmas.config.EventBadge;
+import christmas.config.Gift;
+import christmas.model.Order;
+import christmas.model.Promotion;
+import christmas.model.PromotionGenerator;
+import christmas.model.VisitDate;
+import christmas.view.OutputView;
+
+public class PromotionController {
+ private final VisitDate visitDate;
+ private final Order order;
+ private final Promotion promotion;
+
+ public PromotionController() {
+ visitDate = InputController.setVisitDate();
+ order = InputController.setOrder();
+ promotion = new PromotionGenerator(visitDate, order).getPromotion();
+ }
+
+ public void active() {
+ print();
+ }
+
+ private int totalPrice() {
+ return order.getTotalPrice();
+ }
+
+ private int totalDiscount() {
+ return promotion.getTotalDiscount();
+ }
+
+ private boolean isEmptyPromotion() {
+ return promotion.getTotalDiscount() == 0;
+ }
+
+ private void print() {
+ OutputView.printVisitDate(visitDate.getVisitDate());
+ OutputView.printOrder(order.getOrderList());
+ OutputView.printTotalPrice(totalPrice());
+ OutputView.printGift(Gift.getGift(totalPrice()));
+ OutputView.printPromotion(isEmptyPromotion(), promotion.getPromotionList());
+ OutputView.printTotalDiscount(totalDiscount() * Constant.MINUS);
+ OutputView.printPaymentPrice(totalPrice() - promotion.getDiscount());
+ OutputView.printBadge(EventBadge.findBadgeByTotalDiscount(totalDiscount()));
+ }
+} | Java | ๋ฉ์๋ ๋ช
์ ๋ช
์ฌ๋ก ํ๋ ๊ฒ์ ๋ณ๋ก ์ข์ง ์์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,45 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.config.Gift;
+import christmas.config.Menu;
+
+import java.util.EnumMap;
+import java.util.Map;
+
+public class GiftEvent implements DiscountEventInterface {
+ private final int totalPrice;
+
+ public GiftEvent(int totalPrice) {
+ this.totalPrice = totalPrice;
+ }
+
+ private Gift getGift() {
+ return Gift.getGift(totalPrice);
+ }
+
+ private String getGiftMenu() {
+ return getGift().getMenu();
+ }
+
+ @Override
+ public boolean isDiscountTarget() {
+ return !getGift().equals(Gift.NONE);
+ }
+
+ private int getGiftPrice() {
+ return Menu.getMenu(getGiftMenu())
+ .getPrice();
+ }
+
+ @Override
+ public Map<Event, Integer> getDiscountInfo() {
+ Map<Event, Integer> discountInfo = new EnumMap<>(Event.class);
+
+ if (isDiscountTarget()) {
+ discountInfo.put(Event.GIFT, getGiftPrice());
+ }
+
+ return discountInfo;
+ }
+} | Java | ์ด๋ฒคํธ๊ฐ ์ ๊ณตํ๋ ๊ณตํต๊ธฐ๋ฅ์ ์ธํฐํ์ด์ค๋ก ์ ๋ฝ์ ๊ฒ ๊ฐ์์:+1: |
@@ -0,0 +1,46 @@
+package christmas.model;
+
+import christmas.config.Menu;
+import christmas.config.MenuType;
+import christmas.util.Util;
+import christmas.util.validator.OrderGenerateAfterValidator;
+import christmas.util.validator.OrderGenerateBeforeValidator;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Order {
+ private final Map<Menu, Integer> order;
+
+ public Order(String order) {
+ new OrderGenerateBeforeValidator(order);
+ this.order = new OrderGenerator(order).generateOrder();
+ new OrderGenerateAfterValidator(this);
+ }
+
+ public int getTotalQuantity() {
+ return Util.intStreamSum(order.values().stream());
+ }
+
+ public int getMenuQuantity(MenuType menuType) {
+ return Util.intStreamSum(order.keySet()
+ .stream()
+ .filter(menu -> menu.getType() == menuType)
+ .map(order::get));
+ }
+
+ public int getTotalPrice() {
+ return Util.intStreamSum(order.entrySet()
+ .stream()
+ .map(entry -> entry.getKey().getPrice() * entry.getValue()));
+ }
+
+ public Map<String, Integer> getOrderList() {
+ return order.entrySet()
+ .stream()
+ .collect(Collectors.toMap(
+ entry -> entry.getKey().getName(),
+ Map.Entry::getValue
+ ));
+ }
+} | Java | ์ ๋ String ๊ฐ์ ์
๋ ฅ๋ฐ์์ Order ๊ฐ์ฒด์์ ํ์ฑ์ ์งํํ๋๋ฐ ์ด ๋ถ๋ถ์ ๋ฐ๋ก OrderGenerator๋ผ๋ ๊ฐ์ฒด๋ก ๋ถ๋ฆฌํ๋๊น ๋ ์ข์ ๊ฒ ๊ฐ์์:+1: |
@@ -0,0 +1,42 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.util.Util;
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Promotion {
+ private final Map<Event, Integer> promotion;
+
+ public Promotion() {
+ promotion = new EnumMap<>(Event.class);
+ }
+
+ public Map<String, Integer> getPromotionList() {
+ return promotion.entrySet()
+ .stream()
+ .filter(event -> event.getValue() > 0)
+ .collect(Collectors.toMap(
+ event -> event.getKey().getName(),
+ Map.Entry::getValue)
+ );
+ }
+
+ public int getTotalDiscount() {
+ return Util.intStreamSum(promotion.values()
+ .stream());
+ }
+
+ public int getDiscount() {
+ return Util.intStreamSum(promotion.entrySet()
+ .stream()
+ .filter(event -> event.getKey() != Event.GIFT)
+ .map(Map.Entry::getValue));
+ }
+
+ public void setDiscountInfo(Map<Event, Integer> discountInfo) {
+ promotion.putAll(discountInfo);
+ }
+} | Java | Promotion์ด๋ผ๋ ํด๋์ค๋ช
์ ํด๋์ค๋ช
๋ง ๋ณด๊ณ ์ด๋ค ๊ธฐ๋ฅ์ ํ๋์ง ์ถ์ธกํ๊ธฐ ์ด๋ ค์ด ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,42 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.util.Util;
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Promotion {
+ private final Map<Event, Integer> promotion;
+
+ public Promotion() {
+ promotion = new EnumMap<>(Event.class);
+ }
+
+ public Map<String, Integer> getPromotionList() {
+ return promotion.entrySet()
+ .stream()
+ .filter(event -> event.getValue() > 0)
+ .collect(Collectors.toMap(
+ event -> event.getKey().getName(),
+ Map.Entry::getValue)
+ );
+ }
+
+ public int getTotalDiscount() {
+ return Util.intStreamSum(promotion.values()
+ .stream());
+ }
+
+ public int getDiscount() {
+ return Util.intStreamSum(promotion.entrySet()
+ .stream()
+ .filter(event -> event.getKey() != Event.GIFT)
+ .map(Map.Entry::getValue));
+ }
+
+ public void setDiscountInfo(Map<Event, Integer> discountInfo) {
+ promotion.putAll(discountInfo);
+ }
+} | Java | ์ด ํํ ๊ธ์ก์ ๊ตฌํ๋ ๋ฉ์๋์ธ๋ฐ TotalDiscount๋ ์ด ํ ์ธ ๊ธ์ก์ ๊ตฌํ๋ ์๋ฏธ๊ฐ ๋ ๊ฐํ ๊ฒ ๊ฐ์์ ๋ฉ์๋ ์ด๋ฆ์ getTotalBenefitPrice๋ผ๋๊ฐ ๋ค๋ฅธ ์ด๋ฆ์ผ๋ก ๋ฐ๊พธ๋ฉด ๋ ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,42 @@
+package christmas.model;
+
+import christmas.config.Event;
+import christmas.util.Util;
+
+import java.util.EnumMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class Promotion {
+ private final Map<Event, Integer> promotion;
+
+ public Promotion() {
+ promotion = new EnumMap<>(Event.class);
+ }
+
+ public Map<String, Integer> getPromotionList() {
+ return promotion.entrySet()
+ .stream()
+ .filter(event -> event.getValue() > 0)
+ .collect(Collectors.toMap(
+ event -> event.getKey().getName(),
+ Map.Entry::getValue)
+ );
+ }
+
+ public int getTotalDiscount() {
+ return Util.intStreamSum(promotion.values()
+ .stream());
+ }
+
+ public int getDiscount() {
+ return Util.intStreamSum(promotion.entrySet()
+ .stream()
+ .filter(event -> event.getKey() != Event.GIFT)
+ .map(Map.Entry::getValue));
+ }
+
+ public void setDiscountInfo(Map<Event, Integer> discountInfo) {
+ promotion.putAll(discountInfo);
+ }
+} | Java | setter๋ฅผ ์ด์ฉํด์ Promotion ๊ฐ์ฒด๊ฐ ๊ฐ์ง ์ํ๋ฅผ ์กฐ์ํ๋ ๊ฒ์ ๋ณ๋ก ๊ฐ์ฒด ์งํฅ์ ์ธ ์ค๊ณ๊ฐ ์๋ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,49 @@
+package christmas.model;
+
+import christmas.config.MenuType;
+
+public class PromotionGenerator {
+ public static final int DISCOUNT_LIMIT_PRICE = 10000;
+
+ private final Promotion promotion;
+
+ public PromotionGenerator(final VisitDate visitDate, final Order order) {
+ this.promotion = new Promotion();
+
+ if (isDiscountTarget(order.getTotalPrice())) {
+ christmasDDayEvent(visitDate.getVisitDate());
+ weekdayEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.DESSERT));
+ weekendEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.MAIN));
+ specialDayEvent(visitDate.getVisitDate());
+ giftEvent(order.getTotalPrice());
+ }
+ }
+
+ private boolean isDiscountTarget(int totalPrice) {
+ return totalPrice >= DISCOUNT_LIMIT_PRICE;
+ }
+
+ private void christmasDDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new ChristmasDDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void weekdayEvent(int weekday, int dessertQuantity) {
+ promotion.setDiscountInfo(new WeekdayEvent(weekday, dessertQuantity).getDiscountInfo());
+ }
+
+ private void weekendEvent(int weekday, int mainQuantity) {
+ promotion.setDiscountInfo(new WeekendEvent(weekday, mainQuantity).getDiscountInfo());
+ }
+
+ private void specialDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new SpecialDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void giftEvent(int totalPrice) {
+ promotion.setDiscountInfo(new GiftEvent(totalPrice).getDiscountInfo());
+ }
+
+ public Promotion getPromotion() {
+ return promotion;
+ }
+} | Java | ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌํ๊ณ ๊ทธ ๊ฒฐ๊ณผ๋ก Promotionํด๋์ค๋ฅผ ์์ฑํ๋ ์ญํ ์ ํ๋ ๊ฒ ๊ฐ๊ตฐ์.
์ ๋ Promotion์ ๊ตณ์ด ์์ฑํ์ง ์๊ณ ์ด ํด๋์ค์์ ๊ด๋ฆฌํ๋๊ฒ ๋ ์ข๋ค๊ณ ์๊ฐํ๋๋ฐ ์ด๋ ๊ฒ ์ค๊ณํ์ ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,49 @@
+package christmas.model;
+
+import christmas.config.MenuType;
+
+public class PromotionGenerator {
+ public static final int DISCOUNT_LIMIT_PRICE = 10000;
+
+ private final Promotion promotion;
+
+ public PromotionGenerator(final VisitDate visitDate, final Order order) {
+ this.promotion = new Promotion();
+
+ if (isDiscountTarget(order.getTotalPrice())) {
+ christmasDDayEvent(visitDate.getVisitDate());
+ weekdayEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.DESSERT));
+ weekendEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.MAIN));
+ specialDayEvent(visitDate.getVisitDate());
+ giftEvent(order.getTotalPrice());
+ }
+ }
+
+ private boolean isDiscountTarget(int totalPrice) {
+ return totalPrice >= DISCOUNT_LIMIT_PRICE;
+ }
+
+ private void christmasDDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new ChristmasDDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void weekdayEvent(int weekday, int dessertQuantity) {
+ promotion.setDiscountInfo(new WeekdayEvent(weekday, dessertQuantity).getDiscountInfo());
+ }
+
+ private void weekendEvent(int weekday, int mainQuantity) {
+ promotion.setDiscountInfo(new WeekendEvent(weekday, mainQuantity).getDiscountInfo());
+ }
+
+ private void specialDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new SpecialDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void giftEvent(int totalPrice) {
+ promotion.setDiscountInfo(new GiftEvent(totalPrice).getDiscountInfo());
+ }
+
+ public Promotion getPromotion() {
+ return promotion;
+ }
+} | Java | 26๋ฒ ๋ผ์ธ ๋ถํฐ 44๋ฒ ๋ผ์ธ์ ๊ฐ๊ฐ์ ์ด๋ฒคํธ๋ฅผ ์ ์ฉํ๊ณ ํํ ๊ธ์ก์ promotion๊ฐ์ฒด์ set ํด์ฃผ๋ ๊ฒ ๊ฐ์๋ฐ ์ด๋ถ๋ถ์ ์กฐ๊ธ ๋ ๊ฐ๋ตํ ํ ์ ์์ง ์์๊น์? |
@@ -0,0 +1,49 @@
+package christmas.controller;
+
+import christmas.config.Constant;
+import christmas.config.EventBadge;
+import christmas.config.Gift;
+import christmas.model.Order;
+import christmas.model.Promotion;
+import christmas.model.PromotionGenerator;
+import christmas.model.VisitDate;
+import christmas.view.OutputView;
+
+public class PromotionController {
+ private final VisitDate visitDate;
+ private final Order order;
+ private final Promotion promotion;
+
+ public PromotionController() {
+ visitDate = InputController.setVisitDate();
+ order = InputController.setOrder();
+ promotion = new PromotionGenerator(visitDate, order).getPromotion();
+ }
+
+ public void active() {
+ print();
+ }
+
+ private int totalPrice() {
+ return order.getTotalPrice();
+ }
+
+ private int totalDiscount() {
+ return promotion.getTotalDiscount();
+ }
+
+ private boolean isEmptyPromotion() {
+ return promotion.getTotalDiscount() == 0;
+ }
+
+ private void print() {
+ OutputView.printVisitDate(visitDate.getVisitDate());
+ OutputView.printOrder(order.getOrderList());
+ OutputView.printTotalPrice(totalPrice());
+ OutputView.printGift(Gift.getGift(totalPrice()));
+ OutputView.printPromotion(isEmptyPromotion(), promotion.getPromotionList());
+ OutputView.printTotalDiscount(totalDiscount() * Constant.MINUS);
+ OutputView.printPaymentPrice(totalPrice() - promotion.getDiscount());
+ OutputView.printBadge(EventBadge.findBadgeByTotalDiscount(totalDiscount()));
+ }
+} | Java | ์ผ๋ฐ ์ ์ผ๋ก Controller์์๋ ๋์๋ง ์ ์ํ์ง ์ํ๋ ์ ์ํ์ง ์๋ ๊ฑธ๋ก ์๊ณ ์๋๋ฐ, PromotionController๋ Controller๋ณด๋ค๋ ๋๋ฉ์ธ์ค๋ฌ์ด(?)๊ฒ ๊ฐ์์ |
@@ -0,0 +1,26 @@
+package christmas.config;
+
+import java.util.Arrays;
+
+public enum EventBadge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NONE("์์", 0);
+
+ private final String name;
+ private final int limitPrice;
+
+ EventBadge(String name, int limitPrice) {
+ this.name = name;
+ this.limitPrice = limitPrice;
+ }
+
+ public static String findBadgeByTotalDiscount(int totalDiscount) {
+ return Arrays.stream(values())
+ .filter(badge -> totalDiscount >= badge.limitPrice)
+ .findFirst()
+ .orElse(NONE)
+ .name;
+ }
+} | Java | ๋ฐ๊ตด์ด๋ ์ฝ๋ ๋ณด๊ณ ์๊ฒ๋์์ง๋ง Predicate ๋ฅผ ์ด์ฉํด์ ์กฐ๊ฑด์ ๊ฑธ์ด์ฃผ๋ฉด ์ข์์ ๊ฒ ๊ฐ์ต๋๋ค
ํจ์ํ ์ธํฐํ์ด์ค์ ๋ํ ๊ณต๋ถ๋ฅผ ํด์ผ๊ฒ ๋ค์! |
@@ -0,0 +1,25 @@
+package christmas.config;
+
+public class Message {
+ public static final String INPUT_DATE = "12์ ์ค ์๋น ์์ ๋ฐฉ๋ฌธ ๋ ์ง๋ ์ธ์ ์ธ๊ฐ์? (์ซ์๋ง ์
๋ ฅํด ์ฃผ์ธ์!)";
+ public static final String INPUT_ORDER = "์ฃผ๋ฌธํ์ค ๋ฉ๋ด๋ฅผ ๋ฉ๋ด์ ๊ฐ์๋ฅผ ์๋ ค ์ฃผ์ธ์. (e.g. ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,์ด์ฝ์ผ์ดํฌ-1)";
+
+ public static final String OUTPUT_VISIT_DATE = "12์ %d์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!\n";
+ public static final String OUTPUT_MENU_TITLE = "\n<์ฃผ๋ฌธ ๋ฉ๋ด>";
+ public static final String OUTPUT_ITEM = "%s %d๊ฐ%n";
+ public static final String OUTPUT_WON = "%s์%n";
+ public static final String OUTPUT_MINUS_WON = "-" + OUTPUT_WON;
+ public static final String OUTPUT_TOTAL_PRICE = "%n<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_GIFT_TITLE = "\n<์ฆ์ ๋ฉ๋ด>";
+ public static final String OUTPUT_PROMOTION_TITLE = "\n<ํํ ๋ด์ญ>";
+ public static final String OUTPUT_PROMOTION_ITEM = "%s: " + OUTPUT_MINUS_WON;
+ public static final String OUTPUT_TOTAL_DISCOUNT = "%n<์ดํํ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_PAYMENT_PRICE = "%n<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>%n" + OUTPUT_WON;
+ public static final String OUTPUT_BADGE = "%n<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>%n%s%n";
+ public static final String OUTPUT_NONE = "์์";
+
+
+ public static final String ERROR_MESSAGE_PREFIX = "[ERROR]";
+ public static final String ERROR_INPUT_DATE = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ๋ ์ง์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+ public static final String ERROR_INPUT_ORDER = ERROR_MESSAGE_PREFIX + " ์ ํจํ์ง ์์ ์ฃผ๋ฌธ์
๋๋ค. ๋ค์ ์
๋ ฅํด ์ฃผ์ธ์.";
+} | Java | ์ถ๋ ฅ๋ถ๋ถ์ ๋ฉ์์ง ์์์ ๊ฒฝ์ฐ์๋ ๊ฐ๋ฐํ๋ฉด์ ํญ์ ๊ณ ๋ฏผํ๋ ๋ถ๋ถ์
๋๋ค. ์ฝ๋๋ฅผ ํ ๊ตฐ๋ฐ ๋ชจ์ ๊ฐ๋
์ฑ์ ๋์ผ์ง, ๋ถ๋ฆฌํด์ ๋ฉ์์ง๋ฅผ ์กฐ๊ธ๋ ์ ์ฐํ๊ฒ ์์ ๊ฐ๋ฅํ๊ฒ ํ ์ง ๊ณ ๋ฏผํ์ง๋ง ๋๋ถ๋ถ ์ถ๋ ฅ์์๋ ์ ํด์ง ๊ท๊ฒฉ์ ์ ์ ๋ ๋ฐ์ดํฐ๋ฅผ ๋ณด๋ด์ค๋ค๊ณ ์๊ฐํ์ฌ ๋ณ๊ฒฝ๊ฐ๋ฅ์ฑ์ด ํฐ ๋ฉ์์ง ์์ฒด๋ฅผ ๋ถ๋ฆฌํ๋ ์ชฝ์ ์ ํํ์ต๋๋ค.
์ ๋ ๋ถ๋ฆฌํ๋๋ฐ ๋์ํฉ๋๋ค! ์ฒ์์๋ ์๋ฌ๋ฉ์์ง๋ฅผ ๋ค๋ฃจ๋ ํด๋์ค๋ฅผ ๋ณ๋๋ก ๋๊น ํ๋๋ฐ ์๊ฐ๋ณด๋ค ์ ์ ์๋ฌ๋ฉ์์ง ์ฌ์ฉ์ผ๋ก ์ด๋ฒ์๋ Message ํด๋์ค ๋ด์ ํฉ์ณ์ ์ฌ์ฉ์ ํ์ต๋๋ค! |
@@ -0,0 +1,25 @@
+package christmas.controller;
+
+import christmas.model.Order;
+import christmas.model.VisitDate;
+import christmas.view.InputView;
+
+public class InputController {
+ public static VisitDate setVisitDate() {
+ try {
+ return new VisitDate(InputView.readDate());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setVisitDate();
+ }
+ }
+
+ public static Order setOrder() {
+ try {
+ return new Order(InputView.readOrder());
+ } catch (IllegalArgumentException illegalArgumentException) {
+ System.out.println(illegalArgumentException.getMessage());
+ return setOrder();
+ }
+ }
+} | Java | ํจ์๋ช
์ง๊ธฐ์ ๊ด๋ จํด์๋ ์ด๋ฒ ํ๋ก์ ํธ์์ ๋ง์ด ๋ถ์กฑํ๋ค์... |
@@ -0,0 +1,49 @@
+package christmas.model;
+
+import christmas.config.MenuType;
+
+public class PromotionGenerator {
+ public static final int DISCOUNT_LIMIT_PRICE = 10000;
+
+ private final Promotion promotion;
+
+ public PromotionGenerator(final VisitDate visitDate, final Order order) {
+ this.promotion = new Promotion();
+
+ if (isDiscountTarget(order.getTotalPrice())) {
+ christmasDDayEvent(visitDate.getVisitDate());
+ weekdayEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.DESSERT));
+ weekendEvent(visitDate.getWeekDay(), order.getMenuQuantity(MenuType.MAIN));
+ specialDayEvent(visitDate.getVisitDate());
+ giftEvent(order.getTotalPrice());
+ }
+ }
+
+ private boolean isDiscountTarget(int totalPrice) {
+ return totalPrice >= DISCOUNT_LIMIT_PRICE;
+ }
+
+ private void christmasDDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new ChristmasDDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void weekdayEvent(int weekday, int dessertQuantity) {
+ promotion.setDiscountInfo(new WeekdayEvent(weekday, dessertQuantity).getDiscountInfo());
+ }
+
+ private void weekendEvent(int weekday, int mainQuantity) {
+ promotion.setDiscountInfo(new WeekendEvent(weekday, mainQuantity).getDiscountInfo());
+ }
+
+ private void specialDayEvent(int visitDate) {
+ promotion.setDiscountInfo(new SpecialDayEvent(visitDate).getDiscountInfo());
+ }
+
+ private void giftEvent(int totalPrice) {
+ promotion.setDiscountInfo(new GiftEvent(totalPrice).getDiscountInfo());
+ }
+
+ public Promotion getPromotion() {
+ return promotion;
+ }
+} | Java | ์ฒ์ ์ค๊ณ์์๋ Promotionํด๋์ค์์ ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌํ๊ณ ์ํ๋ฅผ ์ ์ฅํ๋ ํํ๋ฅผ ๊ฐ์ง๊ณ ์์๋๋ฐ
ํ์ ์ด์์ผ๋ก Promotionํด๋์ค๊ฐ ๋น๋ํด์ก๋ค๊ณ ์๊ฐ์ ํด์ ์ด๋ฅผ ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ๊ตฌํ๋ PromotionGeneratorํด๋์ค์ ์ด๋ฒคํธ ๊ฒฐ๊ณผ๋ฅผ ์ฒ๋ฆฌํ๋ Promotion ํด๋์ค๋ก ๋ถ๋ฆฌํ์ต๋๋ค. ์ด ๊ณผ์ ์์ Promotion์ ์ํ๋ฅผ ์กฐ์ํ๋ setter๋ฅผ ์ฌ์ฉํ๊ฒ ๋์๋๋ฐ ์คํ๋ ค ๊ฐ์ฒด ์งํฅ์ ์ด์ง ๋ชปํ ์ค๊ณ๊ฐ ๋์๋ค์ใ
ใ
|
@@ -0,0 +1,49 @@
+package christmas.controller;
+
+import christmas.config.Constant;
+import christmas.config.EventBadge;
+import christmas.config.Gift;
+import christmas.model.Order;
+import christmas.model.Promotion;
+import christmas.model.PromotionGenerator;
+import christmas.model.VisitDate;
+import christmas.view.OutputView;
+
+public class PromotionController {
+ private final VisitDate visitDate;
+ private final Order order;
+ private final Promotion promotion;
+
+ public PromotionController() {
+ visitDate = InputController.setVisitDate();
+ order = InputController.setOrder();
+ promotion = new PromotionGenerator(visitDate, order).getPromotion();
+ }
+
+ public void active() {
+ print();
+ }
+
+ private int totalPrice() {
+ return order.getTotalPrice();
+ }
+
+ private int totalDiscount() {
+ return promotion.getTotalDiscount();
+ }
+
+ private boolean isEmptyPromotion() {
+ return promotion.getTotalDiscount() == 0;
+ }
+
+ private void print() {
+ OutputView.printVisitDate(visitDate.getVisitDate());
+ OutputView.printOrder(order.getOrderList());
+ OutputView.printTotalPrice(totalPrice());
+ OutputView.printGift(Gift.getGift(totalPrice()));
+ OutputView.printPromotion(isEmptyPromotion(), promotion.getPromotionList());
+ OutputView.printTotalDiscount(totalDiscount() * Constant.MINUS);
+ OutputView.printPaymentPrice(totalPrice() - promotion.getDiscount());
+ OutputView.printBadge(EventBadge.findBadgeByTotalDiscount(totalDiscount()));
+ }
+} | Java | MVCํจํด์ ๋ํ ๋ด์ฉ์ ํ๋ฆฌ์ฝ์ค๋ฅผ ์์ํ๋ฉด์ ์ ํ๋๋ฐ ์ํํ ์ง์์ด ์๋ชป๋ ์ฝ๋๋ฅผ ๋ง๋ค์๋ค์ ใ
ใ
;;
๋ค์ ๊ณต๋ถํด๋ณด๊ฒ ์ต๋๋ค! |
@@ -0,0 +1,27 @@
+package christmas.domain.policy.discount;
+
+import christmas.domain.Orders;
+import christmas.domain.VisitDate;
+
+public class DdayDiscountPolicy implements DiscountPolicy {
+ public static final int CHRISTMAS_DATE = 25;
+ public static final int DISCOUNT_AMOUNT = 1000;
+ public static final int ADDITIONAL_DISCOUNT_AMOUNT = 100;
+ public static final int NOT_DISCOUNT_AMOUNT = 0;
+
+ @Override
+ public int discount(VisitDate visitDate, Orders orders) {
+ if (isNotAfter(visitDate)) {
+ return calculateDiscount(visitDate);
+ }
+ return NOT_DISCOUNT_AMOUNT;
+ }
+
+ private boolean isNotAfter(VisitDate visitDate) {
+ return visitDate.isNotAfter(CHRISTMAS_DATE);
+ }
+
+ private int calculateDiscount(VisitDate visitDate) {
+ return DISCOUNT_AMOUNT + visitDate.calculateDiscount(ADDITIONAL_DISCOUNT_AMOUNT);
+ }
+} | Java | DdayDiscountPolicy์ discount ๋ฉ์๋๊ฐ ๋จ๋
์ผ๋ก ์ฌ์ฉ๋ ์ ๋ ์๋๋ฐ ๋ง์ ์ดํ๋ฉด ์ ์ฉ์ด ๋ถ๊ฐ๋ฅํ๋ค๋ ์กฐ๊ฑด์ ์์ ํ์ง ์์ ๊ฒ ๊ฐ์ต๋๋ค. DiscountPolicy๋ฅผ ์ถ์ํด๋์ค๋ก ํ์ฌ ๋ง์ ์ดํ ์ ์ฉ ๋ถ๊ฐ ์กฐ๊ฑด์ ๊ฑธ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | domain์ด ํน์ Dto์ ์ข
์๋๋ ๊ฒ์ ์ด๋ป๊ฒ ์๊ฐํ์๋์? ์ ๋ Dto๋ ๋ณ๋์ฑ์ด ํฐ ๊ฐ์ฒด๋ผ๊ณ ์๊ฐํด์ domain์ด ์์กดํ๋ ํํ๋ ์ข์ง ์๋ค๊ณ ์๊ฐํฉ๋๋ค. |
@@ -0,0 +1,36 @@
+package christmas.domain;
+
+import christmas.exception.NotExistsBadgeException;
+import java.util.Arrays;
+
+public enum Badge {
+ SANTA("์ฐํ", 20000),
+ TREE("ํธ๋ฆฌ", 10000),
+ STAR("๋ณ", 5000),
+ NONE("์์", 0),
+ ;
+
+ private final String name;
+ private final int minimumAmount;
+
+ private Badge(String name, int minimumAmount) {
+ this.name = name;
+ this.minimumAmount = minimumAmount;
+ }
+
+ public static String getNameByBenefit(int amount) {
+ return from(amount).name;
+ }
+
+ public static Badge from(int amount) {
+ return Arrays.stream(Badge.values())
+ .filter(badge -> badge.isGreaterThan(amount))
+ .findFirst()
+ .orElseThrow(NotExistsBadgeException::new);
+ }
+
+ private boolean isGreaterThan(int benefitAmount) {
+ return this.minimumAmount <= benefitAmount;
+ }
+}
+ | Java | enum์ ์์๊ฐ ๊ณ ์ ๋์ด์ผ ์ ์์คํ๋๋ ์ฝ๋๋ผ๊ณ ์๊ฐํฉ๋๋ค. ๋ค๋ฅธ ๋ฑ๊ธ์ด ์ถ๊ฐ๋๊ฑฐ๋ ํ์ ๋ ์ํฅ์ด ์๋๋ก minimumAmount๋ก ์ ๋ ฌ์ ํ๋ ๊ฒ์ ์ด๋จ๊น์? |
@@ -0,0 +1,18 @@
+package christmas.domain;
+
+public enum DiscountType {
+ CHRISTMAS_DDAY("ํฌ๋ฆฌ์ค๋ง์ค ๋๋ฐ์ด ํ ์ธ"),
+ WEEKDAY("ํ์ผ ํ ์ธ"),
+ WEEKEND("์ฃผ๋ง ํ ์ธ"),
+ SPECIAL("ํน๋ณ ํ ์ธ");
+
+ private final String name;
+
+ DiscountType(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+} | Java | ์ด๋ฏธ Policies๋ก ํด๋์ค๋ณ ๊ตฌ๋ถ์ด ๋์ด ์๋๋ฐ enum์ผ๋ก ์ ๋ชฉ๋ง ๊ฐ์ง๊ณ ์์ ํ์๊ฐ ์์๊น์? ์ ๋ชฉ์ ๊ฐ Policy ๋ด๋ถ๋ก ๋ฃ๋ ๊ฒ๋ ๊ด์ฐฎ์ ๊ฑฐ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,53 @@
+package christmas.domain;
+
+import christmas.dto.BenefitDto;
+import christmas.dto.GiftsDto;
+import java.util.function.Supplier;
+
+public class Bill {
+ public static final int MINIMUM_ORDERS_PRICE = 10000;
+ public static final int EVENT_NOT_APPLIED_AMOUNT = 0;
+
+ private final Discounts discounts;
+ private final Gifts gifts;
+
+ public Bill(Discounts discounts, Gifts gifts) {
+ this.discounts = discounts;
+ this.gifts = gifts;
+ }
+
+ public int getTotalBenefit(Orders orders) {
+ return getAmount(this::sumBenefit, orders);
+ }
+
+ public int getDiscountPrice(Orders orders) {
+ return orders.getTotalPrice() - discounts.sumDiscount();
+ }
+
+ public GiftsDto getGiftDto() {
+ return new GiftsDto(gifts.getResult());
+ }
+
+ public BenefitDto getBenefitDto() {
+ return new BenefitDto(discounts.getResult(), gifts.sumPrice());
+ }
+
+ public String getBadgeName() {
+ return Badge.getNameByBenefit(sumBenefit());
+ }
+
+ private int sumBenefit() {
+ return discounts.sumDiscount() + gifts.sumPrice();
+ }
+
+ private boolean isEventApplicable(Orders orders) {
+ return orders.getTotalPrice() >= MINIMUM_ORDERS_PRICE;
+ }
+
+ private <T> int getAmount(Supplier<T> supplier, Orders orders) {
+ if (isEventApplicable(orders)) {
+ return (int) supplier.get();
+ }
+ return EVENT_NOT_APPLIED_AMOUNT;
+ }
+} | Java | ์ ๋ ๋๊ฐํฉ๋๋ค ๐ค
์ฌ์ค ์ ๋ ๋๋ฉ์ธ์ toDto ๋ฉ์๋๋ฅผ ๋ง๋ค์ด์ ๊ตฌํํ๊ธด ํ์ด์
DTO์์๋ Mapper๋ฅผ ํตํด์๋ ๋ค๋ฅธ ๋ฐฉ์์ผ๋ก DTO๋ฅผ ์์ฑํ๋ ค๋ฉด getter๋ฅผ ์ด์ด์ผ ํ๋๋ฐ getter๋ฅผ ์ต๋ํ ์ง์ํด๋ณผ๋ ค๊ณ ๊ทธ๋ ๊ฒ ํ์ต๋๋ค.
๊ทธ๋ฐ๋ฐ ํ๋ฆฌ์ฝ์ค๋ ๋ค๋ฅธ ๊ธ๋ค ๋ณด๋ ๋ง์ ๋ถ๋ค์ด ์ค์ํ ๊ฐ์ฒด๊ฐ(๋๋ฉ์ธ) ๋ ์ค์ํ ๊ฐ์ฒด(DTO)๋ฅผ ์์กดํ๋ ๊ฒ์ด ์ข์ง ์๋ค๊ณ ๋ง์ํ์๋๋ผ๊ณ ์ ๊ทธ๋์ ์ ๋ DTO์ ์์ฑ๋ฐฉ์์ ๋ํด์ ์๋กญ๊ฒ ๊ณ ๋ฏผํ๊ฒ ๋์๋ค์ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.