code stringlengths 41 34.3k | lang stringclasses 8
values | review stringlengths 1 4.74k |
|---|---|---|
@@ -0,0 +1,16 @@
+package racingcar.constants;
+
+public enum GameConstants {
+ CAR_NAME_LENGTH_MIN(1),
+ CAR_NAME_LENGTH_MAX(5);
+
+ private final int number;
+
+ GameConstants(int number) {
+ this.number = number;
+ }
+
+ public int getNumber() {
+ return number;
+ }
+} | Java | GameRule ๋๋ฉ์ธ์ด ๋ง๋ค์ด ์ ธ์, GameConstants์ ์ค๋ณต๋ ์๋ฏธ๋ฅผ ๋ด๋๊ฑฐ ๊ฐ์๋ฐ
ํด๋น ํด๋์ค์ ๋ํด ๊ณ ๋ฏผ์ด ์ข๋ ํ์ํด๋ณด์ฌ์ฉ |
@@ -0,0 +1,30 @@
+package racingcar.domain;
+
+public class RacingCar {
+ private final CarName carName;
+ private int moveCount;
+
+ public RacingCar(String name) {
+ this.carName = new CarName(name);
+ moveCount = 0;
+ }
+
+ public int getMoveCount() {
+ return moveCount;
+ }
+
+ public String getCarName() {
+ return carName.getName();
+ }
+
+ public void attemptToMove(GameRule gameRule) {
+ if (gameRule.canMove()) {
+ move();
+ }
+ }
+
+ private void move() {
+ moveCount++;
+ }
+
+} | Java | ### ํ์ฌ ์์ ์ฌํญ
- GameRule ๋๋ฉ์ธ์ ๋ฉค๋ฒ๋ณ์๋ก RandomNumber์ TrialCount ์ถ๊ฐ
- RandomNumber๋ ์๋์ฐจ์ ์ ์ง์ฌ๋ถ๋ฅผ ํ๋จํ ๋๋ง ํ์ํ๋ฐ, ์ ์ง์ฌ๋ถ ํ๋จ๋ก์ง์ธ GameRule์ ์์ผ๋ฏ๋ก RandomNumber๋ฅผ GameRule์ ๋ฉค๋ฒ๋ณ์๋ก ์ถ๊ฐํจ
- GameRule ๊ฐ์ฒด๋ฅผ RacingCar์ ๋ฉ์๋ ์์์ ์์ฑํ์ง ์๊ณ Controller์์ ์์ฑํ๋๋ก ์์
- Controller์์ RacingCars์ GameRule๊ฐ์ฒด๋ฅผ ๋งค๊ฐ๋ณ์๋ก ์ ๋ฌ
- GameRandomNumber์ getRandomNumber() ๋ฉ์๋ ์์์ ๋ฐ๋ก ๋๋ค์ซ์๋ฅผ ๋ฐํํ๋๋ก ์์
- ๋๋ค์ซ์๊ฐ ํ์ํ ๋๋ง๋ค ์๋ก์ด RandomNumber ๊ฐ์ฒด๋ฅผ ์์ฑํ์ง ์๊ณ , GameRule์ด ๊ฐ์ง๊ณ ์๋ RandomNumber ๊ฐ์ฒด๋ฅผ ํตํด ๋๋ค์ซ์ ๊ฐ๋ง ๋ฐํ๋ฐ๋๋ก ํจ
### Issue 1 : GameRule ๋๋ฉ์ธ๊ณผ ๋ค๋ฅธ ๋๋ฉ์ธ ๊ฐ์ ์์กด๊ด๊ณ ์ค์ ์ ์ด๋ ค์
- RacingCars์ ๋ฉ์๋ ์์์ ๊ฐ ์๋์ฐจ ๊ฐ์ฒด๋ง๋ค ์ ์ง์ฌ๋ถํ๋จ์ด ํ์ํ๋ฐ, GameRule ๊ฐ์ฒด๋ฅผ RacingCar์๊ฒ ๋๊ฒจ์ฃผ์ง ์๊ณ ์ธ๋ถ์์ ํ๋จ ํ RacingCar๋ฅผ ์ ์ง์ํฌ ๋ฐฉ๋ฒ์ ๋ชจ๋ฅด๊ฒ ์ต๋๋ค..!
### Issue 2 : GameRandomNumber์์ randomNumber๋ผ๋ ๋ฉค๋ฒ๋ณ์์ ํ์์ฑ
- getRandomNumber()์์ ๋ฐ๋ก ๋๋ค์ซ์๋ฅผ ๋ฐํํด์ฃผ๋๋ฐ, ๊ทธ๋ผ randomNumber ๋ฉค๋ฒ๋ณ์๊ฐ ์์ด๋ ๋๋ ๊ฒ์ผ๊น์?
### Issue 3 : GameConstants ํด๋์ค
- ๊ฒ์์์ 5๊ฐ ์ค, 3๊ฐ๋ ํ ๊ณณ์์๋ง ํธ์ถํ๊ณ ๋๋จธ์ง 2๊ฐ๋ ๋ ๊ตฐ๋ฐ์์ ํธ์ถํ๋๋ฐ, ์ด ์์๋ค์ ์ด๋ป๊ฒ ๊ด๋ฆฌํ๋ ๊ฒ์ด ํจ๊ณผ์ ์ผ์ง ๊ถ๊ธํฉ๋๋ค! ์๋๋ ์ ๊ฐ ์๊ฐํด ๋ณธ ๋ฐฉ๋ฒ๋ค์
๋๋ค.
- ๋ชจ๋ ์์๋ฅผ Enum ํด๋์ค๋ก ๋ชจ์์ ๊ด๋ฆฌ
- ํ ๊ณณ์์ ํธ์ถํ๋ ์์๋ ๊ฐ๊ฐ ์ฌ์ฉ๋๋ ๋๋ฉ์ธ์ ๋ฉค๋ฒ๋ณ์๋ก ์ ์ธ, ๋๋จธ์ง๋ Enumํด๋์ค๋ก ๊ด๋ฆฌ
- ๋ชจ๋ ์์๋ฅผ ๊ฐ๊ฐ ์ฌ์ฉ๋๋ ๋๋ฉ์ธ์ ๋ฉค๋ฒ๋ณ์๋ก ์ ์ธ
- ์ฌ๋ฌ ๊ณณ์์ ์ฌ์ฉ๋๋ ์์์ ๊ฒฝ์ฐ, ํน์ ๋๋ฉ์ธ์ ์ ์ ์์๋ก ์ ์ธํ๊ณ ๋ค๋ฅธ ๋๋ฉ์ธ์์ ํธ์ถ
---
๊ฐ ๋๋ฉ์ธ์ ์ญํ ์ ๊ตฌ๋ถํ๋ ๊ฒ๊ณผ ๋๋ฉ์ธ ๊ฐ ์์กด๊ด๊ณ๋ฅผ ์ค์ ํ๋ ๋ถ๋ถ์ด ์ด๋ ต๊ณ ๊ฐ์ธ์ ์ผ๋ก ์ฝํ ๊ฒ ๊ฐ์ต๋๋ค.
์ ์ฒด์ ์ผ๋ก ์ ๊ฐ ํผ๋์ค๋ฌ์ด ๋ถ๋ถ์ด ๋ง์์ ์ฝ๋๋ ๋ฌ๋ผ์ง ์ ์ด ๋ง์ด ์๊ณ , ์ด์๋ค ์์ ์ ์ด๋์์ต๋๋ค. ๋ฆฌ๋ทฐ ๋ถํ๋๋ฆฝ๋๋ค! |
@@ -0,0 +1,24 @@
+package com.example.chatgptcodereviewtest.controller;
+
+import com.example.chatgptcodereviewtest.service.TestService2;
+import lombok.RequiredArgsConstructor;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * ์ค๋ช
:
+ *
+ * @author ์ตํ๋ฒ(Jayce) / hb.choi@dreamus.io
+ * @since 2023/03/23
+ */
+@RestController
+@RequestMapping("/test2")
+@RequiredArgsConstructor
+public class TestController2 {
+
+ private final TestService2 testService2;
+
+ @GetMapping
+ public String getText(@RequestParam(value = "label", required = false) String label) {
+ return testService2.getUppercaseTestLabel(label);
+ }
+}
\ No newline at end of file | Java | ์ ์ฝ๋๋ `TestController2`๋ผ๋ REST API ์ปจํธ๋กค๋ฌ ํด๋์ค์
๋๋ค.
๊ฐ์ ์ ์:
1. Javadoc(์ฃผ์) ์์ฑ์ด ํ์ํฉ๋๋ค. ๋ฉ์๋์ ํด๋์ค์ ์ค๋ช
์ ๊ตฌ์ฒด์ ์ผ๋ก ๋ฌ์์ฃผ์ด ๊ฐ๋
์ฑ์ ๋์ผ ์ ์์ต๋๋ค.
2. ๋ง์ง๋ง ์ค์ ๊ฐํ ๋ฌธ์์ด์ด ์์ต๋๋ค. ์์ค์ฝ๋๋ฅผ ์์ ๋ฐ ํธ์งํ ๋ ๊น์๋ฌ๊ฐ ๋ฐ์ํ์ง ์๋๋ก ๊ฐํ ๋ฌธ์์ด์ ์ถ๊ฐํ๋ ๊ฒ์ด ์ข์ต๋๋ค.
3. `@RequestParam` ์ด๋
ธํ
์ด์
์ required ์์ฑ๊ฐ์ false๋ก ๋์ด ์์ด, ํ์๋ก ๋ค์ด์ฌ ๊ฐ์ด ์๋๋๋ค. ์ด์ ๋ํ ์ฒ๋ฆฌ๋ฅผ ํ๊ณ ์ถ๋ค๋ฉด, ํด๋น ํ๋ผ๋ฏธํฐ ๋ณ์์ ๋ ์ฒดํฌ๋ ๋ํดํธ๊ฐ ๋ฑ์ ์ง์ ํด์ผ ํฉ๋๋ค.
๋ฒ๊ทธ ์ํ์ด ์์ด ๋ณด์
๋๋ค. |
@@ -0,0 +1,17 @@
+package com.example.chatgptcodereviewtest.service;
+
+import org.springframework.stereotype.Service;
+
+/**
+ * ์ค๋ช
:
+ *
+ * @author ์ตํ๋ฒ(Jayce) / hb.choi@dreamus.io
+ * @since 2023/03/23
+ */
+@Service
+public class TestService2 {
+
+ public String getUppercaseTestLabel(String label) {
+ return label.toUpperCase();
+ }
+} | Java | ์ด ์ฝ๋๋ ๋ด์์ ์ธ ๋ฌธ์ ๋ ๋ฒ๊ทธ๊ฐ ์๋ ๊ฒ ๊ฐ์ต๋๋ค.
๋จ์ํ๊ฒ ๋ฌธ์์ด์ ๋๋ฌธ์๋ก ๋ณ๊ฒฝํ๋ ๋ฉ์๋๋ฅผ ๊ฐ์ง๊ณ ์์ผ๋ฉฐ, Spring์ Service ์ด๋
ธํ
์ด์
์ ์ฌ์ฉํ์ฌ Bean์ผ๋ก ๋ฑ๋ก๋์ด ์์ต๋๋ค.
๋ณ์๋ช
๊ณผ ๋ฉ์๋๋ช
์ ์ง๊ด์ฑ ์ธก๋ฉด์์ ๊ฐ์ ํ ์ ์ด ์๋ ๊ฒ ๊ฐ์ต๋๋ค. 'label'์ ๊ตฌ์ฒด์ ์ธ ์๋ฏธ๋ฅผ ์๊ธฐ ์ด๋ ต์ต๋๋ค. ๋ ๊ตฌ์ฒด์ ์ธ ๋ช
์นญ์ ์ฌ์ฉํ๋ค๋ฉด ์ฝ๋์ ๊ฐ๋
์ฑ์ด ํฅ์๋ ๊ฒ์
๋๋ค. |
@@ -0,0 +1,35 @@
+package nextstep.subway.applicaion;
+
+import java.util.List;
+import nextstep.subway.applicaion.dto.PathResponse;
+import nextstep.subway.domain.Line;
+import nextstep.subway.domain.LineRepository;
+import nextstep.subway.domain.Path;
+import nextstep.subway.domain.PathFinder;
+import nextstep.subway.domain.Station;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+@Service
+@Transactional
+public class PathService {
+ private final LineRepository lineRepository;
+ private final StationService stationService;
+
+ public PathService(LineRepository lineRepository,
+ StationService stationService) {
+ this.lineRepository = lineRepository;
+ this.stationService = stationService;
+ }
+
+ public PathResponse searchPath(Long sourceId, Long targetId) {
+ Station source = stationService.findById(sourceId);
+ Station target = stationService.findById(targetId);
+ List<Line> lines = lineRepository.findAll();
+
+ PathFinder pathFinder = PathFinder.from(lines);
+ Path shortestPath = pathFinder.searchPath(source, target);
+ return PathResponse.from(shortestPath);
+ }
+
+} | Java | ๊ฒฝ๋ก๋ฅผ ์ฐพ๊ธฐ์ํด lines๋ผ๋ ์ ๋ณด๊ฐ ์๊ณ , ์ด ์ ๋ณด๋ฅผ ์ด์ฉํด ๊ฒฝ๋ก๋ฅผ ์ฐพ๋๋ฐ ์ด ๊ฒฝ๋ก๋ฅผ ์ฐพ๋ ์ฑ
์์ PathFinder๊ฐ ๊ฐ์ง๊ณ ์๊ณ ๊ทธ ๊ฒฐ๊ณผ ์ ๋ณด๋ Path๊ฐ ๊ฐ์ง๊ณ ์๋ค์!
๊ฐ์ฒด์งํฅ์์ ๊ฐ์ฒด๋ ์ํ์ ํ์๋ก ์ด๋ฃจ์ด์ ธ์๋ค๊ณ ํ๋๋ฐ์
๊ฒฝ๋ก๋ฅผ ์ฐพ๊ธฐ ์ํ ์ํ์ธ lines์ ํ์์ธ PathFinder๋ฅผ ํ๋์ ๊ฐ์ฒด๋ก ๋์ถํด๋ณผ ์๋ ์์๊น์?
๋ง์ฝ์ ์ด๋ ๊ฒ ๋ฆฌํฉํฐ๋ง ํ ๊ฒฝ์ฐ ๊ธฐ์กด์ ๋ง๋ค์ด ๋์๋ ํ
์คํธ๋ฅผ ํ์ฉํด์ ํ
์คํธ์ ๊ฒ์ฆ์ด๋ผ๋ ๋ณดํธ ์์ ๋ฆฌํฉํฐ๋ง์ ํด๋ณด์๋ ๊ฒ์ ๊ถํด๋๋ฆฝ๋๋ค! |
@@ -63,19 +63,19 @@ public void update(Station newUpStation, int minusDistance) {
}
public Section merge(Section section) {
- if (!isDownStation(section.upStation)) {
+ if (!hasDownStationAs(section.upStation)) {
throw new IllegalArgumentException("ํฉ์น๋ ค๋ ๊ตฌ๊ฐ์ ์ํ์ญ์ด ํํ์ญ๊ณผ ๊ฐ์์ผ ํฉ๋๋ค.");
}
return Section.of(line, upStation, section.downStation, distance + section.distance);
}
- public boolean isUpStation(Station station) {
+ public boolean hasUpStationAs(Station station) {
return upStation.equals(station);
}
- public boolean isDownStation(Station station) {
+ public boolean hasDownStationAs(Station station) {
return downStation.equals(station);
}
| Java | ๋ณ๊ฒฝ๋ ๋ค์ด๋ฐ์ด ์๋ฏธ๋ฅผ ์กฐ๊ธ ๋ ์ ์ ๋ฌํ๋ ๊ฒ ๊ฐ์์ ๐ |
@@ -1,6 +1,7 @@
package nextstep.subway.domain;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -34,23 +35,30 @@ public void add(Section section) {
public void remove(Station station) {
validationRemoveStation(station);
- Optional<Section> firstSection = sections.stream()
- .filter(s -> s.isDownStation(station))
- .findAny();
-
- Optional<Section> secondSection = sections.stream()
- .filter(s -> s.isUpStation(station))
- .findAny();
+ Optional<Section> sectionHasUpStation = findSectionHasUpStationAs(station);
+ Optional<Section> sectionHasDownStation = findSectionHasDownStationAs(station);
- firstSection.ifPresent(section -> sections.remove(section));
- secondSection.ifPresent(section -> sections.remove(section));
+ sectionHasUpStation.ifPresent(section -> sections.remove(section));
+ sectionHasDownStation.ifPresent(section -> sections.remove(section));
- if (firstSection.isPresent() && secondSection.isPresent()) {
- mergeExistingSections(firstSection.get(), secondSection.get());
+ if (sectionHasUpStation.isPresent() && sectionHasDownStation.isPresent()) {
+ mergeExistingSections(sectionHasUpStation.get(), sectionHasDownStation.get());
}
}
+ private Optional<Section> findSectionHasDownStationAs(Station station) {
+ return sections.stream()
+ .filter(s -> s.hasUpStationAs(station))
+ .findAny();
+ }
+
+ private Optional<Section> findSectionHasUpStationAs(Station station) {
+ return sections.stream()
+ .filter(s -> s.hasDownStationAs(station))
+ .findAny();
+ }
+
private List<Station> getStations() {
List<Station> stations = new ArrayList<>();
stations.add(sections.get(0).getUpStation());
@@ -152,4 +160,7 @@ private void mergeExistingSections(Section firstSection, Section secondSection)
sections.add(firstSection.merge(secondSection));
}
+ public List<Section> getSectionList() {
+ return Collections.unmodifiableList(sections);
+ }
} | Java | ์ ์ ํ ์ฌ์ด์ฆ๋ก ๋ฉ์๋๋ฅผ ๋๋์ด ์ฃผ์
จ๋ค์ ๐ |
@@ -0,0 +1,48 @@
+package nextstep.subway.unit;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import nextstep.subway.domain.Line;
+import nextstep.subway.domain.Station;
+import org.springframework.test.util.ReflectionTestUtils;
+
+public class PathFixture {
+ /** (10)
+ * ๊ต๋์ญ --- *2ํธ์ * --- ๊ฐ๋จ์ญ
+ * | |
+ * *3ํธ์ * (2) *์ ๋ถ๋น์ * (5)
+ * | |
+ * ๋จ๋ถํฐ๋ฏธ๋์ญ --- *3ํธ์ * --- ์์ฌ
+ (3) **/
+
+
+ public static Station ๊ฐ๋จ์ญ = new Station("๊ฐ๋จ์ญ");
+ public static Station ๊ต๋์ญ = new Station("๊ต๋์ญ");
+ public static Station ์์ฌ์ญ = new Station("์์ฌ์ญ");
+ public static Station ๋จ๋ถํฐ๋ฏธ๋์ญ = new Station("๋จ๋ถํฐ๋ฏธ๋์ญ");
+
+ public static int ๊ต๋์ญ_๊ฐ๋จ์ญ_๊ฑฐ๋ฆฌ = 10;
+ public static int ๊ฐ๋จ์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ = 5;
+ public static int ๊ต๋์ญ_๋จ๋ถํฐ๋ฏธ๋์ญ_๊ฑฐ๋ฆฌ = 2;
+ public static int ๋จ๋ถํฐ๋ฏธ๋์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ = 3;
+
+ public static Line ์ดํธ์ = Line.of("2ํธ์ ", "bg-green-600", ๊ต๋์ญ, ๊ฐ๋จ์ญ, ๊ต๋์ญ_๊ฐ๋จ์ญ_๊ฑฐ๋ฆฌ);
+ public static Line ์ผํธ์ = Line.of("3ํธ์ ", "bg-orange-500", ๊ต๋์ญ, ๋จ๋ถํฐ๋ฏธ๋์ญ, ๊ต๋์ญ_๋จ๋ถํฐ๋ฏธ๋์ญ_๊ฑฐ๋ฆฌ);
+ public static Line ์ ๋ถ๋น์ = Line.of("์ ๋ถ๋น์ ", "bg-red-500", ๊ฐ๋จ์ญ, ์์ฌ์ญ, ๊ฐ๋จ์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ);
+
+ public static List<Line> ๋
ธ์ _๋ชฉ๋ก = new ArrayList<>();
+
+ static {
+ ์ผํธ์ .addSection(๋จ๋ถํฐ๋ฏธ๋์ญ, ์์ฌ์ญ, ๋จ๋ถํฐ๋ฏธ๋์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ);
+
+ ReflectionTestUtils.setField(๊ฐ๋จ์ญ, "id", 1L);
+ ReflectionTestUtils.setField(๊ต๋์ญ, "id", 2L);
+ ReflectionTestUtils.setField(์์ฌ์ญ, "id", 3L);
+ ReflectionTestUtils.setField(๋จ๋ถํฐ๋ฏธ๋์ญ, "id", 4L);
+
+ ๋
ธ์ _๋ชฉ๋ก.addAll(Arrays.asList(์ดํธ์ , ์ผํธ์ , ์ ๋ถ๋น์ ));
+ }
+
+
+} | Java | ํฝ์ค์ณ ๋ถ๋ฆฌ๋ฅผ ํตํด ํ
์คํธ ์ฝ๋ ๋ด ํจ๊ณผ์ ์ธ ์ค๋ณต ์ ๊ฑฐ ๐ |
@@ -0,0 +1,120 @@
+package nextstep.subway.acceptance;
+
+import static nextstep.subway.acceptance.LineSteps.์งํ์ฒ _๋
ธ์ _์์ฑ_์์ฒญ;
+import static nextstep.subway.acceptance.LineSteps.์งํ์ฒ _๋
ธ์ ์_์งํ์ฒ _๊ตฌ๊ฐ_์์ฑ_์์ฒญ;
+import static nextstep.subway.acceptance.PathSteps.๊ฒฝ๋ก_์กฐํ_์์ฒญ;
+import static nextstep.subway.acceptance.StationSteps.์งํ์ฒ ์ญ_์์ฑ_์์ฒญ;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.restassured.response.ExtractableResponse;
+import io.restassured.response.Response;
+import java.util.HashMap;
+import java.util.Map;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import org.springframework.http.HttpStatus;
+
+@DisplayName("์งํ์ฒ ๊ฒฝ๋ก ๊ฒ์")
+public class PathAcceptanceTest extends AcceptanceTest {
+ private Long ๊ต๋์ญ;
+ private Long ๊ฐ๋จ์ญ;
+ private Long ์์ฌ์ญ;
+ private Long ๋จ๋ถํฐ๋ฏธ๋์ญ;
+ private Long ์ฒญ๋๋ฆฌ์ญ;
+ private Long ํ๊ธฐ์ญ;
+
+ private Long ์ผํธ์ ;
+ private Long ์ดํธ์ ;
+ private Long ์ ๋ถ๋น์ ;
+ private Long ์ผํธ์ ;
+
+ private int ๊ต๋์ญ_๊ฐ๋จ์ญ_๊ฑฐ๋ฆฌ = 10;
+ private int ๊ฐ๋จ์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ = 5;
+ private int ๊ต๋์ญ_๋จ๋ถํฐ๋ฏธ๋์ญ_๊ฑฐ๋ฆฌ = 2;
+ private int ๋จ๋ถํฐ๋ฏธ๋์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ = 3;
+ private int ์ฒญ๋๋ฆฌ์ญ_ํ๊ธฐ์ญ_๊ฑฐ๋ฆฌ = 7;
+
+ /** (10)
+ * ๊ต๋์ญ --- *2ํธ์ * --- ๊ฐ๋จ์ญ
+ * | |
+ * *3ํธ์ * (2) *์ ๋ถ๋น์ * (5)
+ * | |
+ * ๋จ๋ถํฐ๋ฏธ๋์ญ --- *3ํธ์ * --- ์์ฌ
+ (3) **/
+
+ @BeforeEach
+ public void setUp() {
+ super.setUp();
+
+ ๊ต๋์ญ = ์งํ์ฒ ์ญ_์์ฑ_์์ฒญ("๊ต๋์ญ").jsonPath().getLong("id");
+ ๊ฐ๋จ์ญ = ์งํ์ฒ ์ญ_์์ฑ_์์ฒญ("๊ฐ๋จ์ญ").jsonPath().getLong("id");
+ ์์ฌ์ญ = ์งํ์ฒ ์ญ_์์ฑ_์์ฒญ("์์ฌ์ญ").jsonPath().getLong("id");
+ ๋จ๋ถํฐ๋ฏธ๋์ญ = ์งํ์ฒ ์ญ_์์ฑ_์์ฒญ("๋จ๋ถํฐ๋ฏธ๋์ญ").jsonPath().getLong("id");
+ ์ฒญ๋๋ฆฌ์ญ = ์งํ์ฒ ์ญ_์์ฑ_์์ฒญ("์ฒญ๋๋ฆฌ์ญ").jsonPath().getLong("id");
+ ํ๊ธฐ์ญ = ์งํ์ฒ ์ญ_์์ฑ_์์ฒญ("ํ๊ธฐ์ญ").jsonPath().getLong("id");
+
+ ์ผํธ์ = ์งํ์ฒ _๋
ธ์ _์์ฑ_์์ฒญ("1ํธ์ ", "blue", ์ฒญ๋๋ฆฌ์ญ, ํ๊ธฐ์ญ, ์ฒญ๋๋ฆฌ์ญ_ํ๊ธฐ์ญ_๊ฑฐ๋ฆฌ).jsonPath().getLong("id");
+ ์ดํธ์ = ์งํ์ฒ _๋
ธ์ _์์ฑ_์์ฒญ("2ํธ์ ", "green", ๊ต๋์ญ, ๊ฐ๋จ์ญ, ๊ต๋์ญ_๊ฐ๋จ์ญ_๊ฑฐ๋ฆฌ).jsonPath().getLong("id");
+ ์ ๋ถ๋น์ = ์งํ์ฒ _๋
ธ์ _์์ฑ_์์ฒญ("์ ๋ถ๋น์ ", "red", ๊ฐ๋จ์ญ, ์์ฌ์ญ, ๊ฐ๋จ์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ).jsonPath().getLong("id");
+ ์ผํธ์ = ์งํ์ฒ _๋
ธ์ _์์ฑ_์์ฒญ("3ํธ์ ", "orange", ๊ต๋์ญ, ๋จ๋ถํฐ๋ฏธ๋์ญ, ๊ต๋์ญ_๋จ๋ถํฐ๋ฏธ๋์ญ_๊ฑฐ๋ฆฌ).jsonPath().getLong("id");
+
+ ์งํ์ฒ _๋
ธ์ ์_์งํ์ฒ _๊ตฌ๊ฐ_์์ฑ_์์ฒญ(์ผํธ์ , createSectionCreateParams(๋จ๋ถํฐ๋ฏธ๋์ญ, ์์ฌ์ญ, ๋จ๋ถํฐ๋ฏธ๋์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ));
+ }
+
+ /**
+ * Given ์งํ์ฒ ๋
ธ์ (2ํธ์ , 3ํธ์ , ์ ๋ถ๋น์ ) ์ ์์ฑํ๊ณ ์ญ, ๊ตฌ๊ฐ์ ์์ฑํ๋ค.
+ * When ์๋ก ๋ค๋ฅธ ๋ ์ญ์ ์ต๋จ ๊ฑฐ๋ฆฌ๋ฅผ ์กฐํํ๋ฉด
+ * Then ์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํ์ ์ฑ๊ณตํ๋ค.
+ */
+ @DisplayName("์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํํ๊ธฐ")
+ @Test
+ void searchShortestPath() {
+ // when
+ ExtractableResponse<Response> response = ๊ฒฝ๋ก_์กฐํ_์์ฒญ(๋จ๋ถํฐ๋ฏธ๋์ญ, ๊ฐ๋จ์ญ);
+
+ // then
+ assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
+ assertThat(response.jsonPath().getList("stations.id", Long.class)).containsExactly(๋จ๋ถํฐ๋ฏธ๋์ญ, ์์ฌ์ญ, ๊ฐ๋จ์ญ);
+ assertThat(response.jsonPath().getInt("distance")).isEqualTo(๋จ๋ถํฐ๋ฏธ๋์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ + ๊ฐ๋จ์ญ_์์ฌ์ญ_๊ฑฐ๋ฆฌ);
+ }
+
+ /**
+ * Given ์งํ์ฒ ๋
ธ์ (2ํธ์ , 3ํธ์ , ์ ๋ถ๋น์ ) ์ ์์ฑํ๊ณ ์ญ, ๊ตฌ๊ฐ์ ์์ฑํ๋ค.
+ * ๊ธฐ์กด ๋
ธ์ ๊ณผ ์ฐ๊ฒฐ๋์ง ์๋ ์๋ก์ด ๋
ธ์ (1ํธ์ )์ ์์ฑํ๋ค.
+ * When ์ฐ๊ฒฐ ๋์ง ์์ ๋ ์ญ์ ์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํ๋ฅผ ์์ฒญ ํ๋ฉด
+ * Then ์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํ์ ์คํจํ๋ค.
+ */
+ @DisplayName("์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํํ๊ธฐ - ์ฐ๊ฒฐ๋์ง ์์ ์ญ์ ์กฐํ ํ ๊ฒฝ์ฐ")
+ @Test
+ void searchShortestPathDoesNotExistPath() {
+ // when
+ ExtractableResponse<Response> response = ๊ฒฝ๋ก_์กฐํ_์์ฒญ(๊ฐ๋จ์ญ, ์ฒญ๋๋ฆฌ์ญ);
+
+ // then
+ assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());;
+ }
+
+ /**
+ * Given ์งํ์ฒ ๋
ธ์ (2ํธ์ , 3ํธ์ , ์ ๋ถ๋น์ ) ์ ์์ฑํ๊ณ ์ญ, ๊ตฌ๊ฐ์ ์์ฑํ๋ค.
+ * When ์ถ๋ฐ์ญ๊ณผ ๋์ฐฉ์ญ์ด ๋์ผํ๋ฐ ์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํ๋ฅผ ์์ฒญํ๋ฉด
+ * Then ์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํ์ ์คํจํ๋ค.
+ */
+ @DisplayName("์ต๋จ ๊ฑฐ๋ฆฌ ์กฐํํ๊ธฐ - ์ถ๋ฐ์ญ๊ณผ ๋์ฐฉ์ญ์ด ๋์ผํ ๊ฒฝ์ฐ")
+ @Test
+ void searchShortestPathSourceEqualsTarget() {
+ // when
+ ExtractableResponse<Response> response = ๊ฒฝ๋ก_์กฐํ_์์ฒญ(๊ฐ๋จ์ญ, ๊ฐ๋จ์ญ);
+
+ // then
+ assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());;
+ }
+
+ private Map<String, String> createSectionCreateParams(Long upStationId, Long downStationId, int distance) {
+ Map<String, String> params = new HashMap<>();
+ params.put("upStationId", upStationId + "");
+ params.put("downStationId", downStationId + "");
+ params.put("distance", distance + "");
+ return params;
+ }
+} | Java | ๋จ์ ํ
์คํธ์ ํฝ์ค์ณ ๊ด๋ฆฌ ๋ฐฉ๋ฒ์ฒ๋ผ ํด๋น ๊ฐ์ฒด๋ค์ ์ฌ์ฌ์ฉ์ด ํ์ํ ๊ฒฝ์ฐ ์ธ์ ํ
์คํธ์ฉ ํฝ์ค์ณ๋ฅผ ๋ง๋ค์ด์ ๊ด๋ฆฌํ ์ ๋ ์๊ฒ ๋ค์! |
@@ -0,0 +1,87 @@
+const express = require('express')
+const http = require('http');
+const path = require('path');
+
+const bodyParser = require('body-parser');
+const static = require('serve-static');
+const multer = require("multer")
+
+const app = express();
+
+app.set('port', process.env.PORT || 3000);
+
+app.use(bodyParser.urlencoded({ extended: false }))
+app.use(bodyParser.json())
+
+app.use('/public', static(path.join(__dirname, 'public')));
+app.use('/uploads', static(path.join(__dirname, 'uploads')))
+
+const upload = multer({
+ storage: multer.diskStorage({
+ destination: function (req, file, cb) {
+ cb(null, './uploads/');
+ },
+ filename: function (req, file, cb) {
+ cb(null, file.originalname);
+ }
+ }),
+}).single('userfile');
+
+app.post("/save", function (req, res) {
+ try {
+ upload(req, res, function (err) {
+ var name = req.body.name;
+ var date = req.body.date;
+ var content = req.body.content;
+ var filename = req.file.filename;
+ console.log(filename);
+ res.writeHead(200, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write(`
+ <head>
+ <meta charset="UTF-8">
+ <link rel="stylesheet" href="/public/stylesheet/momo.css">
+ <title>Document</title>
+ </head>
+ <form method="GET" action="/" id="re-form">
+ <table class="header-table">
+ <thead>
+ <th class="table-head">๋์ ๋ฉ๋ชจ</th>
+ </thead>
+ <tbody class="table-body">
+ <tr>
+ <td>${name},${date},${content}๋ฉ๋ชจ๊ฐ ์ ์ฅ๋์์ต๋๋ค.</td>
+ </tr>
+ <tr>
+ <td colspan="2" class="upload-display">
+ <div class="upload-thumb-wrap"><img class="upload-thumb" src="/uploads/${filename}"></div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <table class="footer-table">
+ <tbody>
+ <tr><td id="re-layor"><button id="redirect" form = "re-form" type="submit" >๋ค์์์ฑ</button></td></tr>
+ </tbody>
+ </table>
+ </form>
+ `);
+ res.end();
+ });
+
+ } catch (err) {
+ console.dir(err.stack);
+
+ res.writeHead(400, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write('<div><p>๋ฉ๋ชจ ์ ์ฅ ์ ์๋ฌ ๋ฐ์</p></div>');
+ res.end();
+ }
+
+});
+
+app.get('/', function (req, res) {
+ res.sendFile(__dirname + "/view/memo/memo.html");
+});
+
+http.createServer(app).listen(app.get('port'), function () {
+ console.log("์๋ฒ์์");
+});
\ No newline at end of file | JavaScript | String์ด ์๋ html์ด๋ ejs ํ์ผ๋ก ๋ณด๋ด๋ ๊ฒ์ด ์ข์ต๋๋ค. (Feat. ์ฟ ๋ง์จฉ)
save.ejs๋ก ๋ถ๋ฆฌํด ์ฃผ์ธ์. |
@@ -0,0 +1,87 @@
+const express = require('express')
+const http = require('http');
+const path = require('path');
+
+const bodyParser = require('body-parser');
+const static = require('serve-static');
+const multer = require("multer")
+
+const app = express();
+
+app.set('port', process.env.PORT || 3000);
+
+app.use(bodyParser.urlencoded({ extended: false }))
+app.use(bodyParser.json())
+
+app.use('/public', static(path.join(__dirname, 'public')));
+app.use('/uploads', static(path.join(__dirname, 'uploads')))
+
+const upload = multer({
+ storage: multer.diskStorage({
+ destination: function (req, file, cb) {
+ cb(null, './uploads/');
+ },
+ filename: function (req, file, cb) {
+ cb(null, file.originalname);
+ }
+ }),
+}).single('userfile');
+
+app.post("/save", function (req, res) {
+ try {
+ upload(req, res, function (err) {
+ var name = req.body.name;
+ var date = req.body.date;
+ var content = req.body.content;
+ var filename = req.file.filename;
+ console.log(filename);
+ res.writeHead(200, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write(`
+ <head>
+ <meta charset="UTF-8">
+ <link rel="stylesheet" href="/public/stylesheet/momo.css">
+ <title>Document</title>
+ </head>
+ <form method="GET" action="/" id="re-form">
+ <table class="header-table">
+ <thead>
+ <th class="table-head">๋์ ๋ฉ๋ชจ</th>
+ </thead>
+ <tbody class="table-body">
+ <tr>
+ <td>${name},${date},${content}๋ฉ๋ชจ๊ฐ ์ ์ฅ๋์์ต๋๋ค.</td>
+ </tr>
+ <tr>
+ <td colspan="2" class="upload-display">
+ <div class="upload-thumb-wrap"><img class="upload-thumb" src="/uploads/${filename}"></div>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <table class="footer-table">
+ <tbody>
+ <tr><td id="re-layor"><button id="redirect" form = "re-form" type="submit" >๋ค์์์ฑ</button></td></tr>
+ </tbody>
+ </table>
+ </form>
+ `);
+ res.end();
+ });
+
+ } catch (err) {
+ console.dir(err.stack);
+
+ res.writeHead(400, { 'Content-Type': 'text/html;charset=utf8' });
+ res.write('<div><p>๋ฉ๋ชจ ์ ์ฅ ์ ์๋ฌ ๋ฐ์</p></div>');
+ res.end();
+ }
+
+});
+
+app.get('/', function (req, res) {
+ res.sendFile(__dirname + "/view/memo/memo.html");
+});
+
+http.createServer(app).listen(app.get('port'), function () {
+ console.log("์๋ฒ์์");
+});
\ No newline at end of file | JavaScript | ๋น ์ค๊ณผ ๋ค์ฌ์ฐ๊ธฐ ์ ๋ฆฌํด ์ฃผ์ธ์. |
@@ -1,7 +1,10 @@
package christmas;
+import christmas.controller.MainController;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ MainController mainController = new MainController();
+ mainController.run();
}
} | Java | ๊ฐ์ฒด๋ฅผ ์์ฑํ ๋ new ์์ฝ์ด๋ณด๋ค ์ ์ ํฉํ ๋ฆฌ ๋ฉ์๋๋ฅผ ์ฌ์ฉํด๋ณด์๋ฉด ์ด๋จ๊น์. ๊ฐ๋
์ฑ์ด๋ ๊ฐ์ฒด ์์ฑ ์ ์ ํ ๊ฐ์ ์ฌ๋ฌ ๊ฐ์ง ์ด์ ์ด ์์ด์.
https://tecoble.techcourse.co.kr/post/2020-05-26-static-factory-method/ |
@@ -0,0 +1,47 @@
+package christmas.controller;
+
+import java.util.Map;
+
+import christmas.view.*;
+import christmas.model.*;
+
+public class MainController {
+ private OrderMenu orderMenu;
+
+ public MainController() {
+ orderMenu = new OrderMenu();
+ }
+
+ public void run() {
+ orderMenu.setOrderDate(InputView.readDate());
+ setReadOrder();
+
+ OutputView.printPreview(orderMenu.getOrderDate());
+ OutputView.printOrder(orderMenu.getUserOrder());
+ int totalPrice = orderMenu.getTotalPrice();
+ OutputView.printTotalPrice(totalPrice);
+ OutputView.printPresent(totalPrice);
+ benefitControl(totalPrice);
+ }
+
+ private void benefitControl(int totalPrice) {
+ Benefit benefit = new Benefit(orderMenu.getOrderDate(), orderMenu.getCategoryCount(), totalPrice);
+ OutputView.printBenefits(benefit.getBenefits());
+
+ int totalBenefitPrice = benefit.getTotalBenefitPrice();
+ OutputView.printTotalBenefitPrice(totalBenefitPrice);
+ OutputView.printTotalPayment(totalPrice - totalBenefitPrice + benefit.getPresentPrice());
+ OutputView.printEventBadge(totalBenefitPrice);
+ }
+
+ private void setReadOrder() {
+ Map<String, Integer> orderMenu;
+ try {
+ orderMenu = InputView.readOrder();
+ this.orderMenu.setUserOrder(orderMenu);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ setReadOrder();
+ }
+ }
+} | Java | OutputView๋ InputView์ ์
์ถ๋ ฅ ๊ธฐ๋ฅ๋ค์ ๋ชจ๋ ์คํํฑ ๋ฉ์๋๋ก ๊ตฌํํ์
จ๋ค์. ๋ณดํต์ ํด๋น ๊ฐ์ฒด๋ฅผ ์์ฑ ํ์ ์ผ๋ฐ ๋ฉ์๋๋ฅผ ํธ์ถํ๋๋ฐ ์คํํฑ ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ ์ด์ ๊ฐ ์์ผ์ค๊น์? |
@@ -0,0 +1,97 @@
+package christmas.util;
+
+import java.util.Map;
+import java.util.List;
+
+public class Validator {
+ private final static char MIN_DIGIT = '0';
+ private final static char MAX_DIGIT = '9';
+ private final static char CHAR_HYPHEN = '-';
+ private final static char CHAR_COMMA = ',';
+ private final static int MIN_DAY = 1;
+ private final static int MAX_DAY = 31;
+ private final static int IS_TWO = 2;
+
+ public static void validateDate(String input) {
+ if (input.isEmpty()) {
+ throw new IllegalArgumentException(ErrorMessage.DATE_ERROR.get());
+ }
+ for (int i = Constant.ZERO.get(); i < input.length(); ++i) {
+ if (input.charAt(i) < MIN_DIGIT || input.charAt(i) > MAX_DIGIT) {
+ throw new IllegalArgumentException(ErrorMessage.DATE_ERROR.get());
+ }
+ }
+ int date = Integer.parseInt(input);
+ if (date < MIN_DAY || date > MAX_DAY) {
+ throw new IllegalArgumentException(ErrorMessage.DATE_ERROR.get());
+ }
+ }
+
+ public static void validateOrder(String input) {
+ // splitํ ๊ฒฝ์ฐ ๋ง์ง๋ง์ ๋น ๋ฌธ์์ด์ ์ฌ๋ผ์ง๋ฏ๋ก ๋ณ๋๋ก ์์ธ ์ฒ๋ฆฌ
+ if (input.isEmpty() || input.charAt(input.length() - Constant.ONE.get()) == CHAR_COMMA) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ String[] splittedComma = input.split(Message.COMMA.get());
+ if (splittedComma.length == Constant.ZERO.get()) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ for (String string : splittedComma) {
+ if (validateFormat(string)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ }
+ }
+
+ public static boolean validateMenu(Map<String, Integer> userOrder, List<Map<String, Integer>> menu) {
+ int[] countCategory = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : userOrder.entrySet()) {
+ if (entry.getValue() <= Constant.ZERO.get()) {
+ return true;
+ }
+ int category = Utility.getCategory(entry.getKey(), menu);
+ if (category == Constant.NOT_IN_MENU.get()) {
+ return true;
+ }
+ countCategory[category] += entry.getValue();
+ }
+ if (validateCount(countCategory)) {
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean validateCount(int[] countCategory) {
+ // ์๋ฃ๋ง ์ํจ ๊ฒฝ์ฐ ์์ธ ์ฒ๋ฆฌ
+ if (countCategory[Constant.EPPETIZER.get()] == Constant.ZERO.get()
+ && countCategory[Constant.MAINMENU.get()] == Constant.ZERO.get()
+ && countCategory[Constant.DESSERT.get()] == Constant.ZERO.get()) {
+ return true;
+ }
+ int totalCount = Constant.ZERO.get();
+ for (int count : countCategory) {
+ totalCount += count;
+ }
+ if (totalCount > Constant.MAX_MENU_COUNT.get()) {
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean validateFormat(String input) {
+ if (input.isEmpty() || input.charAt(input.length() - Constant.ONE.get()) == CHAR_HYPHEN) {
+ return true;
+ }
+ String[] splittedHyphen = input.split(Message.HYPHEN.get());
+ if (splittedHyphen.length != IS_TWO) {
+ return true;
+ }
+ for (int i = Constant.ZERO.get(); i < splittedHyphen[Constant.VALUE_INDEX.get()].length(); ++i) {
+ if (splittedHyphen[Constant.VALUE_INDEX.get()].charAt(i) < MIN_DIGIT
+ || splittedHyphen[Constant.VALUE_INDEX.get()].charAt(i) > MAX_DIGIT) {
+ return true;
+ }
+ }
+ return false;
+ }
+} | Java | ์ ๋ ์ฑ๊ธฐ์ง ๋ชปํ ๋ถ๋ถ์ด๊ธดํฉ๋๋ค๋ง ํด๋น ๋ด์ฉ ๊ณต์ ํด๋๋ฆฌ์๋ฉด,
'์๋ฃ๋ง ์ฃผ๋ฌธ'๊ณผ ๊ฐ์ ์์ธ์ฒ๋ฆฌ๋ ๋ฌธ์์ด ํ์ฑ ์์ธ๊ฐ ์๋ ๋น์ฆ๋์ค ๋ก์ง ์์ธ์ฒ๋ฆฌ์ด๋ฏ๋ก
๊ฐ์ฒด์์ฑ์์ ์์ธ ์ฒ๋ฆฌ๋ฅผ ํด์ฃผ๋ฉด ์ญํ ๋ถ๋ฆฌ ์์น์ ํจ์ฌ ๋ ์ข์ ์ฝ๋๊ฐ ๋ ๊ฒ ๊ฐ์ต๋๋ค~! |
@@ -1,7 +1,10 @@
package christmas;
+import christmas.controller.MainController;
+
public class Application {
public static void main(String[] args) {
- // TODO: ํ๋ก๊ทธ๋จ ๊ตฌํ
+ MainController mainController = new MainController();
+ mainController.run();
}
} | Java | ์๊ฐํ์ง ๋ชปํ๋ ๊ฐ๋
์ธ๋ฐ ๊ฐ์ฌํฉ๋๋ค! ๋ฆฌํฉํ ๋งํ ๋ ์ ์ฉํ๋ฉด ์ข์ ๊ฒ ๊ฐ๋ค์ |
@@ -0,0 +1,39 @@
+package christmas.util;
+
+public enum Constant {
+ NOT_IN_MENU(-1),
+ EPPETIZER(0),
+ MAINMENU(1),
+ DESSERT(2),
+ BEVERAGE(3),
+ CATEGORY_COUNT(4),
+ ZERO(0),
+ ONE(1),
+ THOUSAND(1000),
+ HUNDRED(100),
+ CHRISTMAS_DAY(25),
+ MIN_BENEFIT_PRICE(10000),
+ PRESENT_COST(120000),
+ CHAMPAIGN_PRICE(25000),
+ WEEKDAYS(7),
+ FRIDAY(1),
+ SATURDAY(2),
+ SUNDAY(3),
+ EVENT_PRICE(2023),
+ SANTA(20000),
+ TREE(10000),
+ STAR(5000),
+ MAX_MENU_COUNT(20),
+ KEY_INDEX(0),
+ VALUE_INDEX(1);
+
+ private final int value;
+
+ Constant(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return this.value;
+ }
+} | Java | Enum์ ๋ฉ๋ด์ ๋ณด ์ ์ฅํ๋ ์๋ฃ๊ตฌ์กฐ๋ก ์ฌ์ฉํ๋ฉด ์ฉ์ฒ๊ฐ ์ ๋ง์ ๊ฒ ๊ฐ์ต๋๋ค.
๋ฉ๋ด์ ํด๋นํ๋ ํ๊ธ์ด๋ฆ(String)๊ณผ ๊ฐ๊ฒฉ(Integer)๊ฐ ์กด์ฌํ๊ธฐ ๋๋ฌธ์ด์ง์. |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | Map.of๋ก ์ด๊ธฐํํ๋ ํธํด๋ณด์ด๋ค์! ๋ฐฐ์ ์ต๋๋ค! ์ด๋๊ฐ์ ์จ๋จน์ด ๋ด์ผ๊ฒ ์ด์! |
@@ -0,0 +1,47 @@
+package christmas.controller;
+
+import java.util.Map;
+
+import christmas.view.*;
+import christmas.model.*;
+
+public class MainController {
+ private OrderMenu orderMenu;
+
+ public MainController() {
+ orderMenu = new OrderMenu();
+ }
+
+ public void run() {
+ orderMenu.setOrderDate(InputView.readDate());
+ setReadOrder();
+
+ OutputView.printPreview(orderMenu.getOrderDate());
+ OutputView.printOrder(orderMenu.getUserOrder());
+ int totalPrice = orderMenu.getTotalPrice();
+ OutputView.printTotalPrice(totalPrice);
+ OutputView.printPresent(totalPrice);
+ benefitControl(totalPrice);
+ }
+
+ private void benefitControl(int totalPrice) {
+ Benefit benefit = new Benefit(orderMenu.getOrderDate(), orderMenu.getCategoryCount(), totalPrice);
+ OutputView.printBenefits(benefit.getBenefits());
+
+ int totalBenefitPrice = benefit.getTotalBenefitPrice();
+ OutputView.printTotalBenefitPrice(totalBenefitPrice);
+ OutputView.printTotalPayment(totalPrice - totalBenefitPrice + benefit.getPresentPrice());
+ OutputView.printEventBadge(totalBenefitPrice);
+ }
+
+ private void setReadOrder() {
+ Map<String, Integer> orderMenu;
+ try {
+ orderMenu = InputView.readOrder();
+ this.orderMenu.setUserOrder(orderMenu);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ setReadOrder();
+ }
+ }
+} | Java | MainController๊ฐ ํฌ๊ฒ ์ปจํธ๋กค(๊ฐ์ฒด๋ด ๋ฐ์ดํฐ๋ฅผ ์์ ๋ฐ ์ ์ฅ)ํ๋ ๋ชจ๋ธ์ orderMenu์ธ ๊ฒ ๊ฐ์๋ณด์
๋๋ค. ์ฆ ํด๋์ค ์ด๋ฆ์ด orderController์ด๋ฉด Model๊ณผ Controller๊ฐ์ ์ญํ ์์กด์ฑ์ ๋ ๋ง๋ ์๋ช
์ผ ๊ฒ ๊ฐ์ต๋๋ค |
@@ -0,0 +1,79 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.Message;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Benefit {
+ private int orderDate;
+ private int[] categoryCount;
+ Map<String, Integer> benefits;
+
+ public Benefit(int orderDate, int[] categoryCount, int totalPrice) {
+ this.orderDate = orderDate;
+ this.categoryCount = categoryCount;
+ benefits = new HashMap<>();
+ if (totalPrice < Constant.MIN_BENEFIT_PRICE.get()) {
+ return;
+ }
+ christmasBenefit();
+ weekBenefit();
+ starBenefit();
+ if (totalPrice >= Constant.PRESENT_COST.get()) {
+ presentBenefit();
+ }
+ }
+
+ public Map<String, Integer> getBenefits() {
+ return this.benefits;
+ }
+
+ public int getTotalBenefitPrice() {
+ int totalBenefitPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.benefits.entrySet()) {
+ int benefit = entry.getValue();
+ totalBenefitPrice += benefit;
+ }
+ return totalBenefitPrice;
+ }
+
+ public int getPresentPrice() {
+ if (this.benefits.containsKey(Message.PRESENT_BENEFIT.get())) {
+ return Constant.CHAMPAIGN_PRICE.get();
+ }
+ return Constant.ZERO.get();
+ }
+
+ private void christmasBenefit() {
+ if (orderDate > Constant.CHRISTMAS_DAY.get()) {
+ return;
+ }
+ int benefit = Constant.THOUSAND.get() + (orderDate - Constant.ONE.get()) * Constant.HUNDRED.get();
+ benefits.put(Message.D_DAY_BENEFIT.get(), benefit);
+ }
+
+ private void weekBenefit() {
+ if (orderDate % Constant.WEEKDAYS.get() == Constant.FRIDAY.get()
+ || orderDate % Constant.WEEKDAYS.get() == Constant.SATURDAY.get()) {
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.MAINMENU.get()];
+ benefits.put(Message.WEEKEND_BENEFIT.get(), benefit);
+ return;
+ }
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.DESSERT.get()];
+ benefits.put(Message.WEEKDAY_BENEFIT.get(), benefit);
+ }
+
+ private void starBenefit() {
+ if (orderDate != Constant.CHRISTMAS_DAY.get()
+ && orderDate % Constant.WEEKDAYS.get() != Constant.SUNDAY.get()) {
+ return;
+ }
+ benefits.put(Message.STAR_BENEFIT.get(), Constant.THOUSAND.get());
+ }
+
+ private void presentBenefit() {
+ benefits.put(Message.PRESENT_BENEFIT.get(), Constant.CHAMPAIGN_PRICE.get());
+ }
+} | Java | ์ ์ฒด์ ์ผ๋ก ํจ์๋ถ๋ฆฌ๊ฐ ์ ๋ผ์์ด์ ํจ์๋น ๋ผ์ธ์ด ์งง์ ํธ์ด๋ค์! ๊ต์ฅํ ๊ฐ๋
์ฑ ์ข์ ์ฝ๋๊ฐ ๋ ๊ฒ ๊ฐ์ต๋๋ค! |
@@ -0,0 +1,39 @@
+package christmas.util;
+
+public enum Constant {
+ NOT_IN_MENU(-1),
+ EPPETIZER(0),
+ MAINMENU(1),
+ DESSERT(2),
+ BEVERAGE(3),
+ CATEGORY_COUNT(4),
+ ZERO(0),
+ ONE(1),
+ THOUSAND(1000),
+ HUNDRED(100),
+ CHRISTMAS_DAY(25),
+ MIN_BENEFIT_PRICE(10000),
+ PRESENT_COST(120000),
+ CHAMPAIGN_PRICE(25000),
+ WEEKDAYS(7),
+ FRIDAY(1),
+ SATURDAY(2),
+ SUNDAY(3),
+ EVENT_PRICE(2023),
+ SANTA(20000),
+ TREE(10000),
+ STAR(5000),
+ MAX_MENU_COUNT(20),
+ KEY_INDEX(0),
+ VALUE_INDEX(1);
+
+ private final int value;
+
+ Constant(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return this.value;
+ }
+} | Java | ์์๋ค์ enum์ผ๋ก ๊ด๋ฆฌํ์๋ ๊ฒ์ ์ข์ ํฌ์ธํธ์ธ ๊ฒ ๊ฐ์ต๋๋ค. ํ์ง๋ง constant์ ๋ชจ๋ ์์๋ฅผ ๋ค ๋ฃ์ด๋ฒ๋ฆฌ์๋ฉด ๊ฐ๋ณ ์์๋ฅผ ์์ ํ๊ฑฐ๋ ๋ณ๊ฒฝํด์ผ ํ ๋ ์ฐพ๊ธฐ ์ด๋ ค์์ง ๊ฒ ๊ฐ์์. enum์ ์ข
๋ฅ๋ณ๋ก, ๋ฌธ๋งฅ๋ณ๋ก ๋ถ๋ฆฌํ์๋ ๊ฒ์ ์ถ์ฒ ๋๋ ค์. |
@@ -0,0 +1,79 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.Message;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Benefit {
+ private int orderDate;
+ private int[] categoryCount;
+ Map<String, Integer> benefits;
+
+ public Benefit(int orderDate, int[] categoryCount, int totalPrice) {
+ this.orderDate = orderDate;
+ this.categoryCount = categoryCount;
+ benefits = new HashMap<>();
+ if (totalPrice < Constant.MIN_BENEFIT_PRICE.get()) {
+ return;
+ }
+ christmasBenefit();
+ weekBenefit();
+ starBenefit();
+ if (totalPrice >= Constant.PRESENT_COST.get()) {
+ presentBenefit();
+ }
+ }
+
+ public Map<String, Integer> getBenefits() {
+ return this.benefits;
+ }
+
+ public int getTotalBenefitPrice() {
+ int totalBenefitPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.benefits.entrySet()) {
+ int benefit = entry.getValue();
+ totalBenefitPrice += benefit;
+ }
+ return totalBenefitPrice;
+ }
+
+ public int getPresentPrice() {
+ if (this.benefits.containsKey(Message.PRESENT_BENEFIT.get())) {
+ return Constant.CHAMPAIGN_PRICE.get();
+ }
+ return Constant.ZERO.get();
+ }
+
+ private void christmasBenefit() {
+ if (orderDate > Constant.CHRISTMAS_DAY.get()) {
+ return;
+ }
+ int benefit = Constant.THOUSAND.get() + (orderDate - Constant.ONE.get()) * Constant.HUNDRED.get();
+ benefits.put(Message.D_DAY_BENEFIT.get(), benefit);
+ }
+
+ private void weekBenefit() {
+ if (orderDate % Constant.WEEKDAYS.get() == Constant.FRIDAY.get()
+ || orderDate % Constant.WEEKDAYS.get() == Constant.SATURDAY.get()) {
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.MAINMENU.get()];
+ benefits.put(Message.WEEKEND_BENEFIT.get(), benefit);
+ return;
+ }
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.DESSERT.get()];
+ benefits.put(Message.WEEKDAY_BENEFIT.get(), benefit);
+ }
+
+ private void starBenefit() {
+ if (orderDate != Constant.CHRISTMAS_DAY.get()
+ && orderDate % Constant.WEEKDAYS.get() != Constant.SUNDAY.get()) {
+ return;
+ }
+ benefits.put(Message.STAR_BENEFIT.get(), Constant.THOUSAND.get());
+ }
+
+ private void presentBenefit() {
+ benefits.put(Message.PRESENT_BENEFIT.get(), Constant.CHAMPAIGN_PRICE.get());
+ }
+} | Java | ์ค์ ์ ํ๋ฆฌ์ผ์ด์
์์ ๋ฐฐ์ด ๋ณด๋ค๋ ๋ฆฌ์คํธ๋, ๋งต, ์
๋ฑ ์ปฌ๋ ์
๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ๋ค๊ณ ํด์. ๊ทธ ์ด์ ๋ ์ง๋ ์ฃผ์ฐจ ํผ๋๋ฐฑ์ ๋ณด๋ฉด ๋ฐฐ์ด๋ณด๋ค ์ข ๋ ํธ๋ฆฌํ ์ฌ๋ฌ API๋ค์ ์ ๊ณตํ๊ธฐ ๋๋ฌธ์ธ๋ฐ์. ์ด์ธ์๋ ์ปฌ๋ ์
์ด ์ ํธ๋๋ ์ด์ ๋ ์ดํํฐ๋ธ ์๋ฐ ๋ฑ์์๋ ์ธ๊ธ๋์ด ์์ต๋๋ค.
https://incheol-jung.gitbook.io/docs/study/effective-java/undefined-3/2020-03-20-effective-28item |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ๋ฉ๋ด ์ด๋ฆ๊ณผ ๊ฐ๊ฒฉ์ ๊ฒฝ์ฐ ํ๋ ์ฝ๋ฉํ๊ธฐ๋ณด๋ค enum ๋ฑ์ผ๋ก ๋ถ๋ฆฌํ์ฌ ๊ด๋ฆฌํ๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,97 @@
+package christmas.util;
+
+import java.util.Map;
+import java.util.List;
+
+public class Validator {
+ private final static char MIN_DIGIT = '0';
+ private final static char MAX_DIGIT = '9';
+ private final static char CHAR_HYPHEN = '-';
+ private final static char CHAR_COMMA = ',';
+ private final static int MIN_DAY = 1;
+ private final static int MAX_DAY = 31;
+ private final static int IS_TWO = 2;
+
+ public static void validateDate(String input) {
+ if (input.isEmpty()) {
+ throw new IllegalArgumentException(ErrorMessage.DATE_ERROR.get());
+ }
+ for (int i = Constant.ZERO.get(); i < input.length(); ++i) {
+ if (input.charAt(i) < MIN_DIGIT || input.charAt(i) > MAX_DIGIT) {
+ throw new IllegalArgumentException(ErrorMessage.DATE_ERROR.get());
+ }
+ }
+ int date = Integer.parseInt(input);
+ if (date < MIN_DAY || date > MAX_DAY) {
+ throw new IllegalArgumentException(ErrorMessage.DATE_ERROR.get());
+ }
+ }
+
+ public static void validateOrder(String input) {
+ // splitํ ๊ฒฝ์ฐ ๋ง์ง๋ง์ ๋น ๋ฌธ์์ด์ ์ฌ๋ผ์ง๋ฏ๋ก ๋ณ๋๋ก ์์ธ ์ฒ๋ฆฌ
+ if (input.isEmpty() || input.charAt(input.length() - Constant.ONE.get()) == CHAR_COMMA) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ String[] splittedComma = input.split(Message.COMMA.get());
+ if (splittedComma.length == Constant.ZERO.get()) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ for (String string : splittedComma) {
+ if (validateFormat(string)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ }
+ }
+
+ public static boolean validateMenu(Map<String, Integer> userOrder, List<Map<String, Integer>> menu) {
+ int[] countCategory = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : userOrder.entrySet()) {
+ if (entry.getValue() <= Constant.ZERO.get()) {
+ return true;
+ }
+ int category = Utility.getCategory(entry.getKey(), menu);
+ if (category == Constant.NOT_IN_MENU.get()) {
+ return true;
+ }
+ countCategory[category] += entry.getValue();
+ }
+ if (validateCount(countCategory)) {
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean validateCount(int[] countCategory) {
+ // ์๋ฃ๋ง ์ํจ ๊ฒฝ์ฐ ์์ธ ์ฒ๋ฆฌ
+ if (countCategory[Constant.EPPETIZER.get()] == Constant.ZERO.get()
+ && countCategory[Constant.MAINMENU.get()] == Constant.ZERO.get()
+ && countCategory[Constant.DESSERT.get()] == Constant.ZERO.get()) {
+ return true;
+ }
+ int totalCount = Constant.ZERO.get();
+ for (int count : countCategory) {
+ totalCount += count;
+ }
+ if (totalCount > Constant.MAX_MENU_COUNT.get()) {
+ return true;
+ }
+ return false;
+ }
+
+ private static boolean validateFormat(String input) {
+ if (input.isEmpty() || input.charAt(input.length() - Constant.ONE.get()) == CHAR_HYPHEN) {
+ return true;
+ }
+ String[] splittedHyphen = input.split(Message.HYPHEN.get());
+ if (splittedHyphen.length != IS_TWO) {
+ return true;
+ }
+ for (int i = Constant.ZERO.get(); i < splittedHyphen[Constant.VALUE_INDEX.get()].length(); ++i) {
+ if (splittedHyphen[Constant.VALUE_INDEX.get()].charAt(i) < MIN_DIGIT
+ || splittedHyphen[Constant.VALUE_INDEX.get()].charAt(i) > MAX_DIGIT) {
+ return true;
+ }
+ }
+ return false;
+ }
+} | Java | ์ด๋ ๊ฒ ์ ํจ์ฑ ๊ฒ์ฌ ๋ก์ง์ ํ ๊ตฐ๋ฐ์์ ๊ด๋ฆฌํ๋ ๊ฒ๋ ์ข์ ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ์ต๋๋ค. ๊ฐ์ธ์ ์ธ ์๊ฐ์ด์ง๋ง ๋๋ฉ์ธ์์ ์ ํจ์ฑ ๊ฒ์ฌํ๊ฒ ๋๋ฉด ์ ํจ์ฑ ๊ฒ์ฌ ๋ก์ง๋ค์ด ํฉ์ด์ง๋ ๊ฒฝํฅ์ด ์์ด์ ๋ก์ง์ ๋ฐ๋ผ๊ฐ๊ธฐ ์ด๋ ค์ด๋ฐ ์ด๋ ๊ฒ ๋ชจ์๋๋ฉด ์ ํจ์ฑ ๊ฒ์ฌ ๋ฉ์๋๋ค๋ง ํ๋์ ๋ณผ ์ ์์ด์ ์ข์ ๊ฒ ๊ฐ์์. |
@@ -0,0 +1,96 @@
+package christmas.view;
+
+import christmas.util.Constant;
+import christmas.util.Message;
+import java.util.Map;
+
+import java.text.DecimalFormat;
+
+public class OutputView {
+ public static void printPreview(int orderDate) {
+ System.out.println("12์ " + orderDate + "์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!");
+ System.out.println();
+ }
+
+ public static void printOrder(Map<String, Integer> userOrder) {
+ System.out.println("<์ฃผ๋ฌธ ๋ฉ๋ด>");
+ for (Map.Entry<String, Integer> entry : userOrder.entrySet()) {
+ System.out.println(entry.getKey() + Message.SPACE.get() + entry.getValue() + Message.COUNT.get());
+ }
+ System.out.println();
+ }
+
+ public static void printTotalPrice(int totalPrice) {
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+
+ System.out.println("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>");
+ String formattedNumber = decimalFormat.format(totalPrice);
+ System.out.println(formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printPresent(int totalPrice) {
+ System.out.println("<์ฆ์ ๋ฉ๋ด>");
+ if (totalPrice < Constant.PRESENT_COST.get()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ System.out.println(Message.ONE_CHAMPAIGN.get());
+ System.out.println();
+ }
+
+ public static void printBenefits(Map<String, Integer> benefits) {
+ System.out.println("<ํํ ๋ด์ญ>");
+ if (benefits.isEmpty()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ for (Map.Entry<String, Integer> entry : benefits.entrySet()) {
+ System.out.print(entry.getKey() + ": -");
+ String fomattedNumber = decimalFormat.format(entry.getValue());
+ System.out.println(fomattedNumber + Message.WON.get());
+ }
+ System.out.println();
+ }
+
+ public static void printTotalBenefitPrice(int totalBenefitPrice) {
+ System.out.println("<์ดํํ ๊ธ์ก>");
+ if (totalBenefitPrice == Constant.ZERO.get()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ String formattedNumber = decimalFormat.format(totalBenefitPrice);
+ System.out.println(Message.HYPHEN.get() + formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printTotalPayment(int totalPayment) {
+ System.out.println("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>");
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ String formattedNumber = decimalFormat.format(totalPayment);
+ System.out.println(formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printEventBadge(int totalBenefitPrice) {
+ System.out.println("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+ if (totalBenefitPrice >= Constant.SANTA.get()) {
+ System.out.println("์ฐํ");
+ return;
+ }
+ if (totalBenefitPrice >= Constant.TREE.get()) {
+ System.out.println("ํธ๋ฆฌ");
+ return;
+ }
+ if (totalBenefitPrice >= Constant.STAR.get()) {
+ System.out.println("๋ณ");
+ return;
+ }
+ System.out.println(Message.NOTHING.get());
+ }
+} | Java | ์ถ๋ ฅ ๋ทฐ ๋ฉ์๋์ ์ฃผ๋ฌธ์ด๋ ํ ์ธ ์ ์ฃผ๋ฌธ๊ธ์ก์ ๋ฐ์์ ์ฒ๋ฆฌ ํ ํํ์ด๋ ์ฆ์ ๋ฉ๋ด๋ฅผ ๊ณ์ฐํ๋ ๋ถ๊ธฐ ๋ก์ง์ด ๋ด๊ฒจ ์๋ค์. ์ถ๋ ฅ ๋ทฐ๋ ์ถ๋ ฅ๋ง์ ๋ํ ์ฑ
์์ ๊ฐ์ง๋ ๊ฒ์ด ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. ํํ์ด๋ ์ฆ์ ๋ฉ๋ด๋ฅผ ๊ณ์ฐํ๋ ์ฑ
์์ ๊ฐ๊ฐ์ ๋๋ฉ์ธ ๊ฐ์ฒด๋ก ์ด๋ํ์๋ ๊ฒ ์ด๋จ๊น์? |
@@ -0,0 +1,135 @@
+package christmas;
+
+import christmas.model.OrderMenu;
+import christmas.util.Validator;
+
+import java.lang.reflect.Array;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ValidatorTest {
+ private List<Map<String, Integer>> menu = new ArrayList<>(List.of(
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ๋น์ด์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isDateNoneTest() {
+ assertThatThrownBy(() -> Validator.validateDate(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ์ซ์๊ฐ ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isDateInvalidTest() {
+ assertThatThrownBy(() -> Validator.validateDate("1a"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ๋ฒ์๋ฅผ ๋ฒ์ด๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void dateRangeTest() {
+ assertThatThrownBy(() -> Validator.validateDate("123"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ์ฃผ๋ฌธ์ด ๋น์ด์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOrderNoneTest() {
+ assertThatThrownBy(() -> Validator.validateOrder(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ์ฃผ๋ฌธ ์ค ๋น ๋ฌธ์์ด์ด ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isParsedNoneTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder(",ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,,๋ ๋์์ธ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder(",,,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์ฃผ๋ฌธ ํฌ๋งท์ด ์ฌ๋ฐ๋ฅด์ง ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isFormatWrongTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1-1,์ ๋ก์ฝ๋ผ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,---"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("๊ฐ์์ ์ซ์๊ฐ ์๋ ๊ฐ์ด ๋ค์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isNotNumberTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-2๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์ฃผ๋ฌธํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOrderInMenu() {
+ Map<String, Integer> order1 = Map.of("๋ ์๊ฟ", 1);
+ Map<String, Integer> order2 = Map.of("์์ก์ด์ํ", 2, "์ฐ์ ์ก์ฐ", 1);
+ Map<String, Integer> order3 = Map.of("์์ก์ด์ํ", 1, "์์ด์คํฌ๋ฆผ", 1);
+
+ assertThat(Validator.validateMenu(order1, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order2, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(false);
+ }
+
+ @DisplayName("0๊ฐ ์ดํ์ธ ๊ฐ์๊ฐ ์๋ค๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isCountValid() {
+ Map<String, Integer> order1 = Map.of("์์ด์คํฌ๋ฆผ", 0);
+ Map<String, Integer> order2 = Map.of("์์ก์ด์ํ", 1, "์์ด์คํฌ๋ฆผ", 0);
+
+ assertThat(Validator.validateMenu(order1, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order2, menu)).isEqualTo(true);
+ }
+
+ @DisplayName("20๊ฐ๊ฐ ๋์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isUnderTwenty() {
+ Map<String, Integer> order3 = Map.of("์์ก์ด์ํ", 21);
+ Map<String, Integer> order4 = Map.of("์์ก์ด์ํ", 10, "์์ด์คํฌ๋ฆผ", 11);
+
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order4, menu)).isEqualTo(true);
+ }
+
+ @DisplayName("์๋ฃ๋ง ์ฃผ๋ฌธํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOnlyBeverage() {
+ Map<String, Integer> order3 = Map.of("์ ๋ก์ฝ๋ผ", 1);
+ Map<String, Integer> order4 = Map.of("์ ๋ก์ฝ๋ผ", 3, "๋ ๋์์ธ", 1);
+
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order4, menu)).isEqualTo(true);
+ }
+} | Java | ํ๋์ ํ
์คํธ๋ ํ๋์ ๊ธฐ๋ฅ ํน์ ์ฑ
์๋ง์ ํ
์คํธ ํ๋ ๊ฒ์ด ๋ ์ข์ ๊ฒ ๊ฐ์์. ์ผ๋ฐ์ ์ผ๋ก ํ๋์ ํ
์คํธ ๋ฉ์๋์์ ๋ฌด์์ ํ
์คํธํ๋ ค๋์ง ์ ๊ธฐ์ ํ ์ ์๊ธฐ ๋๋ฌธ์ ํ๋์ ํ
์คํธ์ ํ๋์ ๋จ์ธ๋ฌธ์ ์ฐ๋ ๊ฒ์ด ๊ถ์ฅ๋ฉ๋๋ค. |
@@ -0,0 +1,39 @@
+package christmas.util;
+
+public enum Constant {
+ NOT_IN_MENU(-1),
+ EPPETIZER(0),
+ MAINMENU(1),
+ DESSERT(2),
+ BEVERAGE(3),
+ CATEGORY_COUNT(4),
+ ZERO(0),
+ ONE(1),
+ THOUSAND(1000),
+ HUNDRED(100),
+ CHRISTMAS_DAY(25),
+ MIN_BENEFIT_PRICE(10000),
+ PRESENT_COST(120000),
+ CHAMPAIGN_PRICE(25000),
+ WEEKDAYS(7),
+ FRIDAY(1),
+ SATURDAY(2),
+ SUNDAY(3),
+ EVENT_PRICE(2023),
+ SANTA(20000),
+ TREE(10000),
+ STAR(5000),
+ MAX_MENU_COUNT(20),
+ KEY_INDEX(0),
+ VALUE_INDEX(1);
+
+ private final int value;
+
+ Constant(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return this.value;
+ }
+} | Java | ์์๋ฅผ ํ๋์ enum์ ๊ด๋ฆฌํ์ ๊ฒ ๊ฐ์๋ฐ, enum์ ์ข ๋ถ๋ฆฌํด๋ณด๋ฉด ์ด๋จ๊น์? ๊ด๋ จ์ฑ์ด ์๋ ์์๋ค๋ผ๋ฆฌ ํ๊ตฐ๋ฐ ๋ชฐ๋ ค์๋ค๋ณด๋ ์ด์ํ๊ฒ ๋๊ปด์ง๋๋ค |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | menu๋ฅผ list์ ๊ด๋ฆฌํ์
จ๊ตฐ์
์ ๋ต์ ์๋๊ฒ ๊ฐ๋ค๋ง ์ฐํ
์ฝ์์ enum์ ์ฌ์ฉํ๋ผ๊ณ ๊ถ์ฅํ์ผ๋ ์ด๋ฐ ๋ฉ๋ด๋ค์ enum์์ ๊ด๋ฆฌํ๋ฉด ์ข ๋ ์ข์ง ์์๊น ์๊ฐ์ด ๋ญ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ํด๋์ค๋ช
์ OrderMenu์ธ๋ฐ orderDate๋ฅผ ์ธ์คํด์ค ๋ณ์๋ก ๊ด๋ฆฌํ๋๊ฒ ์กฐ๊ธ ์ด์ํ๊ฒ ๋๊ปด์ง๋๋ค.
ํด๋์ค ๋ถ๋ฆฌ๋ฅผ ํตํด orderDate์ ๊ด๋ จํ ํด๋์ค๋ฅผ ๋ง๋ค๊ฑฐ๋, OrderMenu์ ํด๋์ค๋ช
์ด ๋ฉ๋ด์ ๋ ์ง๋ฅผ ๋ค ํฌํจํ๊ฒ๋ ์๊ฐ์ด ๋ค๊ฒ๋ ๋ณ๊ฒฝํด๋ณด๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,47 @@
+package christmas.controller;
+
+import java.util.Map;
+
+import christmas.view.*;
+import christmas.model.*;
+
+public class MainController {
+ private OrderMenu orderMenu;
+
+ public MainController() {
+ orderMenu = new OrderMenu();
+ }
+
+ public void run() {
+ orderMenu.setOrderDate(InputView.readDate());
+ setReadOrder();
+
+ OutputView.printPreview(orderMenu.getOrderDate());
+ OutputView.printOrder(orderMenu.getUserOrder());
+ int totalPrice = orderMenu.getTotalPrice();
+ OutputView.printTotalPrice(totalPrice);
+ OutputView.printPresent(totalPrice);
+ benefitControl(totalPrice);
+ }
+
+ private void benefitControl(int totalPrice) {
+ Benefit benefit = new Benefit(orderMenu.getOrderDate(), orderMenu.getCategoryCount(), totalPrice);
+ OutputView.printBenefits(benefit.getBenefits());
+
+ int totalBenefitPrice = benefit.getTotalBenefitPrice();
+ OutputView.printTotalBenefitPrice(totalBenefitPrice);
+ OutputView.printTotalPayment(totalPrice - totalBenefitPrice + benefit.getPresentPrice());
+ OutputView.printEventBadge(totalBenefitPrice);
+ }
+
+ private void setReadOrder() {
+ Map<String, Integer> orderMenu;
+ try {
+ orderMenu = InputView.readOrder();
+ this.orderMenu.setUserOrder(orderMenu);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ setReadOrder();
+ }
+ }
+} | Java | ์ฌ์ค ์ ๊ฐ ์์ฒญ ์ค๋ ์ฐพ์๋ณด๊ณ ๊ณ ๋ฏผํ ๋ถ๋ถ์ด๊ธด ํ๋ฐ ๋ณดํต ์ฌ์ฉํ๋ ๋ฐฉ์์ ์ ๋ชฐ๋ผ์ ์ ๊ฐ ์๊ฐํ ๋๋ก ํ์ต๋๋ค. ๊ฐ์ธ์ ์ผ๋ก ์๊ฐํ View ํด๋์ค๋ ์ํ๋ฅผ ๊ฐ๊ณ ์์ง ์๊ณ ์ธ์คํด์คํ๋ฅผ ํ ํ์๊ฐ ์๋ ๊ฒ ๊ฐ์์ ์คํํฑ ํด๋์ค๋ ์ฑ๊ธํค ํจํด์ ์ฃผ๋ก ์ฌ์ฉํ๋ค๊ณ ๋ดค์๋๋ฐ, ๊ณผ์ ์์ View๋ฅผ ์์ํ ์ผ์ ์์ ๊ฒ ๊ฐ์์ ์คํํฑ ํด๋์ค๋ก ๊ตฌํํ์ต๋๋ค. ์ผ๋ฐ์ ์ผ๋ก๋ ์ฑ๊ธํค ํจํด์ ์ฌ์ฉํ๋ ๊ฑธ๊น์? |
@@ -0,0 +1,39 @@
+package christmas.util;
+
+public enum Constant {
+ NOT_IN_MENU(-1),
+ EPPETIZER(0),
+ MAINMENU(1),
+ DESSERT(2),
+ BEVERAGE(3),
+ CATEGORY_COUNT(4),
+ ZERO(0),
+ ONE(1),
+ THOUSAND(1000),
+ HUNDRED(100),
+ CHRISTMAS_DAY(25),
+ MIN_BENEFIT_PRICE(10000),
+ PRESENT_COST(120000),
+ CHAMPAIGN_PRICE(25000),
+ WEEKDAYS(7),
+ FRIDAY(1),
+ SATURDAY(2),
+ SUNDAY(3),
+ EVENT_PRICE(2023),
+ SANTA(20000),
+ TREE(10000),
+ STAR(5000),
+ MAX_MENU_COUNT(20),
+ KEY_INDEX(0),
+ VALUE_INDEX(1);
+
+ private final int value;
+
+ Constant(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return this.value;
+ }
+} | Java | enum์ ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์ ๋ชฐ๋๋ ๊ฒ ๊ฐ์์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,47 @@
+package christmas.controller;
+
+import java.util.Map;
+
+import christmas.view.*;
+import christmas.model.*;
+
+public class MainController {
+ private OrderMenu orderMenu;
+
+ public MainController() {
+ orderMenu = new OrderMenu();
+ }
+
+ public void run() {
+ orderMenu.setOrderDate(InputView.readDate());
+ setReadOrder();
+
+ OutputView.printPreview(orderMenu.getOrderDate());
+ OutputView.printOrder(orderMenu.getUserOrder());
+ int totalPrice = orderMenu.getTotalPrice();
+ OutputView.printTotalPrice(totalPrice);
+ OutputView.printPresent(totalPrice);
+ benefitControl(totalPrice);
+ }
+
+ private void benefitControl(int totalPrice) {
+ Benefit benefit = new Benefit(orderMenu.getOrderDate(), orderMenu.getCategoryCount(), totalPrice);
+ OutputView.printBenefits(benefit.getBenefits());
+
+ int totalBenefitPrice = benefit.getTotalBenefitPrice();
+ OutputView.printTotalBenefitPrice(totalBenefitPrice);
+ OutputView.printTotalPayment(totalPrice - totalBenefitPrice + benefit.getPresentPrice());
+ OutputView.printEventBadge(totalBenefitPrice);
+ }
+
+ private void setReadOrder() {
+ Map<String, Integer> orderMenu;
+ try {
+ orderMenu = InputView.readOrder();
+ this.orderMenu.setUserOrder(orderMenu);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ setReadOrder();
+ }
+ }
+} | Java | ๋ค์ ๋ณด๋๊น MainController๊ฐ ์ ์ ํ ์ด๋ฆ์ด ์๋ ๊ฒ ๊ฐ๋ค์, ๋ณดํต ๋ชจ๋ธ๊ณผ ์ปจํธ๋กค๋ฌ์ ๊ด๊ณ๊ฐ 1๋ 1๋ก ์ด๋ฃจ์ด์ง๋ค๊ณ ๋ณด๋ฉด ๋๋ ๊ฑธ๊น์? |
@@ -0,0 +1,39 @@
+package christmas.util;
+
+public enum Constant {
+ NOT_IN_MENU(-1),
+ EPPETIZER(0),
+ MAINMENU(1),
+ DESSERT(2),
+ BEVERAGE(3),
+ CATEGORY_COUNT(4),
+ ZERO(0),
+ ONE(1),
+ THOUSAND(1000),
+ HUNDRED(100),
+ CHRISTMAS_DAY(25),
+ MIN_BENEFIT_PRICE(10000),
+ PRESENT_COST(120000),
+ CHAMPAIGN_PRICE(25000),
+ WEEKDAYS(7),
+ FRIDAY(1),
+ SATURDAY(2),
+ SUNDAY(3),
+ EVENT_PRICE(2023),
+ SANTA(20000),
+ TREE(10000),
+ STAR(5000),
+ MAX_MENU_COUNT(20),
+ KEY_INDEX(0),
+ VALUE_INDEX(1);
+
+ private final int value;
+
+ Constant(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return this.value;
+ }
+} | Java | ์์์ฒ๋ฆฌ์๋ง ๊ธ๊ธํด์ ๋ถ๋ฆฌํ์ง ๋ชปํ๋๋ฐ ์ง๊ธ ๋ณด๋ ๊ฐ๋
์ฑ ์ธก๋ฉด์์๋ ์ข์ง ์์ ๊ฒ ๊ฐ๋ค์. ์ด ๋ถ๋ถ์ ๊ผญ ์์ ํด์ผ๊ฒ ์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,79 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.Message;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class Benefit {
+ private int orderDate;
+ private int[] categoryCount;
+ Map<String, Integer> benefits;
+
+ public Benefit(int orderDate, int[] categoryCount, int totalPrice) {
+ this.orderDate = orderDate;
+ this.categoryCount = categoryCount;
+ benefits = new HashMap<>();
+ if (totalPrice < Constant.MIN_BENEFIT_PRICE.get()) {
+ return;
+ }
+ christmasBenefit();
+ weekBenefit();
+ starBenefit();
+ if (totalPrice >= Constant.PRESENT_COST.get()) {
+ presentBenefit();
+ }
+ }
+
+ public Map<String, Integer> getBenefits() {
+ return this.benefits;
+ }
+
+ public int getTotalBenefitPrice() {
+ int totalBenefitPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.benefits.entrySet()) {
+ int benefit = entry.getValue();
+ totalBenefitPrice += benefit;
+ }
+ return totalBenefitPrice;
+ }
+
+ public int getPresentPrice() {
+ if (this.benefits.containsKey(Message.PRESENT_BENEFIT.get())) {
+ return Constant.CHAMPAIGN_PRICE.get();
+ }
+ return Constant.ZERO.get();
+ }
+
+ private void christmasBenefit() {
+ if (orderDate > Constant.CHRISTMAS_DAY.get()) {
+ return;
+ }
+ int benefit = Constant.THOUSAND.get() + (orderDate - Constant.ONE.get()) * Constant.HUNDRED.get();
+ benefits.put(Message.D_DAY_BENEFIT.get(), benefit);
+ }
+
+ private void weekBenefit() {
+ if (orderDate % Constant.WEEKDAYS.get() == Constant.FRIDAY.get()
+ || orderDate % Constant.WEEKDAYS.get() == Constant.SATURDAY.get()) {
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.MAINMENU.get()];
+ benefits.put(Message.WEEKEND_BENEFIT.get(), benefit);
+ return;
+ }
+ int benefit = Constant.EVENT_PRICE.get() * categoryCount[Constant.DESSERT.get()];
+ benefits.put(Message.WEEKDAY_BENEFIT.get(), benefit);
+ }
+
+ private void starBenefit() {
+ if (orderDate != Constant.CHRISTMAS_DAY.get()
+ && orderDate % Constant.WEEKDAYS.get() != Constant.SUNDAY.get()) {
+ return;
+ }
+ benefits.put(Message.STAR_BENEFIT.get(), Constant.THOUSAND.get());
+ }
+
+ private void presentBenefit() {
+ benefits.put(Message.PRESENT_BENEFIT.get(), Constant.CHAMPAIGN_PRICE.get());
+ }
+} | Java | ์ ์ฝ๋์์๋ ๋ฐฐ์ด๋ง์ผ๋ก ํด๊ฒฐ์ด ๊ฐ๋ฅํด์ ๋ฐฐ์ด๋ก ์ฒ๋ฆฌํ๋๋ฐ ์ฌ๋ ค์ฃผ์ ๋งํฌ๋ฅผ ๋ณด๋๊น ์ปฌ๋ ์
ArrayList์ ์ฅ์ ์ด ๊ฐ๋ณ ๊ธธ์ด๋ง์ ์๋์๊ตฐ์. ๋ง์ด ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ์ด ์ ์ ์ ๊ฐ ์์ ๋ชฐ๋๋ ๋ถ๋ถ์ด์์ต๋๋ค. ํ๋์ฝ๋ฉํ๋ฉด์๋ ์ข์ ๋ฐฉ์์ด ์๋๋ผ๊ณ ๋๊ผ๋๋ฐ enum์ ์ฌ์ฉํ๋ฉด ๋์๋ค์... |
@@ -0,0 +1,96 @@
+package christmas.view;
+
+import christmas.util.Constant;
+import christmas.util.Message;
+import java.util.Map;
+
+import java.text.DecimalFormat;
+
+public class OutputView {
+ public static void printPreview(int orderDate) {
+ System.out.println("12์ " + orderDate + "์ผ์ ์ฐํ
์ฝ ์๋น์์ ๋ฐ์ ์ด๋ฒคํธ ํํ ๋ฏธ๋ฆฌ ๋ณด๊ธฐ!");
+ System.out.println();
+ }
+
+ public static void printOrder(Map<String, Integer> userOrder) {
+ System.out.println("<์ฃผ๋ฌธ ๋ฉ๋ด>");
+ for (Map.Entry<String, Integer> entry : userOrder.entrySet()) {
+ System.out.println(entry.getKey() + Message.SPACE.get() + entry.getValue() + Message.COUNT.get());
+ }
+ System.out.println();
+ }
+
+ public static void printTotalPrice(int totalPrice) {
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+
+ System.out.println("<ํ ์ธ ์ ์ด์ฃผ๋ฌธ ๊ธ์ก>");
+ String formattedNumber = decimalFormat.format(totalPrice);
+ System.out.println(formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printPresent(int totalPrice) {
+ System.out.println("<์ฆ์ ๋ฉ๋ด>");
+ if (totalPrice < Constant.PRESENT_COST.get()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ System.out.println(Message.ONE_CHAMPAIGN.get());
+ System.out.println();
+ }
+
+ public static void printBenefits(Map<String, Integer> benefits) {
+ System.out.println("<ํํ ๋ด์ญ>");
+ if (benefits.isEmpty()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ for (Map.Entry<String, Integer> entry : benefits.entrySet()) {
+ System.out.print(entry.getKey() + ": -");
+ String fomattedNumber = decimalFormat.format(entry.getValue());
+ System.out.println(fomattedNumber + Message.WON.get());
+ }
+ System.out.println();
+ }
+
+ public static void printTotalBenefitPrice(int totalBenefitPrice) {
+ System.out.println("<์ดํํ ๊ธ์ก>");
+ if (totalBenefitPrice == Constant.ZERO.get()) {
+ System.out.println(Message.NOTHING.get());
+ System.out.println();
+ return;
+ }
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ String formattedNumber = decimalFormat.format(totalBenefitPrice);
+ System.out.println(Message.HYPHEN.get() + formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printTotalPayment(int totalPayment) {
+ System.out.println("<ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก>");
+ DecimalFormat decimalFormat = new DecimalFormat(Message.PRICE_FORMAT.get());
+ String formattedNumber = decimalFormat.format(totalPayment);
+ System.out.println(formattedNumber + Message.WON.get());
+ System.out.println();
+ }
+
+ public static void printEventBadge(int totalBenefitPrice) {
+ System.out.println("<12์ ์ด๋ฒคํธ ๋ฐฐ์ง>");
+ if (totalBenefitPrice >= Constant.SANTA.get()) {
+ System.out.println("์ฐํ");
+ return;
+ }
+ if (totalBenefitPrice >= Constant.TREE.get()) {
+ System.out.println("ํธ๋ฆฌ");
+ return;
+ }
+ if (totalBenefitPrice >= Constant.STAR.get()) {
+ System.out.println("๋ณ");
+ return;
+ }
+ System.out.println(Message.NOTHING.get());
+ }
+} | Java | mvc์ ์ญํ ๋ถ๋ฆฌ์ ์ต์ํ์ง ์์์ ๊ทธ๋ฐ์ง View๊ฐ ์ฒ๋ฆฌํด๋ ๊ด์ฐฎ๋ค๊ณ ์๊ฐํ๋๋ฐ ๋ค์ ๋ณด๋๊น ๋ง์ํ์ ๋ถ๋ถ์ด ๋ง๋ ๊ฒ ๊ฐ๋ค์. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,135 @@
+package christmas;
+
+import christmas.model.OrderMenu;
+import christmas.util.Validator;
+
+import java.lang.reflect.Array;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ValidatorTest {
+ private List<Map<String, Integer>> menu = new ArrayList<>(List.of(
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ๋น์ด์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isDateNoneTest() {
+ assertThatThrownBy(() -> Validator.validateDate(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ์ซ์๊ฐ ์๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isDateInvalidTest() {
+ assertThatThrownBy(() -> Validator.validateDate("1a"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ๋ ์ง๊ฐ ๋ฒ์๋ฅผ ๋ฒ์ด๋๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void dateRangeTest() {
+ assertThatThrownBy(() -> Validator.validateDate("123"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ์ฃผ๋ฌธ์ด ๋น์ด์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOrderNoneTest() {
+ assertThatThrownBy(() -> Validator.validateOrder(""))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์
๋ ฅ๋ ์ฃผ๋ฌธ ์ค ๋น ๋ฌธ์์ด์ด ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isParsedNoneTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder(",ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,๋ ๋์์ธ-1,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-2,,๋ ๋์์ธ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder(",,,"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("์ฃผ๋ฌธ ํฌ๋งท์ด ์ฌ๋ฐ๋ฅด์ง ์์ผ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isFormatWrongTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1-1,์ ๋ก์ฝ๋ผ-1"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,---"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("๊ฐ์์ ์ซ์๊ฐ ์๋ ๊ฐ์ด ๋ค์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isNotNumberTest() {
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ assertThatThrownBy(() -> Validator.validateOrder("ํด์ฐ๋ฌผํ์คํ-1,์ ๋ก์ฝ๋ผ-2๋ ๋์์ธ"))
+ .isInstanceOf(IllegalArgumentException.class);
+ }
+
+ @DisplayName("๋ฉ๋ดํ์ ์๋ ๋ฉ๋ด๋ฅผ ์ฃผ๋ฌธํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOrderInMenu() {
+ Map<String, Integer> order1 = Map.of("๋ ์๊ฟ", 1);
+ Map<String, Integer> order2 = Map.of("์์ก์ด์ํ", 2, "์ฐ์ ์ก์ฐ", 1);
+ Map<String, Integer> order3 = Map.of("์์ก์ด์ํ", 1, "์์ด์คํฌ๋ฆผ", 1);
+
+ assertThat(Validator.validateMenu(order1, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order2, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(false);
+ }
+
+ @DisplayName("0๊ฐ ์ดํ์ธ ๊ฐ์๊ฐ ์๋ค๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isCountValid() {
+ Map<String, Integer> order1 = Map.of("์์ด์คํฌ๋ฆผ", 0);
+ Map<String, Integer> order2 = Map.of("์์ก์ด์ํ", 1, "์์ด์คํฌ๋ฆผ", 0);
+
+ assertThat(Validator.validateMenu(order1, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order2, menu)).isEqualTo(true);
+ }
+
+ @DisplayName("20๊ฐ๊ฐ ๋์ด๊ฐ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isUnderTwenty() {
+ Map<String, Integer> order3 = Map.of("์์ก์ด์ํ", 21);
+ Map<String, Integer> order4 = Map.of("์์ก์ด์ํ", 10, "์์ด์คํฌ๋ฆผ", 11);
+
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order4, menu)).isEqualTo(true);
+ }
+
+ @DisplayName("์๋ฃ๋ง ์ฃผ๋ฌธํ๋ฉด ์์ธ๊ฐ ๋ฐ์ํ๋ค.")
+ @Test
+ void isOnlyBeverage() {
+ Map<String, Integer> order3 = Map.of("์ ๋ก์ฝ๋ผ", 1);
+ Map<String, Integer> order4 = Map.of("์ ๋ก์ฝ๋ผ", 3, "๋ ๋์์ธ", 1);
+
+ assertThat(Validator.validateMenu(order3, menu)).isEqualTo(true);
+ assertThat(Validator.validateMenu(order4, menu)).isEqualTo(true);
+ }
+} | Java | ํ
์คํธ๋ ๋ ์ ๊ฒฝ์จ์ผ๊ฒ ๊ตฐ์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,39 @@
+package christmas.util;
+
+public enum Constant {
+ NOT_IN_MENU(-1),
+ EPPETIZER(0),
+ MAINMENU(1),
+ DESSERT(2),
+ BEVERAGE(3),
+ CATEGORY_COUNT(4),
+ ZERO(0),
+ ONE(1),
+ THOUSAND(1000),
+ HUNDRED(100),
+ CHRISTMAS_DAY(25),
+ MIN_BENEFIT_PRICE(10000),
+ PRESENT_COST(120000),
+ CHAMPAIGN_PRICE(25000),
+ WEEKDAYS(7),
+ FRIDAY(1),
+ SATURDAY(2),
+ SUNDAY(3),
+ EVENT_PRICE(2023),
+ SANTA(20000),
+ TREE(10000),
+ STAR(5000),
+ MAX_MENU_COUNT(20),
+ KEY_INDEX(0),
+ VALUE_INDEX(1);
+
+ private final int value;
+
+ Constant(int value) {
+ this.value = value;
+ }
+
+ public int get() {
+ return this.value;
+ }
+} | Java | ์์๋ฅผ ์ฒ๋ฆฌํ๋ค๋ ๊ฒ์๋ง ์ ๊ฒฝ์ฐ๋ค ๋ณด๋ ๋ฏธ์ฒ ์๊ฐ์ ๋ชปํ์ต๋๋ค. ๋ค์ ํ์ธํด๋ณด๋ ๊ฐ๋
์ฑ ์ธก๋ฉด์์๋ ๋ง์ด ๋ถํธํ ๊ฒ ๊ฐ์์. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ์ ๋ ์ด ๋ถ๋ถ์ ์ฒ๋ฆฌํ๋ฉด์ ์ข์ ๋ฐฉ์์ด ์๋๋ผ๊ณ ๋๊ผ๋๋ฐ, enum์ ํตํด ์ฒ๋ฆฌํ ์ ์๋จ ์๊ฐ์ ๋ชปํ๋ค์. ํด์ด๋ ์ฝ๋๋ฅผ ๋ณด๊ณ enum์ ์ ์ฒ๋ฆฌํ์
จ๋ค๊ณ ๋๊ผ๋๋ฐ ์ฐธ๊ณ ํด์ ์ ์ฉํด๋ด์ผ๊ฒ ์ต๋๋ค. ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,68 @@
+package christmas.model;
+
+import christmas.util.Constant;
+import christmas.util.ErrorMessage;
+import christmas.util.Utility;
+import christmas.util.Validator;
+
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.List;
+
+public class OrderMenu {
+ private final List<Map<String, Integer>> menu;
+
+ private int orderDate;
+ private Map<String, Integer> userOrder;
+
+ public OrderMenu() {
+ menu = new ArrayList<>(List.of(
+ // EPPETIZER 0
+ Map.of("์์ก์ด์ํ", 6000, "ํํ์ค", 5500, "์์ ์๋ฌ๋", 8000),
+ // MAINMENU 1
+ Map.of("ํฐ๋ณธ์คํ
์ดํฌ", 55000, "๋ฐ๋นํ๋ฆฝ", 54000, "ํด์ฐ๋ฌผํ์คํ", 35000, "ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000),
+ // DESSERT 2
+ Map.of("์ด์ฝ์ผ์ดํฌ", 15000, "์์ด์คํฌ๋ฆผ", 5000),
+ // BEVERAGE 3
+ Map.of("์ ๋ก์ฝ๋ผ", 3000, "๋ ๋์์ธ", 60000, "์ดํ์ธ", 25000)
+ ));
+ }
+
+ public int getOrderDate() {
+ return this.orderDate;
+ }
+
+ public Map<String, Integer> getUserOrder() {
+ return this.userOrder;
+ }
+
+ public int getTotalPrice() {
+ int totalPrice = Constant.ZERO.get();
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ int price = menu.get(category).get(entry.getKey());
+ totalPrice += price * entry.getValue();
+ }
+ return totalPrice;
+ }
+
+ public int[] getCategoryCount() {
+ int[] categoryCount = new int[Constant.CATEGORY_COUNT.get()];
+ for (Map.Entry<String, Integer> entry : this.userOrder.entrySet()) {
+ int category = Utility.getCategory(entry.getKey(), menu);
+ categoryCount[category] += entry.getValue();
+ }
+ return categoryCount;
+ }
+
+ public void setOrderDate(int date) {
+ this.orderDate = date;
+ }
+
+ public void setUserOrder(Map<String, Integer> userOrder) {
+ if (Validator.validateMenu(userOrder, this.menu)) {
+ throw new IllegalArgumentException(ErrorMessage.ORDER_ERROR.get());
+ }
+ this.userOrder = userOrder;
+ }
+} | Java | ๋ง์ํด์ฃผ์ ๋ถ๋ถ ๋ค์ ๋ณด๋๊น ํด๋์ค ์ด๋ฆ์ด ๋ด์ฉ์ ๋ค ํฌ๊ดํ์ง ๋ชปํด ์ด์ํ๊ฒ ๋๊ปด์ง๋ค์. ์ฃผ๋ฌธํ ๋ถ๋ถ์ ๋ค ์ฒ๋ฆฌํ๊ธฐ ์ํด ๋ ์ง๊ฐ ํ์ํ๋ฐ ํด๋์ค์ ์ด๋ฆ์ ๋ณ๊ฒฝํด๋ณด๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,47 @@
+package christmas.controller;
+
+import java.util.Map;
+
+import christmas.view.*;
+import christmas.model.*;
+
+public class MainController {
+ private OrderMenu orderMenu;
+
+ public MainController() {
+ orderMenu = new OrderMenu();
+ }
+
+ public void run() {
+ orderMenu.setOrderDate(InputView.readDate());
+ setReadOrder();
+
+ OutputView.printPreview(orderMenu.getOrderDate());
+ OutputView.printOrder(orderMenu.getUserOrder());
+ int totalPrice = orderMenu.getTotalPrice();
+ OutputView.printTotalPrice(totalPrice);
+ OutputView.printPresent(totalPrice);
+ benefitControl(totalPrice);
+ }
+
+ private void benefitControl(int totalPrice) {
+ Benefit benefit = new Benefit(orderMenu.getOrderDate(), orderMenu.getCategoryCount(), totalPrice);
+ OutputView.printBenefits(benefit.getBenefits());
+
+ int totalBenefitPrice = benefit.getTotalBenefitPrice();
+ OutputView.printTotalBenefitPrice(totalBenefitPrice);
+ OutputView.printTotalPayment(totalPrice - totalBenefitPrice + benefit.getPresentPrice());
+ OutputView.printEventBadge(totalBenefitPrice);
+ }
+
+ private void setReadOrder() {
+ Map<String, Integer> orderMenu;
+ try {
+ orderMenu = InputView.readOrder();
+ this.orderMenu.setUserOrder(orderMenu);
+ } catch (IllegalArgumentException e) {
+ System.out.println(e.getMessage());
+ setReadOrder();
+ }
+ }
+} | Java | MVC ๊ฐ๊ฐ์ ๋ถ๋ฆฌ๋์ด ์๋ ์์๋ค ๋ณด๋๊น ๊ฐ๊ฐ์ ๋ถ๋ฆฌ๋ ๊ฐ์ฒด๋ก ๋ณด๊ณ ์ธ์คํด์คํํด์ ์ฌ์ฉํ๋ ๊ฒ ๊ฐ์์. ๋ฌผ๋ก ์ด๊ฒ ์ ๋ต์ด๋ผ๋ ๊ฑด ์๋๋๋ค. ๋ง์ํ์ ๋๋ก ์ํ๋ฅผ ๊ฐ์ง์ง ์์ผ๋ ์คํํฑ ๋ฉ์๋๋ก ๋ง๋์ ๊ฒ๋ ํ ๊ฐ์ง ๋ฐฉ๋ฒ์ธ ๊ฒ ๊ฐ์ต๋๋ค.
์ฐธ๊ณ ๋ก, ์คํํฑ ๋ฉ์๋๋ง์ผ๋ก ๊ตฌ์ฑ๋ ๊ฐ์ฒด๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ๋ฌธ์ ๋ฅผ ์ฐพ์๋ดค๋๋ฐ, ๋ง์ ๊ฒฝ์ฐ ๋ทฐ์์ ์ํ๋ฅผ ๊ฐ์ ธ์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ผ๋ฉฐ, ์คํํฑ ๋ฉ์๋์ ๊ฒฝ์ฐ ํ
์คํธ ์ ๋ชฉ ๊ฐ์ฒด๋ฅผ ๋ง๋ค๊ธฐ ์ด๋ ต๊ณ ์์์ด๋ ๋คํ์ฑ์ ์ฌ์ฉํ๊ธฐ ์ด๋ ค์์ ํ์ฅ์ฑ์ด๋ ์ ์ฐ์ฑ์ด ๋จ์ด์ง๋ค๊ณ ํ๋ค์. |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ๊ฐ ๊ธฐ๋ฌผ ๋ค์ ๋์จ ์ซ์๊ฐ ์ ์์ธ ๊ฒ์ผ๋ก ๋ณด์ด๋๋ฐ,
์ ์ ๊ณ์ฐ์ ๋ํ ๊ฒ๋ ๊ธฐ๋ฅ ๋ชฉ๋ก์ผ๋ก ๋นผ๋ฉด ์ด๋จ๊น์?
ํด๋น ์ฝ๋๋ง ๋ณด๊ณ ์ดํดํ๋ ์ฌ๋์๊ฒ๋ ์ด๋ค ์ซ์๋ฅผ ์๋ฏธํ๋์ง ์๊ธฐ๊ฐ ์ด๋ ค์ธ ๊ฒ ๊ฐ์์. |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ํธ์ ์ด๋๋ฐฉํฅ์ ์ํ์ข์ฐ๋๊ฐ์ ๋ชจ๋ ์ํ๋๋งํผ ์ด๋์ธ ๊ฒ์ผ๋ก ์๊ณ ์๋๋ฐ,
์ํ์ข์ฐ๋ 1์นธ์ฉ๋ฐ์ ์ด๋ํ์ง ๋ชปํ๋๊ฑด๊ฐ์?
ํธ์ ์ด๋ ๊ท์น์ ํ ๋ฒ ๋ค์ ๋ด์ฃผ์๊ฒ ์ด์? |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ๋ต! Player ๊ธฐ๋ฅ๋ชฉ๋ก์ ์ ์ ๊ณ์ฐ๋ ์ถ๊ฐํ์ต๋๋ค |
@@ -1 +1,127 @@
# java-chess ๊ฒ์
+
+## ๊ตฌํํด์ผํ ๋ชฉ๋ก
+
+### ์
๋ ฅ
+
+- [x] ๋ช
๋ น์ด ์
๋ ฅ
+ - [x] ์์ธ: `null` ์
๋ ฅ
+
+### ์ถ๋ ฅ
+
+- [x] ์์ ์๋ด ๋ฌธ๊ตฌ ์ถ๋ ฅ
+- [x] ์ฒด์คํ ์ค๋
์ท ์ถ๋ ฅ
+- [x] ์ฐจ๋ก ์ถ๋ ฅ
+- [x] ์ ์ ์ถ๋ ฅ
+- [x] ์น์ ์ถ๋ ฅ
+
+### ์๋น์ค
+
+#### `ChessService`
+
+- [x] `Command`์ ๋ฐ๋ผ ๊ธฐ๋ฅ ์ํ
+- [x] ๊ฒ์ ํ์ฌ ์ํฉ DTO
+
+### ๋๋ฉ์ธ
+
+#### `Operation`
+
+- [x] ๋ช
๋ น์ด ๊ฒ์ฆ
+ - [x] start: ๊ฒ์ ์คํ
+ - [x] status: ํ๋ณ ์ ์
+ - [x] move: ๊ธฐ๋ฌผ ์ด๋
+ - [x] end: ๊ฐ์ ์ข
๋ฃ
+
+#### `Board`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+ - [x] ์์ธ
+ - [x] ์์ง์ผ ๊ธฐ๋ฌผ์ด ์์ ํ ์์ ๊ฐ ์๋ ๊ฒฝ์ฐ
+ - [x] `source`์ `target`์ด ๊ฐ์ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] ๋ณธ์ธ์ ๊ธฐ๋ฌผ์ ๊ณต๊ฒฉํ๋ ๊ฒฝ์ฐ
+ - [x] ์ด๋ ๊ฒฝ๋ก๊ฐ ๋ค๋ฅธ ๊ธฐ๋ฌผ์ ๊ฐ๋ก๋งํ ๊ฒฝ์ฐ
+ - [x] `King`: `target`์ด ์ ์ด ๊ณต๊ฒฉ ๊ฐ๋ฅํ ์์น์ธ ๊ฒฝ์ฐ
+ - [x] `Pawn`: `target`์ ์ ์ด ์๋๋ฐ ๋๊ฐ์ ์ผ๋ก ์ด๋ํ๋ ๊ฒฝ์ฐ
+ - [x] ์์ ์ ๊ธฐ๋ฌผ ์ด๋
+ - [x] ๊ณต๊ฒฉ์ธ ๊ฒฝ์ฐ ์ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+ - [x] ์ฐจ๋ก ๋ณ๊ฒฝ
+- [x] ํ์ฌ ์ฐจ๋ก ๊ด๋ฆฌ
+- [x] ์์น ์ ๋ณด
+ - [x] ํน์ ์์น๊ฐ ๋น์๋์ง ํ์ธ
+ - [x] ํน์ ์์น์ ์๋ ๊ธฐ๋ฌผ ํ์ธ
+- [x] ๊ฐ ํ ์ ์ ๊ณ์ฐ
+- [x] ์น์ ํ์ธ
+ - [x] ์์ธ: ๋ `King`์ด ๋ชจ๋ ์ด์ ์๋ ๊ฒฝ์ฐ
+
+#### `Team`
+
+- [x] ๊ธฐ๋ฌผ ์ด๋
+- [x] ๊ธฐ๋ฌผ ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์ ์๊ฒ ๊ณต๊ฒฉ๋ฐ์ ๊ฒฝ์ฐ ๊ธฐ๋ฌผ ์ ๊ฑฐ
+- [x] ๊ธฐ๋ฌผ ๊ฒ์
+- [x] ์ ์ ๊ณ์ฐ
+
+#### `Piece`
+
+- [x] ์ด๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ํ์์น์์ ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+- [x] ์์ ํ์ธ
+- [x] ํ์
ํ์ธ
+ - [x] `Pawn`
+ - [x] `King`
+
+#### `MovePattern`
+
+- [x] ๊ฐ ๊ธฐ๋ฌผ ํ์
์ ๋ง๋ ํจํด ๊ฒ์
+ - [x] `Pawn`์ ์์์ ๋ง๋ ํจํด ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด ์ค `gap`์ ๋ง๋ `MoveUnit` ๊ฒ์
+- [x] ๋ณธ์ธ ํจํด์ผ๋ก ๊ณต๊ฒฉ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveLimit`
+
+- [x] ํ ์นธ๋ง ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+
+#### `MoveUnits`
+
+- [x] ๋ณธ์ธ ๋ฆฌ์คํธ์์ ๋งค์นญ๋๋ `MoveUnit` ๊ฒ์
+ - [x] ์์ธ: ๋งค์นญ๋๋ `MoveUnit`์ด ์๋ ๊ฒฝ์ฐ
+- [x] ์ด๋ ๋จ์ ๋ณ๋ก ์ด๋ ๊ฐ๋ฅํ ๋ชจ๋ ๊ฒฝ๋ก ๊ฒ์
+
+#### `MoveUnit`
+
+- [x] `MoveUnit`์ ์ขํ๊ฐ `gap`์ ๋งค์นญ๋๋์ง ํ์ธ
+
+#### `Position`
+
+- [x] 64๊ฐ ์์น ์บ์ฑ ๋ฐ ๊ฒ์
+- [x] `Gap` ๊ณ์ฐ
+- [x] ์ด๋ ๋จ์๋ก ํ๊ฒ๊น์ง ์ด๋ํ ๋ ์ง๋๊ฐ๋ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ์ด๋ ๊ฐ๋ฅํ ์ฒด์คํ์ ๋ชจ๋ ์์น ๊ฒ์
+- [x] ์ด๋ ๋จ์๋ก ํ ๋ฒ ๋ ์ด๋ ๊ฐ๋ฅํ์ง ํ์ธ
+- [x] ์ด๋ ๋จ์๋ก ์ด๋
+
+## ์ด๋ ๊ท์น
+
+- [x] ํฐ (1 or 0.5)
+ - [x] ์ ๋ฐฉํฅ ์ง์ 1์นธ ์ด๋
+ - [x] ์ฒ์ ์ด๋ ์์๋ 2์นธ ์ด๋ ๊ฐ๋ฅ
+ - [x] ๊ณต๊ฒฉ ์์๋ ์ ๋ฐฉํฅ ์ข, ์ฐ ๋๊ฐ์ 1์นธ ์ด๋
+
+- [x] ๋ฃฉ (5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ๋์ดํธ (2.5)
+ - [x] ๋ชจ๋ ์ง์ ๋ฐฉํฅ 1์นธ + ์ด๋ํ ์ง์ ๋ฐฉํฅ์ ์ข, ์ฐ ๋๊ฐ์ 1์นธ์ผ๋ก ์ด๋
+ - [x] ์งํ ๋ฐฉํฅ์ด ๊ฐ๋ก๋งํ๋ ์ , ์๊ตฐ ์๊ด์์ด ๋ฐ์ด๋์ ์ ์์
+
+- [x] ๋น์ (3)
+ - [x] ๋ชจ๋ ๋๊ฐ์ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํธ (9)
+ - [x] ๋ชจ๋ ๋ฐฉํฅ์ผ๋ก ์ํ๋ ๋งํผ ์ด๋
+
+- [x] ํน
+ - [x] ๋ชจ๋ ๋ฐฉํฅ 1์นธ ์ด๋
+ - [x] ์๋์ ๊ณต๊ฒฉ ๋ฒ์๋ก๋ ์ด๋ ๋ถ๊ฐ๋ฅ
+ | Unknown | ๋ต ํธ ์ด๋ ๊ท์น์ ์์ ํ ์ฐฉ๊ฐํด๋ฒ๋ ธ์ด์ใ
ใ
์์ ํ์ต๋๋ค! |
@@ -0,0 +1,42 @@
+import Customer from '../src/models/Customer';
+import Order from '../src/models/Order';
+
+describe('Customer ํด๋์ค', () => {
+ let customer;
+
+ beforeEach(() => {
+ customer = new Customer();
+ });
+
+ test('์ฃผ๋ฌธ์ด ์์ ๋, ๋ฑ์ง ๊ณ์ฐ ๊ฒฐ๊ณผ๋ null์ด ๋๋ค.', () => {
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBeNull();
+ });
+
+ test('์ ์ ํ ํ ์ธ ๊ธ์ก์ ๋ฐ๋ผ ์ฌ๋ฐ๋ฅธ ๋ฑ์ง๊ฐ ํ ๋น๋๋ค.', () => {
+ const order = new Order();
+ order.setDiscountAmount(10000);
+ customer.addOrder(order);
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBe('ํธ๋ฆฌ');
+ });
+
+ test('์ฌ๋ฌ ์ฃผ๋ฌธ์ ์ถ๊ฐํ์ ๋, ์ด ํ ์ธ ๊ธ์ก์ ๋ฐ๋ฅธ ๋ฑ์ง๊ฐ ํ ๋น๋๋ค.', () => {
+ const order1 = new Order();
+ order1.setDiscountAmount(3000);
+ const order2 = new Order();
+ order2.setDiscountAmount(2000);
+ customer.addOrder(order1);
+ customer.addOrder(order2);
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBe('๋ณ');
+ });
+
+ test('ํ ์ธ ๊ธ์ก์ด 5000์ ์ดํ์ผ ๋ ๋ฑ์ง๋ null๋ก ํ์๋๋ค.', () => {
+ const order = new Order();
+ order.setDiscountAmount(4000);
+ customer.addOrder(order);
+ customer.calculateBadge();
+ expect(customer.getBadge()).toBeNull();
+ });
+}); | JavaScript | ์ง๊ธ์ `ํธ๋ฆฌ`์ ๋ํ ํ
์คํธ ์ผ์ด์ค๋ง ์๋๋ฐ, `๋ณ`๊ณผ `์ฐํ` ํ
์คํธ ์ผ์ด์ค๊น์ง ๋ชจ๋ ํฌํจํ๋ฉด ํ
์คํธ ์ ๋ขฐ๋๊ฐ ๋์์ง ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,48 @@
+import Menu from '../src/models/Menu';
+import { MenuConstants } from '../src/constants/MenuConstants';
+
+describe('Menu ํด๋์ค', () => {
+ let menu;
+
+ beforeEach(() => {
+ menu = new Menu();
+ });
+
+ test('๋ฉ๋ด ํญ๋ชฉ์ด ์ฌ๋ฐ๋ฅด๊ฒ ์ด๊ธฐํ๋์ด์ผ ํ๋ค.', () => {
+ expect(menu.getItem('ํฐ๋ณธ์คํ
์ดํฌ')).toEqual({
+ name: 'ํฐ๋ณธ์คํ
์ดํฌ',
+ price: 55000,
+ category: 'MAINS',
+ });
+ expect(menu.getItem('์์ ์๋ฌ๋')).toEqual({
+ name: '์์ ์๋ฌ๋',
+ price: 8000,
+ category: 'APPETIZERS',
+ });
+ });
+
+ test('์กด์ฌํ์ง ์๋ ๋ฉ๋ด ํญ๋ชฉ์ ๋ํด null์ ๋ฐํํด์ผ ํ๋ค.', () => {
+ expect(menu.getItem('์์ก์ด์คํ')).toBeNull();
+ expect(menu.getItem('1234')).toBeNull();
+ expect(menu.getItem('์คํ
์ดํฌ@')).toBeNull();
+ });
+
+ test('๋ชจ๋ ๋ฉ๋ด ์นดํ
๊ณ ๋ฆฌ๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ๋ก๋๋์ด์ผ ํ๋ค.', () => {
+ Object.keys(MenuConstants).forEach((category) => {
+ Object.keys(MenuConstants[category]).forEach((itemName) => {
+ const menuItem = menu.getItem(itemName);
+ expect(menuItem).not.toBeNull();
+ expect(menuItem.category).toBe(category);
+ });
+ });
+ });
+
+ test('๊ฐ ๋ฉ๋ด ํญ๋ชฉ์ ๊ฐ๊ฒฉ์ด ์ ํํด์ผ ํจ', () => {
+ Object.keys(MenuConstants).forEach((category) => {
+ Object.entries(MenuConstants[category]).forEach(([itemName, price]) => {
+ const menuItem = menu.getItem(itemName);
+ expect(menuItem.price).toBe(price);
+ });
+ });
+ });
+}); | JavaScript | ์ฌ๊ธฐ ๋ ํ
์คํธ ๋ชจ๋ ์ฌ๋ฌ ๊ฐ์ `expect()`๋ฅผ ๊ฐ์ง๊ณ ์๋๋ฐ์. `expect()`ํ๋ ๋ถ๋ถ์ ๊ตฌ์กฐ๊ฐ ๋น์ทํ๋๊น "๋ฉ๋ด ํญ๋ชฉ ์ด๊ธฐํ ํ
์คํธ"์ "์กด์ฌํ์ง ์๋ ๋ฉ๋ด ํญ๋ชฉ ํ
์คํธ"๋ฅผ `test.each()`๋ก ๋ณ๊ฒฝํ๋ ๊ฑด ์ด๋จ๊น์?. ํ๋ก๋์
์ฝ๋๋ฅผ ์์ฑํ ๋ ์ค๋ณต๋๋ ๋ถ๋ถ์ ์ ๊ฑฐํ๋ ๊ฒ์ฒ๋ผ, ํ
์คํธ ์ฝ๋๋ ๋ง์ฐฌ๊ฐ์ง๋ก ์ค๋ณต์ ์ ๊ฑฐํ๋ ๋ฆฌํฉํฐ๋ง์ด ํ์ํ๋ค๊ณ ์๊ฐํฉ๋๋ค! |
@@ -0,0 +1,73 @@
+import OrderValidator from '../src/validators/OrderValidator';
+import Menu from '../src/models/Menu';
+import { ValidatorConstants } from '../src/validators/constants/ValidatorConstants';
+
+describe('OrderValidator ํด๋์ค', () => {
+ let mockMenu;
+
+ beforeEach(() => {
+ mockMenu = new Menu();
+ });
+
+ describe('validateOrderItems ๋ฉ์๋', () => {
+ test('์ ํจํ ์ฃผ๋ฌธ ํญ๋ชฉ์ ๋ํด ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const orderItems = [{ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).not.toThrow();
+ });
+
+ test('์กด์ฌํ์ง ์๋ ๋ฉ๋ด ํญ๋ชฉ์ ๋ํด ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [{ name: '๋ฏธ์ง์๋ฉ๋ด', quantity: 1 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+
+ test('์๋ฃ๋ง ํฌํจ๋ ์ฃผ๋ฌธ ์ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [{ name: '์ ๋ก์ฝ๋ผ', quantity: 2 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.ONLY_BEVERAGE_ERROR),
+ );
+ });
+
+ test('์ฃผ๋ฌธ ํญ๋ชฉ์ ์ด ์๋์ด 20๊ฐ๋ฅผ ์ด๊ณผํ๋ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = new Array(21).fill({ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 });
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+ test('์ฃผ๋ฌธ ํญ๋ชฉ์ ์ด ์๋์ด 20๊ฐ ์ดํ์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const orderItems = new Array(20).fill({ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 });
+ expect(() => OrderValidator.validateTotalQuantity(orderItems)).not.toThrow();
+ });
+
+ test('์ฃผ๋ฌธ ์๋์ด 0 ์ดํ์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [{ name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 0 }];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+
+ test('์๋์ด 1 ์ด์์ธ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const item = { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 };
+ expect(() => OrderValidator.validateQuantity(item)).not.toThrow();
+ });
+
+ test('์ค๋ณต๋ ๋ฉ๋ด ํญ๋ชฉ์ด ํฌํจ๋ ๊ฒฝ์ฐ ์์ธ๊ฐ ๋ฐ์ํด์ผ ํ๋ค', () => {
+ const orderItems = [
+ { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 },
+ { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 },
+ ];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).toThrow(
+ new Error(ValidatorConstants.INVALID_ORDER_ERROR),
+ );
+ });
+
+ test('์์๊ณผ ์๋ฃ๊ฐ ํผํฉ๋ ์ ํจํ ์ฃผ๋ฌธ์ ์์ธ๊ฐ ๋ฐ์ํ์ง ์์์ผ ํ๋ค', () => {
+ const orderItems = [
+ { name: 'ํฐ๋ณธ์คํ
์ดํฌ', quantity: 1 },
+ { name: '์ ๋ก์ฝ๋ผ', quantity: 2 },
+ ];
+ expect(() => OrderValidator.validateOrderItems(orderItems, mockMenu)).not.toThrow();
+ });
+ });
+}); | JavaScript | `Validator` ํ
์คํธ ํ์ผ์์๋ ์์ธ๊ฐ ๋ฐ์ํ์ ๋ ์๋ฌ์ ์ ํ๊ณผ ๋ฉ์์ง ํฌํจ ์ฌ๋ถ๋ฅผ ๊ฒ์ฌํ๊ณ ์๋๋ฐ์. ๋ค๋ฅธ ๊ณณ์ ์์ธ ํ
์คํธ์์๋ ๋ฉ์์ง ๊ฒ์ฌ ์์ด ์์ธ๊ฐ ๋ฐ์ํ๋์ง๋ง(`toThrow()`) ๊ฒ์ฌํ๋ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค. |
@@ -0,0 +1,56 @@
+import InputView from '../views/InputView';
+import OutputView from '../views/OutputView';
+import OrderService from '../services/OrderService';
+import DiscountService from '../services/DiscountService';
+import Customer from '../models/Customer';
+import { DateFormatter } from '../utils/DateFormatter';
+
+export default class EventController {
+ #orderService;
+
+ #customer;
+
+ #discountService;
+
+ constructor() {
+ this.#orderService = new OrderService();
+ this.#customer = new Customer();
+ this.#discountService = new DiscountService();
+ }
+
+ async start() {
+ OutputView.printWelcomeMessage();
+ await this.handleOrderProcess();
+ }
+
+ async handleOrderProcess() {
+ try {
+ const inputDate = await this.getDateFromUser();
+ await this.handleMenuOrderProcess(inputDate);
+ } catch (error) {
+ OutputView.printErrorMessage(error.message);
+ await this.handleOrderProcess();
+ }
+ }
+
+ async getDateFromUser() {
+ const day = await InputView.readDate();
+ return DateFormatter.createDateFromDay(day);
+ }
+
+ async handleMenuOrderProcess(inputDate) {
+ try {
+ const inputMenuItems = await InputView.readMenu();
+ const order = this.#orderService.createOrder(inputDate, inputMenuItems);
+ order.applyDiscounts(this.#discountService, inputDate);
+ this.#customer.addOrder(order);
+ this.#customer.calculateBadge();
+ OutputView.printDay(inputDate);
+ OutputView.printOrderDetails(order);
+ OutputView.printBadge(this.#customer);
+ } catch (error) {
+ OutputView.printErrorMessage(error.message);
+ await this.handleMenuOrderProcess(inputDate);
+ }
+ }
+} | JavaScript | ํจ์ ๋ผ์ธ ์๊ฐ ๋ฑ 15๋ผ์ธ์ธ ๊ฒ ๊ฐ๋ค์. ๋ง์ฝ ์ด๋ค ์ถ๋ ฅ์ด ํ๋ ์ถ๊ฐ๋๋ค๋ฉด ์ฌ๊ธฐ์ ์ถ๊ฐํด์ผ ํ ํ
๋ฐ, ๊ทธ๋ฌ๋ฉด ํจ์ ๋ผ์ธ ์๊ฐ 15๋ผ์ธ์ ๋๊ธธ ์๋ ์์ ๊ฒ ๊ฐ์์.
ํจ์ ๋ผ์ธ ์ ์ ํ์ด ์๋ ๊ฒ์ 15๋ผ์ธ์ด๋ผ๋ ๊ฒ ์ค์ํด์๋ผ๊ธฐ๋ณด๋ค ๊ทธ๋งํผ **ํจ์๋ฅผ ์ ๋ถ๋ฆฌํ์** ๋ ์๋ฏธ์ธ ๊ฒ ๊ฐ์ต๋๋ค. ๊ทธ๋์ ํจ์์ ๋ผ์ธ ์๊ฐ ๊ฐ๋น๊ฐ๋นํ๋ค๋ ๊ฒ์, ๋ฆฌํฉํฐ๋ง์ ์ ํธ๊ฐ ์๋๊น ์ถ์ด์๐ค
์ด ๋ฉ์๋๋ ๋์์ ์ฌ๋ฌ ๊ฐ์ง ์ผ์ ์ฒ๋ฆฌํ๊ณ ์๋ ๊ฒ์ฒ๋ผ ๋ณด์ด๋๋ฐ์(์
๋ ฅ ๋ฐ๊ธฐ, ์ฃผ๋ฌธ ์์ฑ, ๊ฐ์ข
ํ ์ธ ์ ์ฉ, ์ถ๋ ฅ, ์
๋ ฅ ์์ธ ์ฒ๋ฆฌ ๋ฐ ์ฌ์
๋ ฅ ๋ฐ๊ธฐ ๋ฑ). ๋ฉ์๋๊ฐ ํ๋์ ์ญํ ๋ง ์ํํ ์ ์๋๋ก ๋ถ๋ฆฌํ๋ ๊ฒ์ ์ด๋จ๊น์? |
@@ -0,0 +1,30 @@
+export default class Customer {
+ #orders;
+
+ #badge;
+
+ static BADGE_CRITERIA = [
+ { name: '์ฐํ', amount: 20000 },
+ { name: 'ํธ๋ฆฌ', amount: 10000 },
+ { name: '๋ณ', amount: 5000 },
+ ];
+
+ constructor() {
+ this.#orders = [];
+ this.#badge = null;
+ }
+
+ addOrder(order) {
+ this.#orders.push(order);
+ }
+
+ calculateBadge() {
+ const totalDiscount = this.#orders.reduce((sum, order) => sum + order.getDiscountAmount(), 0);
+ const badge = Customer.BADGE_CRITERIA.find((badgeName) => totalDiscount >= badgeName.amount);
+ this.#badge = badge ? badge.name : null;
+ }
+
+ getBadge() {
+ return this.#badge;
+ }
+} | JavaScript | ์์๋ฅผ ํ์ผ๋ก ๋ง๋ ๋ค๋ฉด ์์ ์ด ํ์ํ ๋ ์ฐพ๊ธฐ๊ฐ ์์ํ๊ณ , ๋ฐฐ์ง ์ ๋ณด๊ฐ ๋์ด๋๊ฑฐ๋ ์ค์ด๋ค์ด๋ ๊ด๋ฆฌํ๊ธฐ ํธ๋ฆฌํ ๊ฒ ๊ฐ์๋ฐ์. ํ์ผ๋ก ๋ง๋ค์ง ์๊ณ ์ฌ๊ธฐ์ ์์ฑํ์ ์ด์ ๊ฐ ์๋์? |
@@ -0,0 +1,81 @@
+import { OrderConstants } from './constants/OrderConstants';
+
+export default class Order {
+ #menuItems;
+
+ #totalAmount;
+
+ #discountAmount;
+
+ #gift;
+
+ #discountDetails;
+
+ constructor() {
+ this.#menuItems = new Map();
+ this.#totalAmount = 0;
+ this.#discountAmount = 0;
+ this.#gift = null;
+ this.#discountDetails = {};
+ }
+
+ applyDiscounts(discountService, date) {
+ const discountResults = discountService.applyDiscounts(this, date);
+ this.setDiscountDetails(discountResults);
+ this.checkForGift();
+ }
+
+ addMenuItem(menuItem, quantity) {
+ this.#menuItems.set(menuItem.name, { ...menuItem, quantity });
+ this.#totalAmount += menuItem.price * quantity;
+ }
+
+ addDiscountDetail(discountName, discountAmount) {
+ this.#discountDetails[discountName] =
+ (this.#discountDetails[discountName] || 0) + discountAmount;
+ this.#discountAmount += discountAmount;
+ }
+
+ setDiscountDetails(discountDetails) {
+ this.#discountDetails = { ...discountDetails };
+ this.#discountAmount = Object.values(this.#discountDetails).reduce(
+ (sum, amount) => sum + amount,
+ 0,
+ );
+ }
+
+ checkForGift() {
+ if (this.#totalAmount >= OrderConstants.GIFT_THRESHOLD_AMOUNT) {
+ this.#gift = `${OrderConstants.GIFT_NAME} ${OrderConstants.GIFT_QUANTITY}๊ฐ`;
+ }
+ }
+
+ getDiscountDetails() {
+ return this.#discountDetails;
+ }
+
+ getTotalAmount() {
+ return this.#totalAmount;
+ }
+
+ getFinalAmount() {
+ const giftDiscount = this.#discountDetails[OrderConstants.GIFT_EVENT_TITLE] || 0;
+ return this.#totalAmount - (this.#discountAmount - giftDiscount);
+ }
+
+ setDiscountAmount(discountAmount) {
+ this.#discountAmount = discountAmount;
+ }
+
+ getDiscountAmount() {
+ return this.#discountAmount;
+ }
+
+ getItems() {
+ return Array.from(this.#menuItems.values());
+ }
+
+ getGift() {
+ return this.#gift;
+ }
+} | JavaScript | ์ ๋ `Model`์ ์ฆ์ ๋ฉ๋ด์ ๋ํ ์ ๋ณด(๋ฐ์ดํฐ)๋ง ์ ์ฅํ๊ณ , ๊ทธ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ '`์ฆ์ ๋ฉ๋ด` `๊ฐ์`๊ฐ'์ ๊ฐ์ด ํฌ๋งทํ
ํ๋ ๊ฒ์ `View`์ ์ญํ ์ด๋ผ๊ณ ์๊ฐํด์.
๋ง์ฝ ์ฆ์ ๋ฉ๋ด ๋ฐ์ดํฐ์ ๋ํด ๋ค๋ฅธ ํ์์ผ๋ก ์ถ๋ ฅํ๋ ๋ทฐ๊ฐ ์ฌ๋ฌ ๊ฐ ์๊ธด๋ค๊ณ ๊ฐ์ ํด ๋ด
์๋ค. ์ง๊ธ ์ฝ๋๋ฐฉ์๋๋ก๋ผ๋ฉด ๊ฐ ๋ทฐ์์ ๋ํ๋ผ ์ถ๋ ฅ ํ์์ `Model`์์ ์ํํด์ผ ํฉ๋๋ค. ํ์ง๋ง ์ด๊ฑด `Model`์ด `View`์ ์์กดํ๋ ๊ฒ๊ณผ ๊ฐ์ต๋๋ค. ์ถ๋ ฅ ํ์์ด ๋ณ๊ฒฝ๋์์ ๋ `Model`์ ๋ฉ์๋๋ฅผ ๋ณ๊ฒฝํ๊ฒ ๋ ํ
๋๊น์. ๋ `Model`์ ์ญํ ์ ๋ฒ์ด๋๋ ๊ฒ์ด๊ธฐ๋ ํฉ๋๋ค.
๊ทธ๋์ ์ ๋ ์ด ๋ฉ์๋๋ฅผ ์ถ๋ ฅ์ ๋ด๋นํ๋ `View` ์ชฝ์ผ๋ก ์ฎ๊ธฐ๋ ๊ฒ ์ข์ ๊ฒ ๊ฐ์๋ฐ, ์ด๋ป๊ฒ ์๊ฐํ์๋์? |
@@ -0,0 +1,6 @@
+export const OrderConstants = {
+ GIFT_THRESHOLD_AMOUNT: 120000,
+ GIFT_EVENT_TITLE: '์ฆ์ ์ด๋ฒคํธ',
+ GIFT_NAME: '์ดํ์ธ',
+ GIFT_QUANTITY: 1,
+}; | JavaScript | ์ง๊ธ์ ์ฆ์ ์ด๋ฒคํธ๊ฐ ์ดํ์ธ 1๊ฐ๋ง ์ฃผ๊ณ ์๋๋ฐ์. ๋ง์ฝ ์ด ์ด๋ฒคํธ๊ฐ ํ์ฅ๋๋ค๋ฉด, ๋ฐฐ์ง ์ด๋ฒคํธ์ฒ๋ผ ๊ธ์ก์ ๋ฐ๋ผ ๋ค๋ฅธ ์ ๋ฌผ์ ์ฆ์ ํ๊ฒ ๋ ์๋ ์์ ๊ฒ ๊ฐ์์. Strategy ํจํด์ ์ ํํ์ ์ด์ ๋ ์ ์ง๋ณด์์ ๋ณ๊ฒฝ์ ์ฉ์ดํด์๋ผ๊ณ ์๊ฐ๋๋๋ฐ์. ๊ทธ๋งํผ ์์๋ฅผ ์ ์ธํ ๋์๋ ํ์ฅ์ฑ์ ์ฑ๊ธฐ๋ฉด ๋ ์ข์ง ์์์๊น ์๊ฐํด๋ด
๋๋ค! |
@@ -0,0 +1,46 @@
+import ChristmasDiscountStrategy from './strategies/ChristmasDiscountStrategy';
+import WeekdayDiscountStrategy from './strategies/WeekdayDiscountStrategy';
+import WeekendDiscountStrategy from './strategies/WeekendDiscountStrategy';
+import SpecialDiscountStrategy from './strategies/SpecialDiscountStrategy';
+import GiftChampagneStrategy from './strategies/GiftChampagneStrategy';
+
+export default class DiscountService {
+ #strategies;
+
+ constructor() {
+ this.#strategies = {
+ christmas: new ChristmasDiscountStrategy(),
+ special: new SpecialDiscountStrategy(),
+ weekday: new WeekdayDiscountStrategy(),
+ weekend: new WeekendDiscountStrategy(),
+ giftChampagne: new GiftChampagneStrategy(),
+ };
+ }
+
+ applyDiscounts(order, date) {
+ const MINIMUM_AMOUNT_FOR_DISCOUNTS = 10000;
+ if (order.getTotalAmount() >= MINIMUM_AMOUNT_FOR_DISCOUNTS) {
+ const discountResults = this.calculateTotalDiscounts(order, date);
+ const totalDiscountAmount = this.calculateTotalDiscountAmount(discountResults);
+ order.setDiscountAmount(totalDiscountAmount);
+ return discountResults;
+ }
+ return {};
+ }
+
+ calculateTotalDiscounts(order, date) {
+ const discountResults = {};
+ Object.keys(this.#strategies).forEach((strategyKey) => {
+ const strategy = this.#strategies[strategyKey];
+ const discountResult = strategy.applyDiscount(order, date);
+ if (discountResult.amount > 0) {
+ discountResults[discountResult.name] = discountResult.amount;
+ }
+ });
+ return discountResults;
+ }
+
+ calculateTotalDiscountAmount(discountResults) {
+ return Object.values(discountResults).reduce((sum, amount) => sum + amount, 0);
+ }
+} | JavaScript | ์ด ๋ถ๋ถ์ ์ด๋ ๊ฒ ๋ฐ๊ฟ ์ ์์ ๊ฒ ๊ฐ์์!
```javascript
Object.values(this.#strategies).forEach((strategy) => {
const discountResult = strategy.applyDiscount(order, date);
// ...
});
``` |
@@ -0,0 +1,5 @@
+export default class IDiscountStrategy {
+ applyDiscount(order, date) {
+ throw new Error('[ERROR] ํ์ ํด๋์ค์์ applyDiscount ๋ฉ์๋๋ฅผ ๊ตฌํํด์ผ ํฉ๋๋ค.');
+ }
+} | JavaScript | ํ์ผ๋ช
๊ณผ ํด๋์ค๋ช
๋งจ ์์ `I`๊ฐ ๋ถ์ด ์๋๋ฐ, ํน์ ์๋ํ์ ๊ฑด๊ฐ์? ์๋ํ์ ๊ฑฐ๋ผ๋ฉด ์ด๋ค ์๋ฏธ์ธ์ง ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,16 @@
+import IDiscountStrategy from './IDiscountStrategy';
+import { DiscountStrategyConstants } from './constants/DiscountStrategyConstants';
+
+export default class SpecialDiscountStrategy extends IDiscountStrategy {
+ applyDiscount(order, date) {
+ const dayOfWeek = date.getDay();
+ const isSunday = dayOfWeek === 0;
+ const isChristmas = date.getDate() === 25;
+
+ if (isSunday || isChristmas) {
+ return { name: DiscountStrategyConstants.SPECIAL_DISCOUNT, amount: 1000 };
+ }
+
+ return { name: DiscountStrategyConstants.SPECIAL_DISCOUNT, amount: 0 };
+ }
+} | JavaScript | ํน๋ณ ํ ์ธ์ด ๋ชจ๋ ์ผ์์ผ (+25์ผ)์ด๋ผ๋ ์ ์ ์ด์ฉํ์
จ๋ค์!
์ ๋ ๋ณ ํ์๊ฐ ๋ ๋ ์ง๋ฅผ ํ๋ํ๋ ์์ ๋ฐฐ์ด์ ๋ด์์ ๊ด๋ฆฌํ๋๋ฐ์. ์ฎ๊ฒจ ์ ์ ๋ ์คํ๋ผ๋ ๋๋ค๋ฉด ํฐ์ผ์ด์ง๋ง๐
, ์ด๋ ๊ฒ ํ ์ด์ ๋ ํน๋ณ ํ ์ธ ๋ ์ง๊ฐ ๋ณ๊ฒฝ๋ ์ ์์ ๊ฒ ๊ฐ๋ค๊ณ ์๊ฐํ๊ธฐ ๋๋ฌธ์
๋๋ค. ์๊ตฌ์ฌํญ์์ "ํน๋ณ ํ ์ธ"์ ์ค๋ช
ํ ๋, '๋ฌ๋ ฅ์ ๋ณ์ด ํ์๋ ๋ ์ง'๋ผ๊ณ ์ค๋ช
ํ๋๋ผ๊ตฌ์. ๋ง์ฝ '๋ชจ๋ ์ผ์์ผ๊ณผ ํฌ๋ฆฌ์ค๋ง์ค ๋น์ผ'์ฒ๋ผ ์ค๋ช
ํ๋ค๋ฉด ์ ๋ ์ด๋ฐ ์ฝ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ์ ๊ฒ ๊ฐ๋ค์.
๊ตฌํ ๋ฐฉ์์ ์ ๋ต์ ์์ง๋ง ์ ์๊ฐ์ ํ ๋ฒ ๊ณต์ ๋๋ฆฌ๊ณ ์ถ์์ด์๐ |
@@ -0,0 +1,19 @@
+import IDiscountStrategy from './IDiscountStrategy';
+import { DiscountStrategyConstants } from './constants/DiscountStrategyConstants';
+
+export default class WeekdayDiscountStrategy extends IDiscountStrategy {
+ applyDiscount(order, date) {
+ const dayOfWeek = date.getDay();
+ const isWeekday = dayOfWeek >= 0 && dayOfWeek <= 4;
+
+ if (isWeekday) {
+ const DESSERT_DISCOUNT = 2023;
+ const discountAmount = order
+ .getItems()
+ .filter((item) => item.category === 'DESSERTS')
+ .reduce((total, item) => total + item.quantity * DESSERT_DISCOUNT, 0);
+ return { name: DiscountStrategyConstants.WEEKDAY_DISCOUNT, amount: discountAmount };
+ }
+ return { name: DiscountStrategyConstants.WEEKDAY_DISCOUNT, amount: 0 };
+ }
+} | JavaScript | `0`, `4`์ ๊ฐ์ ์ซ์๋ฅผ `SUNDAY`, `THURSDAY`์ฒ๋ผ ์์ํํด์ ์ฌ์ฉํ๋ฉด ์ฝ๋ ๊ฐ๋
์ฑ์ ๋ ์ฑ๊ธธ ์ ์์ ๊ฒ ๊ฐ์์! |
@@ -0,0 +1,36 @@
+import { ValidatorConstants } from './constants/ValidatorConstants';
+
+export const InputValidator = {
+ Day: {
+ validateDay(input) {
+ const dayPattern = /^\d+$/;
+ if (!dayPattern.test(input)) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+ const day = parseInt(input, 10);
+ if (day < 1 || day > 31) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+
+ return day;
+ },
+ },
+
+ Menu: {
+ validateMenu(input) {
+ const menuSelections = input.split(',');
+ const selectionPattern = /^[๊ฐ-ํฃ]+-\d+$/;
+ const validSelections = menuSelections.map((selection) => {
+ const trimmedSelection = selection.trim();
+ if (!selectionPattern.test(trimmedSelection)) {
+ throw new Error(ValidatorConstants.INVALID_ORDER_ERROR);
+ }
+ const [name, quantity] = trimmedSelection.split('-');
+
+ return { name, quantity: parseInt(quantity, 10) };
+ });
+
+ return validSelections;
+ },
+ },
+}; | JavaScript | ๊ฐ๊ฐ์ validation(์ ๊ทํํ์ ํจํด & ๋ฒ์)์ ๋ ๊ฐ์ ํจ์๋ก ๋ถ๋ฆฌํด ์ ์ธํ๊ณ ํธ์ถํด์ ์ฌ์ฉํ๋ ๊ฑด ์ด๋จ๊น์? ์๋ํด์ ํ๊บผ๋ฒ์ ์์ฑํ์ ๊ฒ ๊ฐ์๋ฐ, ๋ง์ฝ ๋ง๋ค๋ฉด ์ด์ ๊ฐ ๊ถ๊ธํด์! |
@@ -0,0 +1,36 @@
+import { ValidatorConstants } from './constants/ValidatorConstants';
+
+export const InputValidator = {
+ Day: {
+ validateDay(input) {
+ const dayPattern = /^\d+$/;
+ if (!dayPattern.test(input)) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+ const day = parseInt(input, 10);
+ if (day < 1 || day > 31) {
+ throw new Error(ValidatorConstants.INVALID_DATE_ERROR);
+ }
+
+ return day;
+ },
+ },
+
+ Menu: {
+ validateMenu(input) {
+ const menuSelections = input.split(',');
+ const selectionPattern = /^[๊ฐ-ํฃ]+-\d+$/;
+ const validSelections = menuSelections.map((selection) => {
+ const trimmedSelection = selection.trim();
+ if (!selectionPattern.test(trimmedSelection)) {
+ throw new Error(ValidatorConstants.INVALID_ORDER_ERROR);
+ }
+ const [name, quantity] = trimmedSelection.split('-');
+
+ return { name, quantity: parseInt(quantity, 10) };
+ });
+
+ return validSelections;
+ },
+ },
+}; | JavaScript | ์ด ๋ก์ง์ด๋ผ๋ฉด ์ด๋ฐ ์
๋ ฅ์ ๋ฃ์ด๋ ์ ์์ ์ผ๋ก ์๋ํ ๊ฒ ๊ฐ์์. ํน์ ๋ค๋ฅธ ๋ถ๋ถ์์ ๊ฒ์ฌํ๊ณ ์๋๋ฐ ์ ๊ฐ ๋์น ๊ฒ์ผ๊น์?
```
๋ฐ๋นํ๋ฆฝ-1,,,,,,,ํํ์ค-2
๋ฐ๋นํ๋ฆฝ-1,,,ํํ์ค-2,,
``` |
@@ -0,0 +1,123 @@
+import { FOOD_MENU } from '../constants/FoodMenu.js';
+import {
+ EVENT_CONST,
+ DAY_OF_WEEK,
+ UTILS_CONST,
+} from '../constants/Constants.js';
+
+class PlannerUtils {
+ #userOrder;
+
+ #userDate;
+
+ #userDay;
+
+ #userEvent;
+
+ constructor(userOrder, userDate) {
+ this.#userOrder = userOrder;
+ this.#userDate = userDate;
+ this.#userDay = new Date(UTILS_CONST.userDay(this.#userDate)).getDay();
+ this.#userEvent = { ...EVENT_CONST };
+ }
+
+ getTotalAmount() {
+ const MENU_COST = {};
+ Object.values(FOOD_MENU).forEach((course) => {
+ Object.values(course).forEach((menu) => {
+ MENU_COST[menu[0]] = menu[1];
+ });
+ });
+ return this.#sumAmount(MENU_COST);
+ }
+
+ #sumAmount(MENU_COST) {
+ const totalAmount = [];
+ this.#userOrder.forEach((order) => {
+ totalAmount.push(MENU_COST[order[0]] * Number(order[1]));
+ });
+ return totalAmount.reduce((total, cost) => total + cost);
+ }
+
+ benefitCheck() {
+ if (this.getTotalAmount() >= UTILS_CONST.minGetBenefit) {
+ this.#userEvent.christmas = this.#christmasCheck();
+ this.#userEvent.weekDay = this.#weekDaysCheck();
+ this.#userEvent.weekendDay = this.#weekendDayCheck();
+ this.#userEvent.specialDay = this.#specialDayCheck();
+ this.#userEvent.benefitEvent = this.#giftCheck();
+ }
+ return this.#userEvent;
+ }
+
+ #christmasCheck() {
+ if (this.#userDate > UTILS_CONST.christmasEventEnd) {
+ return UTILS_CONST.noBenefit;
+ }
+ return UTILS_CONST.christmasBenefit(this.#userDate);
+ }
+
+ #weekDaysCheck() {
+ if (DAY_OF_WEEK.weekDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekDayEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #weekendDayCheck() {
+ if (DAY_OF_WEEK.weekendDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekendEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #specialDayCheck() {
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDay)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDate)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #giftCheck() {
+ if (this.getTotalAmount() > UTILS_CONST.minGetGift) {
+ return UTILS_CONST.giftCost;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #checkEventMenu(event) {
+ const numberOfMenu = [0];
+ const eventMenu = Object.values(FOOD_MENU[event]).map((menu) => menu[0]);
+ this.#userOrder.forEach((menu) => {
+ if (eventMenu.includes(menu[0])) {
+ numberOfMenu.push(Number(menu[1]));
+ }
+ });
+ return numberOfMenu.reduce((total, amount) => total + amount);
+ }
+
+ calcBenefitAmount() {
+ const totalBenefit = Object.values(this.#userEvent).reduce(
+ (total, amount) => total + amount,
+ );
+ return totalBenefit;
+ }
+
+ calcTotalPayment() {
+ if (this.#userEvent.benefitEvent !== 0) {
+ return (
+ this.getTotalAmount() - this.calcBenefitAmount() + UTILS_CONST.giftCost
+ );
+ }
+ return this.getTotalAmount() - this.calcBenefitAmount();
+ }
+}
+
+export default PlannerUtils; | JavaScript | ์ด๊ฑด ์ ๋ง ์ ์ ๊ฐ์ธ์ ์ธ ์๊ฐ์
๋๋ค๋ง, ํ๋์ ํด๋์ค์์ ๋๋ฌด ๋ง์ ์ผ์ ๋ด๋นํ๊ณ ์๋ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋ค์์ต๋๋ค..! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | ์ด๊ฑด ์ง์ง ์ฌ์ํ ๊ฑฐ๊ธดํ๋ฐ, ๋ณ์ ์ค์ #regax ๊ฐ ์๋๋ฐ ์ ๊ทํํ์์ ๋ํ๋ด๋ ๊ฑฐ๋ผ๊ณ ์๊ฐํ๋๋ฐ, ํน์ ๋ง๋ค๋ฉด regular expression => regex ๊ฐ ์ข์ง ์์๊น! ์๊ฐํด๋ดค์ต๋๋ค! ์๋ง ์คํ์ด์ ๊ฑฐ ๊ฐ๊ธฐ๋ํ๊ตฌ..!? |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | Number.isInteger ๋ง ์์์ง, Number.isSafeInteger ๋ผ๋ ๋ฉ์๋๊ฐ ์๋ ์ค์ ์ ๋ง ๋ชฐ๋๋๋ฐ, ๋๋ถ์ ์ด๋ ๊ฒ ๋ ํ๋ ์์๊ฐ์! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | rangeCheck๋ฉ์๋์์ ๋ ์ง๋ฅผ ๋ํ๋ด๋ ์ซ์ 0, 31๋ ์์์ฒ๋ฆฌํด์ ๊ฐ์ ธ์ค๋ฉด ๋์ค์ ๋ณ๊ฒฝํ ๋ ๋ ํธ๋ฆฌํ์ง ์์๊น ์ถ์์ต๋๋ค! |
@@ -0,0 +1,125 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+import { FOOD_MENU } from '../../constants/FoodMenu.js';
+
+class MenuValidate {
+ #canOrder;
+
+ #userMenu;
+
+ #menu;
+
+ constructor(menu, canOrder = [], userMenu = []) {
+ this.#menu = menu;
+ this.#canOrder = canOrder;
+ this.#userMenu = userMenu;
+ }
+
+ menuCheck() {
+ this.#findingMenu(this.#canOrder, this.#userMenu, this.#menu);
+ this.#userMenu.forEach((order) => {
+ if (!this.#canOrder.includes(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ });
+ }
+
+ #findingMenu() {
+ Object.keys(FOOD_MENU).map((course) =>
+ this.#makeCanOrder(course, this.#canOrder),
+ );
+
+ this.#menu.forEach((order) => this.#userMenu.push(order.split('-')[0]));
+ }
+
+ #makeCanOrder(course) {
+ Object.values(FOOD_MENU[`${course}`]).map((food) =>
+ this.#canOrder.push(food[0]),
+ );
+ }
+
+ menuAmountCheck(regax) {
+ const totalMenuAmount = [];
+ this.#menu.forEach((order) => {
+ this.#amountCheck(order.split('-')[1], regax);
+ totalMenuAmount.push(Number(order.split('-')[1]));
+ });
+
+ this.#totalAmountCheck(totalMenuAmount);
+ }
+
+ #amountCheck(amount, regax) {
+ if (regax.test(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ if (Number(amount) <= 0) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+
+ if (!Number.isSafeInteger(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ #totalAmountCheck(total) {
+ const checkTotal = total.reduce((sum, amount) => sum + amount);
+ if (checkTotal > 20) {
+ throw new Error(ERROR_MSG.totalError);
+ }
+ }
+
+ formCheck() {
+ const form = /^[๊ฐ-ํฃ]+-[0-9]+$/;
+ this.#menu.forEach((order) => this.#formRegaxCheck(order, form));
+ }
+
+ #formRegaxCheck(order, form) {
+ if (!form.test(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ duplicateCheck() {
+ if (this.#userMenu.length !== new Set(this.#userMenu).size) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ drinkCheck() {
+ const menuObject = this.#makingMenuObject();
+ if (this.#objectCheck(menuObject)) {
+ throw new Error(ERROR_MSG.drinkError);
+ }
+ }
+
+ #makingMenuObject() {
+ const menuObject = {};
+ Object.keys(FOOD_MENU).forEach((course) => {
+ menuObject[course] = this.#userMenuCourses(course);
+ });
+ return menuObject;
+ }
+
+ #userMenuCourses(course) {
+ const includeCourse = [];
+ Object.values(FOOD_MENU[course]).forEach((eachMenu) => {
+ if (this.#menuIncludes(eachMenu)) {
+ includeCourse.push(eachMenu[0]);
+ }
+ });
+ return includeCourse.length;
+ }
+
+ #menuIncludes(eachMenu) {
+ return this.#userMenu.includes(eachMenu[0]);
+ }
+
+ #objectCheck(menuObject) {
+ const { appetizer, main, dessert, drink } = menuObject;
+ if (appetizer === 0 && main === 0 && dessert === 0 && drink !== 0) {
+ return true;
+ }
+ return false;
+ }
+}
+
+export default MenuValidate; | JavaScript | ๋ฐฐ์ด์ ์์ฃผ ์ฌ์ฉํ์ ๊ฒ ๊ฐ์์! ์ ๋ ์ด๋ฒ์ ๋ฏธ์
ํ๋ฉด์ Array ๋ Map ์ค์์ ์ด๋ค ๊ฑธ ์ฌ์ฉํ ์ง ๊ณ ๋ฏผํ์๋๋ฐ์, ์ ํํ
๋ ์ฌ์ค Map ์ด ์ต์ํ ๊ฐ๋
์ ์๋์ฌ์ ๋ฐฑ์๋๋ถ๋คํํ
๋ฌผ์ด๋ดค๋๋ฐ ๋ชจ๋ ๋ฐฐ์ด๊ณผ ๋งต ๋ ์ค์ ๊ณจ๋ผ์ผํ๋ค๋ฉด ๋งต์ด ๋ ํจ์จ์ ์ด๋ผ๊ณ ํ์๋๋ผ๊ตฌ์! ๋ฐฐ์ด๋ index๋ก ๊ฐ์ ๊ฐ์ ธ์ฌ ์ ์๊ณ , Map ๋ key๋ก ๊ฐ์ ๊ฐ์ ธ์ค๋๋ฐ, ๋ฐฐ์ด์ ํด๋นindex๊น์ง 0๋ถํฐ ์์ํด์ผํ๋ค๊ณ ํ๋๋ผ๊ตฌ์. ๋ฐ๋ฉด์ ๋งต์ ํ๋ฒ์ ๊ฐ์ ๊ฐ์ ธ์์ ์๊ฐ๋ณต์ก๋๊ฐ O(1) ์ด๋ผ๊ณ ํฉ๋๋ค! |
@@ -0,0 +1,132 @@
+/* eslint-disable max-lines-per-function */
+import PlannerUtils from '../../src/domain/utils/PlannerUtills.js';
+import PlannerData from '../../src/domain/model/PlannerData.js';
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const testCases = [
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5'], day: 25, expected: 275000 },
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ ๋ก์ฝ๋ผ-5', '์์ด์คํฌ๋ฆผ-5'],
+ day: 1,
+ expected: 275000 + 15000 + 25000,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`์ด ๊ธ์ก ํ
์คํธ : ${testCase.menu}`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ expect(plannerUtil.getTotalAmount()).toBe(testCase.expected);
+ });
+ });
+});
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const expectedObj = {
+ christmas: 3400,
+ weekDay: 4046,
+ weekendDay: 0,
+ specialDay: 1000,
+ benefitEvent: 25000,
+ };
+
+ const testCases = [
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: 25,
+ expected: expectedObj,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`ํํ ํ
์คํธ : ${testCase.menu}`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ expect(plannerUtil.benefitCheck()).toStrictEqual(testCase.expected);
+ });
+ });
+});
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const testCases = [
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '25',
+ expected: 3400 + 4046 + 1000 + 25000,
+ },
+ {
+ menu: ['์์ด์คํฌ๋ฆผ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '21',
+ expected: 3000 + 14161,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`์ด ํํ๊ธ์ก ํ
์คํธ : ${testCase.day}์ผ`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ plannerUtil.benefitCheck();
+ expect(plannerUtil.calcBenefitAmount()).toBe(testCase.expected);
+ });
+ });
+});
+
+describe('์ ํธ ํ
์คํธ', () => {
+ const testCases = [
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '25',
+ discount: 3400 + 4046 + 1000,
+ },
+ {
+ menu: ['์์ด์คํฌ๋ฆผ-5', '์ด์ฝ์ผ์ดํฌ-2'],
+ day: '21',
+ discount: 3000 + 14161,
+ },
+ {
+ menu: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1', '๋ ๋์์ธ-1', '์ด์ฝ์ผ์ดํฌ-1'],
+ day: '12',
+ discount: 2100 + 2023,
+ },
+ {
+ menu: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1', '๋ ๋์์ธ-1', '์ด์ฝ์ผ์ดํฌ-1'],
+ day: '26',
+ discount: 2023,
+ },
+ {
+ menu: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ-1', '๋ ๋์์ธ-1'],
+ day: '26',
+ discount: 0,
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`ํ ์ธ ํ ์์ ๊ฒฐ์ ๊ธ์ก : ${testCase.day}์ผ`, () => {
+ const PLANNER_DATA = new PlannerData();
+ PLANNER_DATA.updateDate(testCase.day);
+ PLANNER_DATA.updateFood(testCase.menu);
+ const plannerUtil = new PlannerUtils(
+ PLANNER_DATA.getUserOrder(),
+ PLANNER_DATA.getDate(),
+ );
+ plannerUtil.benefitCheck();
+ const expected = plannerUtil.getTotalAmount() - testCase.discount;
+ expect(plannerUtil.calcTotalPayment()).toBe(expected);
+ });
+ });
+}); | JavaScript | ์ ๋ ํ
์คํธ์ฝ๋๋ฅผ ์ง๋๊ฒ ๋๋ฌด ์ด๋ ค์ ์ด์,, ๋ง์ ์ฐธ๊ณ ๊ฐ ๋ผ์ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,123 @@
+import { FOOD_MENU } from '../constants/FoodMenu.js';
+import {
+ EVENT_CONST,
+ DAY_OF_WEEK,
+ UTILS_CONST,
+} from '../constants/Constants.js';
+
+class PlannerUtils {
+ #userOrder;
+
+ #userDate;
+
+ #userDay;
+
+ #userEvent;
+
+ constructor(userOrder, userDate) {
+ this.#userOrder = userOrder;
+ this.#userDate = userDate;
+ this.#userDay = new Date(UTILS_CONST.userDay(this.#userDate)).getDay();
+ this.#userEvent = { ...EVENT_CONST };
+ }
+
+ getTotalAmount() {
+ const MENU_COST = {};
+ Object.values(FOOD_MENU).forEach((course) => {
+ Object.values(course).forEach((menu) => {
+ MENU_COST[menu[0]] = menu[1];
+ });
+ });
+ return this.#sumAmount(MENU_COST);
+ }
+
+ #sumAmount(MENU_COST) {
+ const totalAmount = [];
+ this.#userOrder.forEach((order) => {
+ totalAmount.push(MENU_COST[order[0]] * Number(order[1]));
+ });
+ return totalAmount.reduce((total, cost) => total + cost);
+ }
+
+ benefitCheck() {
+ if (this.getTotalAmount() >= UTILS_CONST.minGetBenefit) {
+ this.#userEvent.christmas = this.#christmasCheck();
+ this.#userEvent.weekDay = this.#weekDaysCheck();
+ this.#userEvent.weekendDay = this.#weekendDayCheck();
+ this.#userEvent.specialDay = this.#specialDayCheck();
+ this.#userEvent.benefitEvent = this.#giftCheck();
+ }
+ return this.#userEvent;
+ }
+
+ #christmasCheck() {
+ if (this.#userDate > UTILS_CONST.christmasEventEnd) {
+ return UTILS_CONST.noBenefit;
+ }
+ return UTILS_CONST.christmasBenefit(this.#userDate);
+ }
+
+ #weekDaysCheck() {
+ if (DAY_OF_WEEK.weekDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekDayEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #weekendDayCheck() {
+ if (DAY_OF_WEEK.weekendDay.includes(this.#userDay)) {
+ return (
+ this.#checkEventMenu(UTILS_CONST.weekendEvent) * UTILS_CONST.discount
+ );
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #specialDayCheck() {
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDay)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ if (DAY_OF_WEEK.specialDay.includes(this.#userDate)) {
+ return UTILS_CONST.specialDiscount;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #giftCheck() {
+ if (this.getTotalAmount() > UTILS_CONST.minGetGift) {
+ return UTILS_CONST.giftCost;
+ }
+ return UTILS_CONST.noBenefit;
+ }
+
+ #checkEventMenu(event) {
+ const numberOfMenu = [0];
+ const eventMenu = Object.values(FOOD_MENU[event]).map((menu) => menu[0]);
+ this.#userOrder.forEach((menu) => {
+ if (eventMenu.includes(menu[0])) {
+ numberOfMenu.push(Number(menu[1]));
+ }
+ });
+ return numberOfMenu.reduce((total, amount) => total + amount);
+ }
+
+ calcBenefitAmount() {
+ const totalBenefit = Object.values(this.#userEvent).reduce(
+ (total, amount) => total + amount,
+ );
+ return totalBenefit;
+ }
+
+ calcTotalPayment() {
+ if (this.#userEvent.benefitEvent !== 0) {
+ return (
+ this.getTotalAmount() - this.calcBenefitAmount() + UTILS_CONST.giftCost
+ );
+ }
+ return this.getTotalAmount() - this.calcBenefitAmount();
+ }
+}
+
+export default PlannerUtils; | JavaScript | ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค!
`์ฌ๊ธฐ์ ํ์ผ์ด ๋ฐ๋ก ์ ๋ณด์ด๋๋ฐ, ์ ์ PR ๋ก ๋ดค์์ ๋, App.js ์์ #PLANNER ์ด๋ ๊ฒ ์ฌ์ฉํ์
จ๋๋ฐ, ํน์ ๋๋ฌธ์๋ก ใ
ํ์ ์ด์ ๊ฐ ์์ผ์ ๊ฐ์๏ผ๏ผ`
๊ฐ์ธ์ ์ผ๋ก ์์ฑ์์์ ์ ์๋๋ ํด๋์ค๋ ๊ตฌ๋ถ์ ๋ช
ํํ ํ๊ธฐ์ํด ๋๋ฌธ์๋ฅผ ์ฌ์ฉํ์ต๋๋ค! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | ์ MVCํจํด ์์์๋ง ์์ํ๋ฅผ ์๊ฐํ์ง ์ด๋ถ๋ถ์ ๊น๋นกํ๋ค์..! ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,28 @@
+import DateValidate from './validator/DateValidate.js';
+import MenuValidate from './validator/MenuValidate.js';
+
+class InputValidator {
+ #REGAX;
+
+ constructor() {
+ this.#REGAX = /\s|[!@#$%^&*(),?":{}|<>]|[a-zA-Z]/;
+ }
+
+ async dateValidate(date) {
+ const dateValidator = new DateValidate(this.#REGAX, date);
+ dateValidator.regaxCheck();
+ dateValidator.safeCheck();
+ dateValidator.rangeCheck();
+ }
+
+ async menuValidate(menu) {
+ const menuValidator = new MenuValidate(menu);
+ menuValidator.menuCheck();
+ menuValidator.menuAmountCheck(this.#REGAX);
+ menuValidator.formCheck();
+ menuValidator.duplicateCheck();
+ menuValidator.drinkCheck();
+ }
+}
+
+export default InputValidator; | JavaScript | ์ ๊ท์์ผ๋ก ์ ํจ์ฑ ๊ฒ์ฌ ๋ก์ง์ ๊ฐ๊ฒฐํ๊ฒ ํํํ์ผ๋ฉด ์ข์์ ๊ฑฐ๋ ๋ฆฌ๋ทฐ๋ฅผ ๋ฐ์ ์
์ฅ์ผ๋ก์.. ์ ๊ท์ ์ฌ์ฉ์ ๊น๋ํ์ ์ ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค ๐๐ป |
@@ -0,0 +1,34 @@
+export const EVENT_CONST = {
+ christmas: 0,
+ weekDay: 0,
+ weekendDay: 0,
+ specialDay: 0,
+ benefitEvent: 0,
+};
+
+export const DAY_OF_WEEK = {
+ sun: 0,
+ mon: 1,
+ tue: 2,
+ wed: 3,
+ thu: 4,
+ fri: 5,
+ sat: 6,
+ weekDay: [0, 1, 2, 3, 4],
+ weekendDay: [5, 6],
+ specialDay: [0, 25],
+};
+
+export const UTILS_CONST = {
+ userDay: (userDate) => `2023-12-${userDate}`,
+ christmasBenefit: (userDate) => 1000 + (userDate - 1) * 100,
+ minGetBenefit: 10000,
+ christmasEventEnd: 25,
+ noBenefit: 0,
+ discount: 2023,
+ weekDayEvent: 'dessert',
+ weekendEvent: 'main',
+ specialDiscount: 1000,
+ minGetGift: 120000,
+ giftCost: 25000,
+}; | JavaScript | ์ด๋ฏธ ์์ ์ ์ธ์ผ๋ก const ๋ผ๋ ๋จ์ด๋ ๋ดํฌํ ์ ์๋ค๊ณ ์๊ฐํด์! UTILS, EVENT ๋ก ์ ์ธํ๊ณ ๋ด๋ถ ์์๋ค์ ๋ช
์นญ์ ๋ ๊ตฌ์ฒด์ ์ผ๋ก ์์ฑํ์๋ ๋ฐฉ๋ฒ๋ ์ข์์๊ฑฐ๋ผ๊ตฌ ์๊ฐํฉ๋๋ค ใ
ใ
|
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ธํ์ ๋ฐ๋ ๊ตฌ์กฐ๊ฐ ์ ์ฌํ๋, ์ธํ ํธ๋ค๋ง๊ณผ ํธ๋ผ์ด ์บ์น ์ฌ์ฉ์ ์ค๋ณต์ ํ๋์ ๋ฉ์๋๋ก ๋ฐ๋ก ์ ์ธํ๊ณ ํ์ฉํ๋ ๋ฐฉ์๋ ์ข์ ๋ฐฉ๋ฒ์ด๋๋ผ๊ตฌ์ ์ถ์ฒ๋๋ฆฌ๊ตฌ ๊ฐ๋๋ค ๐๐ป |
@@ -0,0 +1,21 @@
+import { Console } from '@woowacourse/mission-utils';
+import { INPUT_MSG } from '../constants/PlannerMsg.js';
+import InputValidator from '../utils/InputValidator.js';
+
+const InputView = {
+ INPUT_VAL: new InputValidator(),
+
+ async readDate() {
+ const userDate = await Console.readLineAsync(INPUT_MSG.inputVisitDay);
+ await this.INPUT_VAL.dateValidate(userDate);
+ return userDate;
+ },
+
+ async readMenu() {
+ const userMenu = await Console.readLineAsync(INPUT_MSG.orderMenu);
+ await this.INPUT_VAL.menuValidate(userMenu.split(','));
+ return userMenu.split(',');
+ },
+};
+
+export default InputView; | JavaScript | ์ธํ ์ ํจ์ฑ ๊ฒ์ฌ์ ๋ํ ํด๋์ค๋ฅผ ๋ฐ๋ก ์ ์ธํ์
์ ๋ทฐ์์ ํธ์ถํ๋ ๋ฐฉ์์ด ๋ ์๋กญ๋ค์ !! ์ ๋ ์ธํ ๋ฐ๋ ๋ด๋ถ์์ ๊ตฌํํ๊ณ , ๋ถ๋ฆฌํด์ผ ํ๋ค๋ ์๊ฐ๋ง ํ์๋๋ฐ ์ด ๋ฐฉ์๋ ํจ์จ์ ์ธ๊ฑฐ ๊ฐ์์ โบ๏ธ |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ฌ๊ฒฝ๋ ์ฝ๋๋ณด๊ณ ์ ๋ ์ญ์ ์ค์ฌ์ผ๊ฒ ๋ค ์๊ฐํ์ต๋๋ค!
์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ ๋ ์ ๋ฒ์๋ catch๋ถ๋ฌธ์ ๋ค์ inputVisitDay๋ฅผ ์คํํ๋ฉด ์ฌ๊ท์ ์ผ๋ก ์ฒ๋ฆฌ๋์ด ํ
์คํธ๊ฐ ํต๊ณผ๊ฐ ์ ๋๋๋ฐ @JonghyunLEE12 ๋์ inputVisitDay๋ฅผ ๋ฐ๋ก returnํ๋๊ฑธ๋ก ํด๊ฒฐํ์
จ๋ค์. ์ด๋ฒ์ ์ ๋ while(true) ๊ตฌ๋ฌธ ์์์ validํ ์
๋ ฅ๊ฐ์ ๋ฐ์ผ๋ฉด while์ ๋๊ฐ๋ ๊ฒ์ผ๋ก ์์ฑํด๋ดค๋๋ฐ ๊ฐ์ธ์ ์ผ๋ก ๋ ๊น๋ํ ์ฒ๋ฆฌ๋ผ๊ณ ์๊ฐ์ด ๋ค๋๋ผ๊ณ ์ ํ๋ฒ ์ฐธ๊ณ ํด๋ณด์
๋ ์ข์ ๊ฒ ๊ฐ์์ |
@@ -0,0 +1,125 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+import { FOOD_MENU } from '../../constants/FoodMenu.js';
+
+class MenuValidate {
+ #canOrder;
+
+ #userMenu;
+
+ #menu;
+
+ constructor(menu, canOrder = [], userMenu = []) {
+ this.#menu = menu;
+ this.#canOrder = canOrder;
+ this.#userMenu = userMenu;
+ }
+
+ menuCheck() {
+ this.#findingMenu(this.#canOrder, this.#userMenu, this.#menu);
+ this.#userMenu.forEach((order) => {
+ if (!this.#canOrder.includes(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ });
+ }
+
+ #findingMenu() {
+ Object.keys(FOOD_MENU).map((course) =>
+ this.#makeCanOrder(course, this.#canOrder),
+ );
+
+ this.#menu.forEach((order) => this.#userMenu.push(order.split('-')[0]));
+ }
+
+ #makeCanOrder(course) {
+ Object.values(FOOD_MENU[`${course}`]).map((food) =>
+ this.#canOrder.push(food[0]),
+ );
+ }
+
+ menuAmountCheck(regax) {
+ const totalMenuAmount = [];
+ this.#menu.forEach((order) => {
+ this.#amountCheck(order.split('-')[1], regax);
+ totalMenuAmount.push(Number(order.split('-')[1]));
+ });
+
+ this.#totalAmountCheck(totalMenuAmount);
+ }
+
+ #amountCheck(amount, regax) {
+ if (regax.test(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ if (Number(amount) <= 0) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+
+ if (!Number.isSafeInteger(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ #totalAmountCheck(total) {
+ const checkTotal = total.reduce((sum, amount) => sum + amount);
+ if (checkTotal > 20) {
+ throw new Error(ERROR_MSG.totalError);
+ }
+ }
+
+ formCheck() {
+ const form = /^[๊ฐ-ํฃ]+-[0-9]+$/;
+ this.#menu.forEach((order) => this.#formRegaxCheck(order, form));
+ }
+
+ #formRegaxCheck(order, form) {
+ if (!form.test(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ duplicateCheck() {
+ if (this.#userMenu.length !== new Set(this.#userMenu).size) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ drinkCheck() {
+ const menuObject = this.#makingMenuObject();
+ if (this.#objectCheck(menuObject)) {
+ throw new Error(ERROR_MSG.drinkError);
+ }
+ }
+
+ #makingMenuObject() {
+ const menuObject = {};
+ Object.keys(FOOD_MENU).forEach((course) => {
+ menuObject[course] = this.#userMenuCourses(course);
+ });
+ return menuObject;
+ }
+
+ #userMenuCourses(course) {
+ const includeCourse = [];
+ Object.values(FOOD_MENU[course]).forEach((eachMenu) => {
+ if (this.#menuIncludes(eachMenu)) {
+ includeCourse.push(eachMenu[0]);
+ }
+ });
+ return includeCourse.length;
+ }
+
+ #menuIncludes(eachMenu) {
+ return this.#userMenu.includes(eachMenu[0]);
+ }
+
+ #objectCheck(menuObject) {
+ const { appetizer, main, dessert, drink } = menuObject;
+ if (appetizer === 0 && main === 0 && dessert === 0 && drink !== 0) {
+ return true;
+ }
+ return false;
+ }
+}
+
+export default MenuValidate; | JavaScript | ๋ฉ๋ด ์ ๊ทํํ์์ ์ ์์ฑํ์
จ๋๋ฐ ๋ฉ๋ด๊ฐฏ์๋ ์ฒซ ์ซ์๋ก 0์ด ๋ค์ด๊ฐ๋๊ฑธ ๋ฐฉ์งํ๊ธฐ ์ํด [0-9]+๋ ๋ณด๋ค [1-9]\d*๊ฐ ๋ ์ ์ ํ์ง ์์๊น ์ถ์ต๋๋ค. (์ฒซ ์ซ์๋ 1์์9๋ง ๊ฐ๋ฅํ๊ณ ๋ท ์ซ์๋ ๋ญ ๋ 0๊ฐ ์ด์ ์ด๋ฐ์์ผ๋ก์) |
@@ -0,0 +1,60 @@
+/* eslint-disable max-lines-per-function */
+import InputValidator from '../../src/domain/utils/InputValidator.js';
+
+describe('๋ ์ง ํ
์คํธ', () => {
+ const userInput = new InputValidator();
+ const testCases = [
+ { date: 'a', expectedError: '[ERROR]' },
+ { date: ' ', expectedError: '[ERROR]' },
+ { date: '์ด์ญ์ค์ผ', expectedError: '[ERROR]' },
+ { date: '32', expectedError: '[ERROR]' },
+ { date: '0', expectedError: '[ERROR]' },
+ { date: '25.5', expectedError: '[ERROR]' },
+ { date: '-1', expectedError: '[ERROR]' },
+ { date: ' 12', expectedError: '[ERROR]' },
+ { date: '1 2', expectedError: '[ERROR]' },
+ { date: '12 ', expectedError: '[ERROR]' },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`๋ ์ง ํ
์คํธ, ๋ ์ง: ${testCase.date}`, async () => {
+ await expect(userInput.dateValidate(testCase.date)).rejects.toThrow(
+ testCases.expectedError,
+ );
+ });
+ });
+});
+
+describe('๋ฉ๋ด ํ
์คํธ', () => {
+ const menuValidate = new InputValidator();
+ const testCases = [
+ { menu: ['์งฌ๋ฝ-1'], expectedError: '[ERROR]' },
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-0'], expectedError: '[ERROR]' },
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-1.5'], expectedError: '[ERROR]' },
+ { menu: ['ํฐ๋ณธ์คํ
์ดํฌ-a'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ1', '๋ ๋์์ธ1'], expectedError: '[ERROR]' },
+ { menu: ['๊น๋ฐฅ-1', '๋ก๋ณถ์ด-1'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ-์ผ', '๋ ๋์์ธ-์ด'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ-a', '๋ ๋์์ธ-b'], expectedError: '[ERROR]' },
+ { menu: ['ํด์ฐ๋ฌผํ์คํ-2', 'ํด์ฐ๋ฌผํ์คํ-1'], expectedError: '[ERROR]' },
+ { menu: ['์ ๋ก์ฝ๋ผ-1'], expectedError: '[ERROR]' },
+ { menu: ['๋ ๋์์ธ-1', '์ ๋ก์ฝ๋ผ-1'], expectedError: '[ERROR]' },
+ { menu: ['์์ ์๋ฌ๋- 1', '์ ๋ก์ฝ๋ผ- 1'], expectedError: '[ERROR]' },
+ {
+ menu: ['๋ ๋์์ธ-2', '์ ๋ก์ฝ๋ผ-2', '์ดํ์ธ-2'],
+ expectedError: '[ERROR]',
+ },
+ {
+ menu: ['ํฐ๋ณธ์คํ
์ดํฌ-10', '๋ ๋์์ธ-20', '์ ๋ก์ฝ๋ผ-20'],
+ expectedError: '[ERROR]',
+ },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`๋ฉ๋ด ํ
์คํธ, ๋ฉ๋ด: ${testCase.menu}`, async () => {
+ await expect(menuValidate.menuValidate(testCase.menu)).rejects.toThrow(
+ testCase.expectedError,
+ );
+ });
+ });
+}); | JavaScript | ์ด์ญ์ค์ผใ
ใ
ํ
์คํธ์ฝ๋๋ฅผ ์ ๋ง ์์ธํ๊ฒ ์ง์
จ๋ค์ ๋ง์ด ๋ฐฐ์ฐ๊ณ ๊ฐ๋๋ค! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | ๊ฐ์ธ์ ์ผ๋ก this.#regax๋ฅผ ํ๋๋ก ๋์ ์ด์ ๊ฐ ๊ถ๊ธํฉ๋๋ค. ์์ํํด์ ๋ฐ๋ก ๊ฐ์ ธ์ ์ฐ์์ง์๊ณ new DateValidate()ํ ๋ regex๋ฅผ ์ ๋ฌํ์ ๋ค๋ฅธ์ด์ ๊ฐ ์์๊น์? |
@@ -0,0 +1,125 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+import { FOOD_MENU } from '../../constants/FoodMenu.js';
+
+class MenuValidate {
+ #canOrder;
+
+ #userMenu;
+
+ #menu;
+
+ constructor(menu, canOrder = [], userMenu = []) {
+ this.#menu = menu;
+ this.#canOrder = canOrder;
+ this.#userMenu = userMenu;
+ }
+
+ menuCheck() {
+ this.#findingMenu(this.#canOrder, this.#userMenu, this.#menu);
+ this.#userMenu.forEach((order) => {
+ if (!this.#canOrder.includes(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ });
+ }
+
+ #findingMenu() {
+ Object.keys(FOOD_MENU).map((course) =>
+ this.#makeCanOrder(course, this.#canOrder),
+ );
+
+ this.#menu.forEach((order) => this.#userMenu.push(order.split('-')[0]));
+ }
+
+ #makeCanOrder(course) {
+ Object.values(FOOD_MENU[`${course}`]).map((food) =>
+ this.#canOrder.push(food[0]),
+ );
+ }
+
+ menuAmountCheck(regax) {
+ const totalMenuAmount = [];
+ this.#menu.forEach((order) => {
+ this.#amountCheck(order.split('-')[1], regax);
+ totalMenuAmount.push(Number(order.split('-')[1]));
+ });
+
+ this.#totalAmountCheck(totalMenuAmount);
+ }
+
+ #amountCheck(amount, regax) {
+ if (regax.test(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ if (Number(amount) <= 0) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+
+ if (!Number.isSafeInteger(Number(amount))) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ #totalAmountCheck(total) {
+ const checkTotal = total.reduce((sum, amount) => sum + amount);
+ if (checkTotal > 20) {
+ throw new Error(ERROR_MSG.totalError);
+ }
+ }
+
+ formCheck() {
+ const form = /^[๊ฐ-ํฃ]+-[0-9]+$/;
+ this.#menu.forEach((order) => this.#formRegaxCheck(order, form));
+ }
+
+ #formRegaxCheck(order, form) {
+ if (!form.test(order)) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ duplicateCheck() {
+ if (this.#userMenu.length !== new Set(this.#userMenu).size) {
+ throw new Error(ERROR_MSG.notInMenu);
+ }
+ }
+
+ drinkCheck() {
+ const menuObject = this.#makingMenuObject();
+ if (this.#objectCheck(menuObject)) {
+ throw new Error(ERROR_MSG.drinkError);
+ }
+ }
+
+ #makingMenuObject() {
+ const menuObject = {};
+ Object.keys(FOOD_MENU).forEach((course) => {
+ menuObject[course] = this.#userMenuCourses(course);
+ });
+ return menuObject;
+ }
+
+ #userMenuCourses(course) {
+ const includeCourse = [];
+ Object.values(FOOD_MENU[course]).forEach((eachMenu) => {
+ if (this.#menuIncludes(eachMenu)) {
+ includeCourse.push(eachMenu[0]);
+ }
+ });
+ return includeCourse.length;
+ }
+
+ #menuIncludes(eachMenu) {
+ return this.#userMenu.includes(eachMenu[0]);
+ }
+
+ #objectCheck(menuObject) {
+ const { appetizer, main, dessert, drink } = menuObject;
+ if (appetizer === 0 && main === 0 && dessert === 0 && drink !== 0) {
+ return true;
+ }
+ return false;
+ }
+}
+
+export default MenuValidate; | JavaScript | ์ ์ด๋ถ๋ถ์ ์ ๊ฐ ์ ์ถํ๊ณ ๋์ ๊นจ๋ฌ์๋ค์ใ
ใ
์ ๋ ์ฐธ ์์ฝ์ต๋๋ค. ์ข์ ์๊ฒฌ ๊ฐ์ฌํฉ๋๋ค! |
@@ -0,0 +1,32 @@
+import { ERROR_MSG } from '../../constants/PlannerMsg.js';
+
+class DateValidate {
+ #regax;
+
+ #date;
+
+ constructor(regax, date) {
+ this.#regax = regax;
+ this.#date = date;
+ }
+
+ regaxCheck() {
+ if (this.#regax.test(this.#date)) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ safeCheck() {
+ if (!Number.isSafeInteger(Number(this.#date))) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+
+ rangeCheck() {
+ if (Number(this.#date) <= 0 || Number(this.#date) > 31) {
+ throw new Error(ERROR_MSG.dateError);
+ }
+ }
+}
+
+export default DateValidate; | JavaScript | InputValidate ํด๋์ค์์ Date ์ Menu ์ ๋ํด ๋๊ฐ์ง ๊ฒ์ฌ๋ฅผ ์ ์ํด์คฌ์ต๋๋ค!
์ฐ์ ์ ์ฒด์ ์ธ ์ ๊ทํํ์์ ์์์์ ์ ์ํ๊ณ ํ์ ๊ฐ์ฒด๋ค์๊ฒ ์ ๋ฌํด์ฃผ๋ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ๋๋ฐ์.
MenuValidate ์์๋ form ์ด๋ผ๋ ์ ๊ทํํ์์ด ๋ ์กด์ฌํ๊ธฐ ๋๋ฌธ์, ํ ๊ฐ์ฒด ์์ ๋ค๋ฅธ ์ ๊ทํํ์์ด ์กด์ฌํ๋๊ฒ ๋ณด๋ค๋
๋ฐ๋ก ์ ์๋ฅผ ํด์ฃผ๋๊ฒ ๋ ์๋ป๋ณด์ฌ์ ๋ค์๊ณผ ๊ฐ์ด ์ฌ์ฉํ์ต๋๋ค! |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | ์ฒ์ ์์์์๋ถํฐ ํ๋์ ๋ฉ์๋๊ฐ ๋๋๋ฉด ๋ค์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ์์ผ๋ก ๋ง๋ฌด๋ฆฌ๋ฅผ ํ์ฌ controller์ชฝ์ ๋ชจ๋ ๋ฉ์๋๊ฐ ์ฐ๊ฒฐ๋์ด ์๋๋ฐ ๊ทธ๋ ๊ฒ ๋ชจ๋ ๋ฉ์๋๋ฅผ ์ฐ๊ฒฐ์ ์ง์ผ์ ์ด์ ๊ฐ ์์ผ์ค๊น์? |
@@ -0,0 +1,21 @@
+import { Console } from '@woowacourse/mission-utils';
+import { INPUT_MSG } from '../constants/PlannerMsg.js';
+import InputValidator from '../utils/InputValidator.js';
+
+const InputView = {
+ INPUT_VAL: new InputValidator(),
+
+ async readDate() {
+ const userDate = await Console.readLineAsync(INPUT_MSG.inputVisitDay);
+ await this.INPUT_VAL.dateValidate(userDate);
+ return userDate;
+ },
+
+ async readMenu() {
+ const userMenu = await Console.readLineAsync(INPUT_MSG.orderMenu);
+ await this.INPUT_VAL.menuValidate(userMenu.split(','));
+ return userMenu.split(',');
+ },
+};
+
+export default InputView; | JavaScript | ๋ ์ง๋ฅผ ๋ฐ์์ค์๋ง์ ๋ฐ๋ก validate๋ฅผ ํด์ฃผ๋ ๊ฒ์ด ๊ด์ฐฎ๋ค๊ณ ์๊ฐํ์ต๋๋ค. controller๋ก ๋ฐ์์ค๋ ๊ฒ๋ณด๋ค ์ด ํธ์ด ํจ์ฌ ๋ณด๊ธฐ ์ข์ ๊ฒ ๊ฐ๋ค์ |
@@ -0,0 +1,28 @@
+import DateValidate from './validator/DateValidate.js';
+import MenuValidate from './validator/MenuValidate.js';
+
+class InputValidator {
+ #REGAX;
+
+ constructor() {
+ this.#REGAX = /\s|[!@#$%^&*(),?":{}|<>]|[a-zA-Z]/;
+ }
+
+ async dateValidate(date) {
+ const dateValidator = new DateValidate(this.#REGAX, date);
+ dateValidator.regaxCheck();
+ dateValidator.safeCheck();
+ dateValidator.rangeCheck();
+ }
+
+ async menuValidate(menu) {
+ const menuValidator = new MenuValidate(menu);
+ menuValidator.menuCheck();
+ menuValidator.menuAmountCheck(this.#REGAX);
+ menuValidator.formCheck();
+ menuValidator.duplicateCheck();
+ menuValidator.drinkCheck();
+ }
+}
+
+export default InputValidator; | JavaScript | ๋ฐ์์จ ๊ฐ์ ๊ฒ์ฌํ ๋ ํ๋ฒ ๋ณด๋ด์ ์ ๊ท์ ํด์ ๊ทธ๊ฒ์ ๋ค์ ๊ฒ์ฌํ๋ ์์ผ๋ก ํ์ ๊ฒ ๊ฐ์๋ฐ ์ด๋ ๊ฒ ์ ๊ท์์ ํ ๋จ๊ณ๋ก ๋ฐ๋ก ๋นผ์ ์ด์ ๊ฐ ์์ ์ง ๊ถ๊ธํฉ๋๋ค! |
@@ -0,0 +1,96 @@
+import OutputView from '../views/OutputView.js';
+import InputView from '../views/InputView.js';
+import PlannerData from '../model/PlannerData.js';
+import PlannerUtils from '../utils/PlannerUtills.js';
+import { STATUS_MSG } from '../constants/PlannerMsg.js';
+
+class PlannerController {
+ constructor() {
+ this.PLANNER_DATA = new PlannerData();
+ }
+
+ async plannerStart() {
+ OutputView.printStatusMsg(STATUS_MSG.welcomeMsg);
+ await this.#inputVisitDay();
+ }
+
+ async #inputVisitDay() {
+ try {
+ const visitDate = await InputView.readDate();
+ this.PLANNER_DATA.updateDate(visitDate);
+ return this.#orderMenu();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#inputVisitDay();
+ }
+ }
+
+ async #orderMenu() {
+ try {
+ const foodAndAmount = await InputView.readMenu();
+ this.PLANNER_DATA.updateFood(foodAndAmount);
+ return this.#showPlanner();
+ } catch (error) {
+ OutputView.printError(error.message);
+ return this.#orderMenu();
+ }
+ }
+
+ #showPlanner() {
+ OutputView.printStatusMsg(
+ STATUS_MSG.showPlanner(this.PLANNER_DATA.getDate()),
+ );
+ this.#showOrderMenu();
+ }
+
+ #showOrderMenu() {
+ OutputView.printStatusMsg(STATUS_MSG.orderMenu);
+ OutputView.printOrderMenu(this.PLANNER_DATA.getUserOrder());
+ this.#totalOrderAmount();
+ }
+
+ #totalOrderAmount() {
+ OutputView.printStatusMsg(STATUS_MSG.totalAmount);
+ const plannerUtils = new PlannerUtils(
+ this.PLANNER_DATA.getUserOrder(),
+ this.PLANNER_DATA.getDate(),
+ );
+ OutputView.printTotalAmount(plannerUtils.getTotalAmount());
+ this.#giftCheck(plannerUtils);
+ }
+
+ #giftCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.giftMenu);
+ OutputView.printGift(plannerUtils.getTotalAmount());
+ this.#benefitCheck(plannerUtils);
+ }
+
+ #benefitCheck(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.userBenefit);
+ this.#showBenefits(plannerUtils.benefitCheck(), plannerUtils);
+ }
+
+ #showBenefits(benefitObject, plannerUtils) {
+ OutputView.printBenefits(benefitObject);
+ this.#showTotalBenefit(plannerUtils);
+ }
+
+ #showTotalBenefit(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.totalBenefit);
+ OutputView.printTotalBenefit(plannerUtils.calcBenefitAmount());
+ this.#showPayment(plannerUtils);
+ }
+
+ #showPayment(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.payment);
+ OutputView.printPayment(plannerUtils.calcTotalPayment());
+ this.#userEventBadge(plannerUtils);
+ }
+
+ #userEventBadge(plannerUtils) {
+ OutputView.printStatusMsg(STATUS_MSG.eventBadge);
+ OutputView.printEventBadge(plannerUtils.calcBenefitAmount());
+ }
+}
+
+export default PlannerController; | JavaScript | Controller์๋ ์ด๋ฒคํธ ํ๋ ๋์ ์
๋ ฅ,์ถ๋ ฅ๋ฑ์ ์์๋ฅผ ์ ์ํ์ต๋๋ค.
๊ฐ๊ฐ์ ์์๋ค์ ํ๋์ ๋ฉ์๋๋ก ์ ์ํ๊ณ , ์ด๋ฅผ ์ฐ๊ฒฐ์์ผ์ฃผ๋ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ์ต๋๋ค |
@@ -0,0 +1,28 @@
+import DateValidate from './validator/DateValidate.js';
+import MenuValidate from './validator/MenuValidate.js';
+
+class InputValidator {
+ #REGAX;
+
+ constructor() {
+ this.#REGAX = /\s|[!@#$%^&*(),?":{}|<>]|[a-zA-Z]/;
+ }
+
+ async dateValidate(date) {
+ const dateValidator = new DateValidate(this.#REGAX, date);
+ dateValidator.regaxCheck();
+ dateValidator.safeCheck();
+ dateValidator.rangeCheck();
+ }
+
+ async menuValidate(menu) {
+ const menuValidator = new MenuValidate(menu);
+ menuValidator.menuCheck();
+ menuValidator.menuAmountCheck(this.#REGAX);
+ menuValidator.formCheck();
+ menuValidator.duplicateCheck();
+ menuValidator.drinkCheck();
+ }
+}
+
+export default InputValidator; | JavaScript | ์ ํจ์ฑ ๊ฒ์ฌ๋ InputValidate ์์์, MenuValidate, DateValidate ์ ๊ฐ์ฒด๋ค๋ก ๋๋๊ฒ ๋ฉ๋๋ค.
์์์์ ์ ๊ท์์ ์ ์ํด์ฃผ๊ณ , ์ ๊ท์์ ์จ์ผํ๋ ๊ฒ์ฌ ํ์์, ํ์ ๊ฐ์ฒด๋ค์๊ฒ ๋ด๋ ค์ฃผ๋ ๋ฐฉ์์ผ๋ก ์ฌ์ฉํ์ต๋๋ค! |
@@ -0,0 +1,21 @@
+/* eslint-disable max-lines-per-function */
+import { OUTPUT_MSG } from '../../src/domain/constants/PlannerMsg.js';
+
+describe('๋ฐฐ์ง ํ
์คํธ', () => {
+ const testCases = [
+ { amount: 1000, expected: '์์' },
+ { amount: 4900, expected: '์์' },
+ { amount: 5000, expected: '๋ณ' },
+ { amount: 9900, expected: '๋ณ' },
+ { amount: 10000, expected: 'ํธ๋ฆฌ' },
+ { amount: 19999, expected: 'ํธ๋ฆฌ' },
+ { amount: 20000, expected: '์ฐํ' },
+ { amount: 50000, expected: '์ฐํ' },
+ ];
+
+ testCases.forEach((testCase) => {
+ test(`๋ฐฐ์ง ํ
์คํธ : ${testCase.amount}`, () => {
+ expect(OUTPUT_MSG.userBadge(testCase.amount)).toBe(testCase.expected);
+ });
+ });
+}); | JavaScript | ์ด๋ ๊ฒ ์ฒ๋ฆฌํ ์ ์๊ตฐ์! |
@@ -0,0 +1,37 @@
+/**
+ *
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+ */
+
+export const FOOD_MENU = {
+ appetizer: {
+ soup: ['์์ก์ด์ํ', 6000],
+ tapas: ['ํํ์ค', 5500],
+ salad: ['์์ ์๋ฌ๋', 8000],
+ },
+ main: {
+ stake: ['ํฐ๋ณธ์คํ
์ดํฌ', 55000],
+ barbeque: ['๋ฐ๋นํ๋ฆฝ', 54000],
+ seafood: ['ํด์ฐ๋ฌผํ์คํ', 35000],
+ christmas: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ', 25000],
+ },
+ dessert: {
+ cake: ['์ด์ฝ์ผ์ดํฌ', 15000],
+ iceCream: ['์์ด์คํฌ๋ฆผ', 5000],
+ },
+ drink: {
+ coke: ['์ ๋ก์ฝ๋ผ', 3000],
+ wine: ['๋ ๋์์ธ', 60000],
+ champane: ['์ดํ์ธ', 25000],
+ },
+}; | JavaScript | FOOD_MENU ๊ฐ์ฒด๋ฅผ ๊น์ ๋๊ฒฐํ๋ ๊ฑด ์ด๋ ์ ๊ฐ์? |
@@ -0,0 +1,37 @@
+/**
+ *
+<์ ํผํ์ด์ >
+์์ก์ด์ํ(6,000), ํํ์ค(5,500), ์์ ์๋ฌ๋(8,000)
+
+<๋ฉ์ธ>
+ํฐ๋ณธ์คํ
์ดํฌ(55,000), ๋ฐ๋นํ๋ฆฝ(54,000), ํด์ฐ๋ฌผํ์คํ(35,000), ํฌ๋ฆฌ์ค๋ง์คํ์คํ(25,000)
+
+<๋์ ํธ>
+์ด์ฝ์ผ์ดํฌ(15,000), ์์ด์คํฌ๋ฆผ(5,000)
+
+<์๋ฃ>
+์ ๋ก์ฝ๋ผ(3,000), ๋ ๋์์ธ(60,000), ์ดํ์ธ(25,000)
+ */
+
+export const FOOD_MENU = {
+ appetizer: {
+ soup: ['์์ก์ด์ํ', 6000],
+ tapas: ['ํํ์ค', 5500],
+ salad: ['์์ ์๋ฌ๋', 8000],
+ },
+ main: {
+ stake: ['ํฐ๋ณธ์คํ
์ดํฌ', 55000],
+ barbeque: ['๋ฐ๋นํ๋ฆฝ', 54000],
+ seafood: ['ํด์ฐ๋ฌผํ์คํ', 35000],
+ christmas: ['ํฌ๋ฆฌ์ค๋ง์คํ์คํ', 25000],
+ },
+ dessert: {
+ cake: ['์ด์ฝ์ผ์ดํฌ', 15000],
+ iceCream: ['์์ด์คํฌ๋ฆผ', 5000],
+ },
+ drink: {
+ coke: ['์ ๋ก์ฝ๋ผ', 3000],
+ wine: ['๋ ๋์์ธ', 60000],
+ champane: ['์ดํ์ธ', 25000],
+ },
+}; | JavaScript | ์ข์ ๋ฆฌ๋ทฐ ๊ฐ์ฌํฉ๋๋ค! @joywhy pr ๋งํฌ ๋จ๊ฒจ์ฃผ์๋ฉด ๋ง๋ฆฌ๋ทฐ ๊ฐ๊ฒ์!! |
@@ -0,0 +1,37 @@
+package christmas.service;
+
+import christmas.domain.Order;
+import christmas.domain.constant.Message;
+import christmas.domain.constant.dish.Appetizer;
+import christmas.domain.constant.dish.Beverage;
+import christmas.domain.constant.dish.Dessert;
+import christmas.domain.constant.dish.MainDish;
+import christmas.domain.constant.dish.Orderable;
+import java.util.Map;
+import java.util.Objects;
+
+public class OrderMaker {
+ public Order make(Map<String, Integer> parsedOrder) {
+ Order order = new Order();
+ parsedOrder.forEach((dishLabel, count) -> order.addMenu(findDish(dishLabel), count));
+ order.validate();
+ return order;
+ }
+
+ private Orderable findDish(String input) {
+ if (Objects.nonNull(Appetizer.valueOfLabel(input))) {
+ return Appetizer.valueOfLabel(input);
+ }
+ if (Objects.nonNull(Beverage.valueOfLabel(input))) {
+ return Beverage.valueOfLabel(input);
+ }
+ if (Objects.nonNull(Dessert.valueOfLabel(input))) {
+ return Dessert.valueOfLabel(input);
+ }
+ if (Objects.nonNull(MainDish.valueOfLabel(input))) {
+ return MainDish.valueOfLabel(input);
+ }
+ throw new IllegalArgumentException(Message.INVALID_ORDER.getContent());
+ }
+
+} | Java | ๋ฉ๋ด enum ํ์
์ด ์์์ผ๋ฉด ํ ๋ฒ์ ์ฐพ์ ์ ์์๊ฑฐ ๊ฐ์ต๋๋ค. |
@@ -0,0 +1,38 @@
+package christmas.domain.constant.dish;
+
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public enum MainDish implements Orderable {
+ T_BONE_STEAK("ํฐ๋ณธ์คํ
์ดํฌ", 55000),
+ BARBEQUE_RIBS("๋ฐ๋นํ๋ฆฝ", 54000),
+ SEAFOOD_PASTA("ํด์ฐ๋ฌผํ์คํ", 35000),
+ CHRISTMAS_PASTA("ํฌ๋ฆฌ์ค๋ง์คํ์คํ", 25000);
+
+ private static final Map<String, MainDish> BY_LABEL =
+ Stream.of(MainDish.values()).collect(Collectors.toMap(MainDish::getLabel, e -> e));
+
+ private final String label;
+ private final int price;
+
+ MainDish(String label, int price) {
+ this.label = label;
+ this.price = price;
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+ @Override
+ public int getPrice() {
+ return price;
+ }
+
+ public static MainDish valueOfLabel(String label) {
+ return BY_LABEL.get(label);
+ }
+
+} | Java | static์ผ๋ก Map์ ์์ฑํด๋ ๊ฑฐ ์ข์ ๊ฑฐ ๊ฐ์ต๋๋ค.
๊ทธ๋ฐ๋ฐ BY_LABEL ์ด๋ฆ์ ๋๋ฌธ์๋ก ํ๋ ๊ฒ์ด ์ปจ๋ฒค์
์ธ์ง ์ ๋ ์ ๋ชจ๋ฅด๊ฒ ๋๋ผ๊ณ ์.
์์๋ ์๋๋ฐ static final์ด๊ธฐ๋ ํ๊ณ ๋ญ๊ฐ ๋ง์๊น์? |
@@ -0,0 +1,31 @@
+package christmas.service;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.constant.Discount;
+import christmas.domain.constant.dish.Orderable;
+import christmas.domain.dto.BenefitDto;
+import christmas.service.discountcalculator.SpecialDiscountCalculator;
+import christmas.service.discountcalculator.WeekDiscountCalculator;
+import christmas.service.discountcalculator.XmasDdayDiscountCalculator;
+import java.util.Map;
+
+public class DiscountManager {
+ public BenefitDto applyDiscount(Map<Orderable, Integer> menus, DecemberDate visitDate) {
+ int totalCost = getTotalCost(menus);
+ BenefitDto benefitDto = new BenefitDto(menus, totalCost);
+ if (totalCost < Discount.DISCOUNT_APPLY_LOWER_BOUND.getValue()) {
+ return benefitDto;
+ }
+ XmasDdayDiscountCalculator.apply(benefitDto, visitDate);
+ WeekDiscountCalculator.apply(menus, benefitDto, visitDate);
+ SpecialDiscountCalculator.apply(benefitDto, visitDate);
+ return benefitDto;
+ }
+
+ private int getTotalCost(Map<Orderable, Integer> menus) {
+ return menus.entrySet().stream()
+ .mapToInt(entry -> entry.getKey().getPrice() * entry.getValue())
+ .sum();
+ }
+
+} | Java | menus๋ณด๋ค Order๋ฅผ ์ธ์๋ก ๋ฐ๋ ๊ฒ์ด ๋ ๊ฐ์ฒด์งํฅ์ ๋ง๋ค๊ณ ์๊ฐํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ Order ๋ด๋ถ์ getTotalCost ๋ฉ์๋๊ฐ ์๋ ๊ฒ์ด ์ด๋จ๊น์? ๊ทธ๋ฌ๋ฉด ์์ ์ ๋ฐ์ดํฐ๋ก ๊ฒฐ๊ณผ๋ฅผ ์ป์ ์ ์์ต๋๋ค. |
@@ -0,0 +1,21 @@
+package christmas.service;
+
+import christmas.domain.constant.Benefit;
+import christmas.domain.dto.BenefitDto;
+
+public class PresentationManager {
+ private static final int PRESENTATION_THRESHOLD = 120000;
+ private static final int PRESENTATION_PRICE = 25000;
+
+ private PresentationManager() {
+
+ }
+
+ public static void present(BenefitDto benefitDto) {
+ if (benefitDto.getTotalCost() >= PRESENTATION_THRESHOLD) {
+ benefitDto.addBenefit(Benefit.PRESENTATION, PRESENTATION_PRICE);
+ benefitDto.presentChampagne();
+ }
+ }
+
+} | Java | 120_000 ์ฒ๋ผ _ ์ ๋ถ์ผ ์ ์์ต๋๋ค! |
@@ -0,0 +1,21 @@
+package christmas.service;
+
+import christmas.domain.constant.Benefit;
+import christmas.domain.dto.BenefitDto;
+
+public class PresentationManager {
+ private static final int PRESENTATION_THRESHOLD = 120000;
+ private static final int PRESENTATION_PRICE = 25000;
+
+ private PresentationManager() {
+
+ }
+
+ public static void present(BenefitDto benefitDto) {
+ if (benefitDto.getTotalCost() >= PRESENTATION_THRESHOLD) {
+ benefitDto.addBenefit(Benefit.PRESENTATION, PRESENTATION_PRICE);
+ benefitDto.presentChampagne();
+ }
+ }
+
+} | Java | private์ผ๋ก ์์ฑ์ ๋ง์์ค๋ ๊ฒ ์ข์ต๋๋ค! ๋ค๋ง ๋ด์ฉ์ด ์์ผ๋ฉด ๋น์ค๋ ์๋ ๊ฒ์ด ์ข์ต๋๋ค. |
@@ -0,0 +1,24 @@
+package christmas.service.discountcalculator;
+
+import static christmas.domain.constant.Discount.DATE_OF_CHRISTMAS;
+import static christmas.domain.constant.Discount.ONE_WEEK;
+import static christmas.domain.constant.Discount.SPECIAL_DISCOUNT_AMOUNT;
+import static christmas.domain.constant.Discount.THREE;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.constant.Benefit;
+import christmas.domain.dto.BenefitDto;
+
+public class SpecialDiscountCalculator {
+ private SpecialDiscountCalculator() {
+
+ }
+
+ public static void apply(BenefitDto benefitDto, DecemberDate visitDate) {
+ if (visitDate.date() == DATE_OF_CHRISTMAS.getValue()
+ || visitDate.date() % ONE_WEEK.getValue() == THREE.getValue()) {
+ benefitDto.addBenefit(Benefit.SPECIAL_DISCOUNT, SPECIAL_DISCOUNT_AMOUNT.getValue());
+ }
+ }
+
+} | Java | ๊ธด ์กฐ๊ฑด์์ ๋ฉ์๋๋ก ๋ฝ๋ ๊ฒ์ด ๊ฐ๋
์ฑ์ ์ข์ต๋๋ค! |
@@ -0,0 +1,70 @@
+package christmas.service.discountcalculator;
+
+import static christmas.domain.constant.Discount.ONE;
+import static christmas.domain.constant.Discount.ONE_WEEK;
+import static christmas.domain.constant.Discount.TWO;
+import static christmas.domain.constant.Discount.WEEK_DISCOUNT_UNIT;
+import static christmas.domain.constant.Discount.ZERO;
+
+import christmas.domain.DecemberDate;
+import christmas.domain.constant.Benefit;
+import christmas.domain.constant.dish.Dessert;
+import christmas.domain.constant.dish.MainDish;
+import christmas.domain.constant.dish.Orderable;
+import christmas.domain.dto.BenefitDto;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class WeekDiscountCalculator {
+ private WeekDiscountCalculator() {
+
+ }
+
+ public static void apply(Map<Orderable, Integer> menus, BenefitDto benefitDto, DecemberDate visitDate) {
+ if (isWeekend(visitDate)) {
+ applyWeekendDiscount(menus, benefitDto);
+ return;
+ }
+ applyWeekdayDiscount(menus, benefitDto);
+ }
+
+ private static void applyWeekendDiscount(Map<Orderable, Integer> menus, BenefitDto benefitDto) {
+ if (getMainDishCount(menus) == ZERO.getValue()) {
+ return;
+ }
+ benefitDto.addBenefit(Benefit.WEEK_END_DISCOUNT, getMainDishCount(menus) * WEEK_DISCOUNT_UNIT.getValue());
+ }
+
+ private static void applyWeekdayDiscount(Map<Orderable, Integer> menus, BenefitDto benefitDto) {
+ if (getDessertCount(menus) == ZERO.getValue()) {
+ return;
+ }
+ benefitDto.addBenefit(Benefit.WEEK_DAY_DISCOUNT, getDessertCount(menus) * WEEK_DISCOUNT_UNIT.getValue());
+ }
+
+ private static int getDessertCount(Map<Orderable, Integer> menus) {
+ return countDishesOfCertainCategory(menus, Dessert.class);
+ }
+
+ private static int getMainDishCount(Map<Orderable, Integer> menus) {
+ return countDishesOfCertainCategory(menus, MainDish.class);
+ }
+
+ private static int countDishesOfCertainCategory(Map<Orderable, Integer> menus,
+ Class<? extends Orderable> category) {
+ int count = ZERO.getValue();
+ for (Entry<Orderable, Integer> entry : menus.entrySet()) {
+ if (entry.getKey().getClass() == category) {
+ count += entry.getValue();
+ }
+ }
+ return count;
+ }
+
+ private static boolean isWeekend(DecemberDate visitDate) {
+ int dateNumber = visitDate.date();
+ return dateNumber % ONE_WEEK.getValue() == ONE.getValue()
+ || dateNumber % ONE_WEEK.getValue() == TWO.getValue();
+ }
+
+} | Java | dto์ addํ๋ ๊ฒ๋ณด๋ค ๊ฒฐ๊ณผ๊ฐ์ ๋ฐํํ๋ฉด Dto์ ์์กด์ฑ์ ๋จ์ด๋จ๋ฆฌ๊ณ ๋ค๋ฅธ Dto์๋ ์ ๋ฌ ํ ์ ์์ต๋๋ค. |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | addPosition ๋ ๋ฐ์ดํฐ ๋ณ๊ฒฝ์ ๋ํ ์ค๋ช
์ด ๋๋ ๊ฒ ๊ฐ์ง๋ง,
run ์ด๋ผ๋ ํ์๋ฅผ ํํํ๋ ๋จ์ด๋ก ๋ฉ์๋๋ช
์ ์ง์ด๋ณด๋ฉด ์ด๋จ๊น์?
์ถํ์ ์๋์ฐจ ๊ธฐ๋ณธ ์ด๋ ์กฐ๊ฑด์ด +2 ๋ก ๋ฐ๋๋ค๊ณ ๊ฐ์ ํ์ ๋
addPosition ์ด๋ฉด ํด๋น ๋ฉ์๋๋ฅผ ์ฌ์ฉํ๋ ์
์ฅ์์ position+1 ์ผ ๊ฒ ๊ฐ๋ค๋ ์๊ฐ์ด ๋๋๋ฐ
run ์ผ๋ก ์ถ์ํ ๋์ด์์ผ๋ฉด +2 ๋ฅผ ํ๋ +1 ์ ํ๋ ์๋์ฐจ๊ฐ ์ด๋ํ๋ค๋ ํ์๋ฅผ ๋ํ๋ด์ ํผ๋์ด ์์ ๊ฒ ๊ฐ์ต๋๋ค ~ |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | ๊ฒฐ๊ณผ๋ฅผ ๋ณด์ฌ์ฃผ๋ View ์ ์ญํ ์ ResultView ์ ์์ํ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | ์ถํ์ ์ฝ์์ด ์๋ GUI ํ๋ก๊ทธ๋จ์ผ๋ก ํ์ฅ๋๋ค๊ณ ํ์ ๋ Car ์ด๋ผ๋ pure ํด์ผํ๋ ๋ชจ๋ธ ํด๋์ค๊ฐ ๋๋ฝํ์ง์ง ์์๊น์~? |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | ์กฐ์์ ๋ธ๋กํฌ์ effective java ์๋ '๊ฐ์ฒด๋ ์ธํฐํ์ด์ค๋ฅผ ์ฌ์ฉํด ์ฐธ์กฐํ๋ผ.'
๋ผ๋ ๋ถ๋ถ์ด ์์ต๋๋ค.
ํ๋ฒ ์ฝ์ด๋ณด์๊ณ ๊ฐ์ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์ ~
jaehun2841.github.io/2019/03/01/effective-java-item64/#%EC%9C%A0%EC%97%B0%ED%95%9C-%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%A8%EC%9D%84-%EC%83%9D%EC%84%B1%ED%95%98%EB%8A%94-%EC%9D%B8%ED%84%B0%ED%8E%98%EC%9D%B4%EC%8A%A4-%ED%83%80%EC%9E%85-%EB%B3%80%EC%88%98 |
@@ -0,0 +1,22 @@
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameWinner {
+ public List<String> findWinner(List<Car> cars) {
+ int max = cars.get(0).position;
+ for (int i = 1; i < cars.size(); i++) {
+ max = Math.max(max, cars.get(i).position);
+ }
+ List<String> winnerList = new ArrayList<>();
+ for (Car car : cars) {
+ addWinnerList(car, max, winnerList);
+ }
+ return winnerList;
+ }
+
+ private void addWinnerList(Car car, int max, List<String> winnerList) {
+ if (car.position == max) {
+ winnerList.add(car.name);
+ }
+ }
+} | Java | ๋ฐฐ์ด ์ฌ์ฉ์ ์ง์ํ๊ณ List ๋ก ์ต๋ํ ๋๊ฒจ๋ฐ์ผ๋ฉด ์ด๋จ๊น์? |
@@ -0,0 +1,18 @@
+import java.util.List;
+
+public class Main {
+ public static void main(String[] args) {
+ InputView inputView = new InputView();
+ RacingGame racingGame = new RacingGame();
+ GameWinner gameWinner = new GameWinner();
+ ResultView resultView = new ResultView();
+
+ List<Car> cars = inputView.registerCar(inputView.inputCarName());
+ int time = inputView.inputTime();
+ for (int i = 0; i < time; i++) {
+ racingGame.raceByTime(cars);
+ resultView.showResultByTime(cars);
+ }
+ resultView.showFinalResult(gameWinner.findWinner(cars));
+ }
+} | Java | Main ์ ์ฝ์ ์ถ๋ ฅํ๋ ์ฝ๋๋ฅผ ์์ ๋ณด๋ฉด ์ด๋จ๊น์~? |
@@ -0,0 +1,29 @@
+import java.util.Random;
+import java.util.List;
+
+public class RacingGame {
+ private static final int RANDOM_RANGE = 10;
+ private static final int MIN_MOVE_STANDARD = 4;
+
+ public void raceByTime(List<Car> cars) {
+ for (Car car : cars) {
+ int randomValue = giveRandomValue();
+ move(car, randomValue);
+ }
+ }
+
+ private int giveRandomValue() {
+ Random random = new Random();
+ return random.nextInt(RANDOM_RANGE);
+ }
+
+ private void move(Car car, int randomValue) {
+ if (canMove(randomValue)) {
+ car.run();
+ }
+ }
+
+ private boolean canMove(int number) {
+ return number >= MIN_MOVE_STANDARD;
+ }
+}
\ No newline at end of file | Java | ์ ๊ทผ์ ์ด์๋ฅผ ์๋ตํ์ ์ด์ ๊ฐ ์์๊น์? ์๋ตํ๋ฉด ์ด๋ค ์ ๊ทผ์ ์ด์๊ฐ ๋ถ์๊น์? |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | ๋ฉ์๋๋ช
์ ์ง์ ๋ ์กฐ๊ฑด ๋ณ๊ฒฝ์ ๊ฐ๋ฅ์ฑ์ ๊ผญ ๊ณ ๋ คํ๋๋ก ํ๊ฒ ์ต๋๋ค! ๋จ๋ฒ์ ์ดํด๋๋ ์ข์ ์์ ์ ์ํด์ฃผ์
์ ๊ฐ์ฌํฉ๋๋ค. |
@@ -0,0 +1,8 @@
+public class Car {
+ public String name;
+ public int position;
+
+ public int run() {
+ return this.position++;
+ }
+}
\ No newline at end of file | Java | GUI ํ๋ก๊ทธ๋จ์ผ๋ก ํ์ฅ๋ ๊ฒฝ์ฐ๋ ๊ณ ๋ คํด์ผ ํ๋ค๋ ์ ๋ช
์ฌํ๊ฒ ์ต๋๋ค! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.