From a54d12f46883d35d5c8fabebf3f5a791f56634dd Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 02:45:18 +0900 Subject: [PATCH 01/50] =?UTF-8?q?docs:=20=EA=B5=AC=ED=98=84=ED=95=A0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EB=AA=A9=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/README.md b/docs/README.md index e69de29bb2..f2ac0a267c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,37 @@ +# 기능 목록 + +--- + +## 입력 +- [ ] 구입 금액 입력 + - [ ] (예외처리) 숫자 여부 확인 + - [ ] (예외처리) 1,000원 단위 확인 +- [ ] 당첨 번호 입력 + - [ ] (예외처리) 쉼표 기준 6개 확인 + - [ ] (예외처리) 숫자 여부 확인 + - [ ] (예외처리) 숫자 범위 1~45 확인 +- [ ] 보너스 번호 입력 + - [ ] (예외처리) 숫자 여부 확인 + - [ ] (예외처리) 숫자 범위 1~45 확인 + +## 출력 +- [ ] 발행 로또 수량 & 번호 출력 + - [ ] 오름차순 정렬 +- [ ] 당첨 내역 출력 +- [ ] 수익률 출력 + - [ ] 소수점 둘째 자리에서 반올림 + +## Application +- [ ] 로또 프로그램 작동 + +## Lotto +- [ ] 구입 금액에 따른 로또 개수 계산 +- [ ] 로또 개수만큼의 로또 번호 생성 + +## Outcome +- [ ] 일치 개수 계산 +- [ ] 3개 이상 일치한 로또 필터링 + +## PrizeMoney +- [ ] 당청금 계산 +- [ ] 수익률 계산 \ No newline at end of file From e162025ba6809cb781d655adada3ff6a09449733 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 14:20:31 +0900 Subject: [PATCH 02/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=206=EA=B0=9C=20&=20=EC=A4=91=EB=B3=B5X=20&=20?= =?UTF-8?q?=EB=B2=94=EC=9C=84=20=EB=82=B4=20=EC=88=AB=EC=9E=90=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/ErrorMessage.java | 13 +++++++++++++ src/main/java/lotto/Lotto.java | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/main/java/lotto/ErrorMessage.java diff --git a/src/main/java/lotto/ErrorMessage.java b/src/main/java/lotto/ErrorMessage.java new file mode 100644 index 0000000000..88e2db9cda --- /dev/null +++ b/src/main/java/lotto/ErrorMessage.java @@ -0,0 +1,13 @@ +package lotto; + +public enum ErrorMessage { + NOT_SIX_NUMBERS("[ERROR] 당첨 번호는 6개를 입력해 주세요."), + DUPLICATED_NUMBERS("[ERROR] 당첨 번호의 중복을 제거해 주세요."), + OUT_OF_RANGE_NUMBER("[ERROR] 당첨 번호는 1 ~ 45 사이의 숫자로 설정해주세요."); + + private final String message; + + ErrorMessage(final String message) { + this.message = message; + } +} diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java index 519793d1f7..3b373bc936 100644 --- a/src/main/java/lotto/Lotto.java +++ b/src/main/java/lotto/Lotto.java @@ -11,10 +11,26 @@ public Lotto(List numbers) { } private void validate(List numbers) { + checkSixNumbers(numbers); + checkNotDuplicated(numbers); + checkInRange(numbers); + } + + private void checkSixNumbers(List numbers) { if (numbers.size() != 6) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException(ErrorMessage.NOT_SIX_NUMBERS.toString()); } } - // TODO: 추가 기능 구현 + private void checkNotDuplicated(List numbers) { + if (numbers.size() != numbers.stream().distinct().count()) { + throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.toString()); + } + } + + private void checkInRange(List numbers) { + if (!numbers.stream().allMatch(n -> n <= 45 && n >= 1)) { + throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.toString()); + } + } } From bd66c953de5b72f5f76bc49d1ec6df09016efeba Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 14:21:13 +0900 Subject: [PATCH 03/50] =?UTF-8?q?test:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B2=94=EC=9C=84=20=EB=82=B4=20=EC=88=AB=EC=9E=90?= =?UTF-8?q?=20=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/lotto/LottoTest.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/lotto/LottoTest.java b/src/test/java/lotto/LottoTest.java index 0f3af0f6c4..cee29b5f23 100644 --- a/src/test/java/lotto/LottoTest.java +++ b/src/test/java/lotto/LottoTest.java @@ -23,5 +23,10 @@ void createLottoByDuplicatedNumber() { .isInstanceOf(IllegalArgumentException.class); } - // 아래에 추가 테스트 작성 가능 + @DisplayName("로또 번호가 1 ~ 45 사이의 숫자가 아니면 예외가 발생한다.") + @Test + void createLottoByOutOfRangeNumber() { + assertThatThrownBy(() -> new Lotto(List.of(1, 2, 46, 3, 4, 5))) + .isInstanceOf(IllegalArgumentException.class); + } } From f1705bfd51cc1cc2db7fde7eeebfe5388952cbe7 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 14:39:37 +0900 Subject: [PATCH 04/50] =?UTF-8?q?docs:=20=EA=B8=B0=EB=8A=A5=EB=B3=84=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B6=84=ED=95=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index f2ac0a267c..44c7141b24 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,12 +21,36 @@ - [ ] 수익률 출력 - [ ] 소수점 둘째 자리에서 반올림 + + ## Application - [ ] 로또 프로그램 작동 -## Lotto +### controller +## InputController +- [ ] 구입 금액 입력 +- [ ] 당첨 번호 입력 +- [ ] 보너스 번호 입력 + + +### service +## LottoService - [ ] 구입 금액에 따른 로또 개수 계산 -- [ ] 로또 개수만큼의 로또 번호 생성 +- [ ] 로또 개수만큼 LottoNumberGenerator 호출 + +### repository +## LottoNumberGenerator +- [ ] 로또 번호 생성 + +## Lotto +- [ ] (예외처리) 숫자 6개 확인 +- [ ] (예외처리) 숫자 중복 없음 확인 +- [ ] (예외처리) 숫자 범위 1~45 확인 + +## BonusLotto +- [ ] (예외처리) 숫자 범위 1~45 확인 + + ## Outcome - [ ] 일치 개수 계산 @@ -34,4 +58,6 @@ ## PrizeMoney - [ ] 당청금 계산 -- [ ] 수익률 계산 \ No newline at end of file +- [ ] 수익률 계산 + + From 5c50af8c1c454c5e3c4009d42cd1a84589d9080d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 17:44:56 +0900 Subject: [PATCH 05/50] =?UTF-8?q?feat:=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EC=88=AB=EC=9E=90=20=EC=A4=91=EB=B3=B5X?= =?UTF-8?q?=20&=20=EB=B2=94=EC=9C=84=20=EB=82=B4=20=EC=88=AB=EC=9E=90=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/ErrorMessage.java | 6 +++- .../java/lotto/repositroy/BonusLotto.java | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/main/java/lotto/repositroy/BonusLotto.java diff --git a/src/main/java/lotto/ErrorMessage.java b/src/main/java/lotto/ErrorMessage.java index 88e2db9cda..e21a5222d7 100644 --- a/src/main/java/lotto/ErrorMessage.java +++ b/src/main/java/lotto/ErrorMessage.java @@ -3,11 +3,15 @@ public enum ErrorMessage { NOT_SIX_NUMBERS("[ERROR] 당첨 번호는 6개를 입력해 주세요."), DUPLICATED_NUMBERS("[ERROR] 당첨 번호의 중복을 제거해 주세요."), - OUT_OF_RANGE_NUMBER("[ERROR] 당첨 번호는 1 ~ 45 사이의 숫자로 설정해주세요."); + OUT_OF_RANGE_NUMBER("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."), private final String message; ErrorMessage(final String message) { this.message = message; } + + public String getMessage() { + return message; + } } diff --git a/src/main/java/lotto/repositroy/BonusLotto.java b/src/main/java/lotto/repositroy/BonusLotto.java new file mode 100644 index 0000000000..085fe21f6d --- /dev/null +++ b/src/main/java/lotto/repositroy/BonusLotto.java @@ -0,0 +1,32 @@ +package lotto.repositroy; + +import lotto.ErrorMessage; +import lotto.LottoRangeNumber; + +import java.util.List; + +public class BonusLotto { + private final Integer number; + + public BonusLotto(Integer number, List winNumbers) { + validate(number, winNumbers); + this.number = number; + } + + private void validate(Integer number, List winNumbers) { + checkInRage(number); + checkNotDuplicated(number, winNumbers); + } + + private void checkInRage(Integer number) { + if (number > LottoRangeNumber.MAX_LOTTO_NUM.getNum() || number < LottoRangeNumber.MIN_LOTTO_NUM.getNum()) { + throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.getMessage()); + } + } + + private void checkNotDuplicated(Integer number, List winNumbers) { + if (winNumbers.contains(number)) { + throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.getMessage()); + } + } +} From 9e16f68ba2c18a0f8cc2ade4c93111a763669ff3 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 17:46:01 +0900 Subject: [PATCH 06/50] =?UTF-8?q?test:=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EB=B2=88=ED=98=B8=20=EC=A4=91=EB=B3=B5X?= =?UTF-8?q?=20&=20=EB=B2=94=EC=9C=84=20=EB=82=B4=20=EC=88=AB=EC=9E=90=20?= =?UTF-8?q?=EA=B2=80=EC=A6=9D=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/repositroy/BonusLottoTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/test/java/lotto/repositroy/BonusLottoTest.java diff --git a/src/test/java/lotto/repositroy/BonusLottoTest.java b/src/test/java/lotto/repositroy/BonusLottoTest.java new file mode 100644 index 0000000000..a8acc94f89 --- /dev/null +++ b/src/test/java/lotto/repositroy/BonusLottoTest.java @@ -0,0 +1,24 @@ +package lotto.repositroy; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class BonusLottoTest { + @DisplayName("보너스 번호가 1 ~ 45 사이의 숫자가 아니면 예외가 발생한다.") + @Test + void createBonusLottoByOutOfRange() { + assertThatThrownBy(() -> new BonusLotto(46, List.of(1, 2, 3, 4, 5, 6))) + .isInstanceOf(IllegalArgumentException.class); + } + + @DisplayName("보너스 번호와 기존 6개의 당첨 번호가 중복되면 예외가 발생한다.") + @Test + void createBonusLottoByDuplicated() { + assertThatThrownBy(() -> new BonusLotto(1, List.of(1, 2, 3, 4, 5, 6))) + .isInstanceOf(IllegalArgumentException.class); + } +} \ No newline at end of file From 31151e5311f1b91d2c1963d4a764616f690d5414 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 17:48:08 +0900 Subject: [PATCH 07/50] =?UTF-8?q?refactor:=20=EC=83=81=EC=88=98=20->=20enu?= =?UTF-8?q?m?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/LottoRangeNumber.java | 20 +++++++++++++++++++ .../java/lotto/{ => repositroy}/Lotto.java | 16 +++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/main/java/lotto/LottoRangeNumber.java rename src/main/java/lotto/{ => repositroy}/Lotto.java (67%) diff --git a/src/main/java/lotto/LottoRangeNumber.java b/src/main/java/lotto/LottoRangeNumber.java new file mode 100644 index 0000000000..543d7b3d75 --- /dev/null +++ b/src/main/java/lotto/LottoRangeNumber.java @@ -0,0 +1,20 @@ +package lotto; + +public enum LottoRangeNumber { + MIN_LOTTO_NUM(1), + MAX_LOTTO_NUM(45), + NUM_OF_LOTTO_NUMS(6) + ; + + + private int num; + + LottoRangeNumber(int num) { + this.num = num; + } + + public int getNum() { + return num; + } + +} diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/repositroy/Lotto.java similarity index 67% rename from src/main/java/lotto/Lotto.java rename to src/main/java/lotto/repositroy/Lotto.java index 3b373bc936..3a0a8f384f 100644 --- a/src/main/java/lotto/Lotto.java +++ b/src/main/java/lotto/repositroy/Lotto.java @@ -1,4 +1,7 @@ -package lotto; +package lotto.repositroy; + +import lotto.ErrorMessage; +import lotto.LottoRangeNumber; import java.util.List; @@ -17,20 +20,21 @@ private void validate(List numbers) { } private void checkSixNumbers(List numbers) { - if (numbers.size() != 6) { - throw new IllegalArgumentException(ErrorMessage.NOT_SIX_NUMBERS.toString()); + if (numbers.size() != LottoRangeNumber.NUM_OF_LOTTO_NUMS.getNum()) { + throw new IllegalArgumentException(ErrorMessage.NOT_SIX_NUMBERS.getMessage()); } } private void checkNotDuplicated(List numbers) { if (numbers.size() != numbers.stream().distinct().count()) { - throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.toString()); + throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.getMessage()); } } private void checkInRange(List numbers) { - if (!numbers.stream().allMatch(n -> n <= 45 && n >= 1)) { - throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.toString()); + if (!numbers.stream().allMatch(n -> n <= LottoRangeNumber.MAX_LOTTO_NUM.getNum() + && n >= LottoRangeNumber.MIN_LOTTO_NUM.getNum())) { + throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.getMessage()); } } } From b3053e031e3493f347d339f33043805c0f965e2d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 22:26:35 +0900 Subject: [PATCH 08/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20-=20=EB=A1=9C=EB=98=90=20=EA=B5=AC=EC=9E=85=20?= =?UTF-8?q?=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/Application.java | 5 ++- .../java/lotto/controller/PlayController.java | 37 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/lotto/controller/PlayController.java diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index d190922ba4..4f172d2c65 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,7 +1,10 @@ package lotto; +import lotto.controller.PlayController; + public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + PlayController playController = new PlayController(); + playController.start(); } } diff --git a/src/main/java/lotto/controller/PlayController.java b/src/main/java/lotto/controller/PlayController.java new file mode 100644 index 0000000000..b2e5ca7606 --- /dev/null +++ b/src/main/java/lotto/controller/PlayController.java @@ -0,0 +1,37 @@ +package lotto.controller; + +import camp.nextstep.edu.missionutils.Console; +import lotto.ErrorMessage; +import lotto.service.LottoTicketService; +import lotto.service.OutputGuide; + +public class PlayController { + private final LottoTicketService lottoTicketService; + + public PlayController() { + this.lottoTicketService = new LottoTicketService(); + } + + + public void start() { + int money = inputMoney(); + lottoTicketService.createLottoTickets(money); + } + + private int inputMoney() { + System.out.println(InputGuide.INPUT_MONEY.getContent()); + int money = changeToInt(Console.readLine()); + System.out.println(money + OutputGuide.NUMBER_OF_PURCHASE.getContent()); + + return money; + } + + private int changeToInt(String money) { + try { + return Integer.parseInt(money); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_NUMBER.getMessage()); + } + } + +} From 81604e3a07009bec60ef01ca98ec7049d5c9bb9f Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 22:27:52 +0900 Subject: [PATCH 09/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=ED=8B=B0?= =?UTF-8?q?=EC=BC=93=20=EA=B0=9C=EC=88=98=20=EB=8F=84=EC=B6=9C=20&=20?= =?UTF-8?q?=ED=8B=B0=EC=BC=93=20=EC=B6=9C=EB=A0=A5=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/service/LottoTicketService.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/lotto/service/LottoTicketService.java diff --git a/src/main/java/lotto/service/LottoTicketService.java b/src/main/java/lotto/service/LottoTicketService.java new file mode 100644 index 0000000000..8ec4bd221a --- /dev/null +++ b/src/main/java/lotto/service/LottoTicketService.java @@ -0,0 +1,34 @@ +package lotto.service; + +import lotto.ErrorMessage; +import lotto.repositroy.LottoTicketGenerator; + +import java.util.Arrays; + +public class LottoTicketService { + private static final int ZERO = 0; + private static final int MONEY_UNIT = 1000; + private final LottoTicketGenerator ticketGenerator; + + public LottoTicketService() { + this.ticketGenerator = new LottoTicketGenerator(); + } + + public void createLottoTickets(int money) { + validate(money); + int ticketNum = money / MONEY_UNIT; + ticketGenerator.generateTicket(ticketNum); + printTickets(); + } + + private void validate(int money) { + if (money % MONEY_UNIT != ZERO) { + throw new IllegalArgumentException(ErrorMessage.INVALID_OF_MONEY_UNIT.getMessage()); + } + } + + private void printTickets() { + ticketGenerator.getSortedTickets().forEach(t -> + System.out.println(Arrays.toString(t.stream().sorted().toArray()))); + } +} From e64b7ccea1e53016fc3dcda5a3905006497a153a Mon Sep 17 00:00:00 2001 From: yeonjy Date: Mon, 28 Aug 2023 22:29:30 +0900 Subject: [PATCH 10/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=ED=8B=B0?= =?UTF-8?q?=EC=BC=93=20=EC=83=9D=EC=84=B1=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositroy/LottoTicketGenerator.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/lotto/repositroy/LottoTicketGenerator.java diff --git a/src/main/java/lotto/repositroy/LottoTicketGenerator.java b/src/main/java/lotto/repositroy/LottoTicketGenerator.java new file mode 100644 index 0000000000..03c5a4142d --- /dev/null +++ b/src/main/java/lotto/repositroy/LottoTicketGenerator.java @@ -0,0 +1,31 @@ +package lotto.repositroy; + +import camp.nextstep.edu.missionutils.Randoms; +import lotto.LottoRangeNumber; + +import java.util.ArrayList; +import java.util.List; + +public class LottoTicketGenerator { + private final List> tickets; + + public LottoTicketGenerator() { + tickets = new ArrayList<>(); + } + + public void generateTicket(int ticketNum) { + for (int i = 0; i < ticketNum; i++) { + tickets.add(generateNumber()); + } + } + + private List generateNumber() { + return Randoms.pickUniqueNumbersInRange(LottoRangeNumber.MIN_LOTTO_NUM.getNum() + , LottoRangeNumber.MAX_LOTTO_NUM.getNum(), LottoRangeNumber.NUM_OF_LOTTO_NUMS.getNum()); + } + + public List> getSortedTickets() { + return tickets; + } + +} From 1706015397e6b9041597dbcd098d446ba0ab0628 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 00:07:50 +0900 Subject: [PATCH 11/50] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=EA=B0=80?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=20enum=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/controller/InputGuide.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/lotto/controller/InputGuide.java diff --git a/src/main/java/lotto/controller/InputGuide.java b/src/main/java/lotto/controller/InputGuide.java new file mode 100644 index 0000000000..e8e93c750c --- /dev/null +++ b/src/main/java/lotto/controller/InputGuide.java @@ -0,0 +1,17 @@ +package lotto.controller; + +public enum InputGuide { + INPUT_MONEY("구입금액을 입력해 주세요."), + INPUT_LOTTO_ANSWER("당첨 번호를 입력해 주세요."), + INPUT_BONUS_ANSWER("보너스 번호를 입력해 주세요."); + + private final String content; + + InputGuide(final String content) { + this.content = content; + } + + public String getContent() { + return content; + } +} From dcc3ede831f2b5962808063ad9c063ac9b7b936b Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 00:10:06 +0900 Subject: [PATCH 12/50] =?UTF-8?q?feat:=20=EC=88=AB=EC=9E=90X=20&=201000?= =?UTF-8?q?=EC=9B=90=20=EB=8B=A8=EC=9C=84X=20=EC=98=88=EC=99=B8=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/ErrorMessage.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/lotto/ErrorMessage.java b/src/main/java/lotto/ErrorMessage.java index e21a5222d7..92772535e6 100644 --- a/src/main/java/lotto/ErrorMessage.java +++ b/src/main/java/lotto/ErrorMessage.java @@ -4,6 +4,9 @@ public enum ErrorMessage { NOT_SIX_NUMBERS("[ERROR] 당첨 번호는 6개를 입력해 주세요."), DUPLICATED_NUMBERS("[ERROR] 당첨 번호의 중복을 제거해 주세요."), OUT_OF_RANGE_NUMBER("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."), + NOT_NUMBER("[ERROR] 정확한 숫자를 입력해 주세요."), + INVALID_OF_MONEY_UNIT("[ERROR] 구입 금액은 1000원 단위 입력해주세요."); + private final String message; From 02bb67eed6b77ff2589a2c7781f6d1214db786fa Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 00:11:50 +0900 Subject: [PATCH 13/50] =?UTF-8?q?refactor:=20=EC=9E=85=EB=A0=A5=EA=B0=92?= =?UTF-8?q?=20->=20=EC=82=AC=EC=9A=A9=EA=B0=80=EB=8A=A5=ED=95=9C=20?= =?UTF-8?q?=EB=8D=B0=EC=9D=B4=ED=84=B0=20Processor=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/InputProcessor.java | 22 +++++++++++++++++ .../java/lotto/controller/PlayController.java | 24 ++++++++++--------- 2 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 src/main/java/lotto/InputProcessor.java diff --git a/src/main/java/lotto/InputProcessor.java b/src/main/java/lotto/InputProcessor.java new file mode 100644 index 0000000000..c55cc07460 --- /dev/null +++ b/src/main/java/lotto/InputProcessor.java @@ -0,0 +1,22 @@ +package lotto; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class InputProcessor { + + public int changeToInt(String money) { + try { + return Integer.parseInt(money); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(ErrorMessage.NOT_NUMBER.getMessage()); + } + } + + public List changeToIntegerList(String s) { + return Arrays.stream(s.split(", ")) + .map(Integer::parseInt).collect(Collectors.toList()); + } +} diff --git a/src/main/java/lotto/controller/PlayController.java b/src/main/java/lotto/controller/PlayController.java index b2e5ca7606..f2a3cae63d 100644 --- a/src/main/java/lotto/controller/PlayController.java +++ b/src/main/java/lotto/controller/PlayController.java @@ -2,36 +2,38 @@ import camp.nextstep.edu.missionutils.Console; import lotto.ErrorMessage; +import lotto.InputProcessor; +import lotto.service.LottoAnswerService; import lotto.service.LottoTicketService; import lotto.service.OutputGuide; +import java.util.List; + public class PlayController { - private final LottoTicketService lottoTicketService; + private final LottoTicketService ticketService; + private final InputProcessor inputProcessor; + private final LottoAnswerController answerController; public PlayController() { - this.lottoTicketService = new LottoTicketService(); + this.ticketService = new LottoTicketService(); + this.inputProcessor = new InputProcessor(); + this.answerController = new LottoAnswerController(); } public void start() { int money = inputMoney(); - lottoTicketService.createLottoTickets(money); + ticketService.createLottoTickets(money); + answerController.playLotto(); } private int inputMoney() { System.out.println(InputGuide.INPUT_MONEY.getContent()); - int money = changeToInt(Console.readLine()); + int money = inputProcessor.changeToInt(Console.readLine()); System.out.println(money + OutputGuide.NUMBER_OF_PURCHASE.getContent()); return money; } - private int changeToInt(String money) { - try { - return Integer.parseInt(money); - } catch (NumberFormatException e) { - throw new IllegalArgumentException(ErrorMessage.NOT_NUMBER.getMessage()); - } - } } From 231bb0ed04a06d56b3145c1f5ced75d4aa1d11ff Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 00:12:33 +0900 Subject: [PATCH 14/50] refactor: Integer -> int --- src/main/java/lotto/repositroy/BonusLotto.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/repositroy/BonusLotto.java b/src/main/java/lotto/repositroy/BonusLotto.java index 085fe21f6d..2966996cad 100644 --- a/src/main/java/lotto/repositroy/BonusLotto.java +++ b/src/main/java/lotto/repositroy/BonusLotto.java @@ -6,25 +6,25 @@ import java.util.List; public class BonusLotto { - private final Integer number; + private final int number; - public BonusLotto(Integer number, List winNumbers) { + public BonusLotto(int number, List winNumbers) { validate(number, winNumbers); this.number = number; } - private void validate(Integer number, List winNumbers) { + private void validate(int number, List winNumbers) { checkInRage(number); checkNotDuplicated(number, winNumbers); } - private void checkInRage(Integer number) { + private void checkInRage(int number) { if (number > LottoRangeNumber.MAX_LOTTO_NUM.getNum() || number < LottoRangeNumber.MIN_LOTTO_NUM.getNum()) { throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.getMessage()); } } - private void checkNotDuplicated(Integer number, List winNumbers) { + private void checkNotDuplicated(int number, List winNumbers) { if (winNumbers.contains(number)) { throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.getMessage()); } From e58053193e135491234f15644585cb04fddd1dee Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:00:15 +0900 Subject: [PATCH 15/50] refactor: ", " -> CRITERIA --- src/main/java/lotto/InputProcessor.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/lotto/InputProcessor.java b/src/main/java/lotto/InputProcessor.java index c55cc07460..e91d6f5c93 100644 --- a/src/main/java/lotto/InputProcessor.java +++ b/src/main/java/lotto/InputProcessor.java @@ -3,9 +3,9 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; public class InputProcessor { + private static final String CRITERIA = ", "; public int changeToInt(String money) { try { @@ -16,7 +16,7 @@ public int changeToInt(String money) { } public List changeToIntegerList(String s) { - return Arrays.stream(s.split(", ")) + return Arrays.stream(s.split(CRITERIA)) .map(Integer::parseInt).collect(Collectors.toList()); } } From 17777c7f865f65f1d15f4b089c1263b5841a2196 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:01:12 +0900 Subject: [PATCH 16/50] =?UTF-8?q?feat:=20=EC=83=81=EA=B8=88=20enum=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/PrizeMoney.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/lotto/PrizeMoney.java diff --git a/src/main/java/lotto/PrizeMoney.java b/src/main/java/lotto/PrizeMoney.java new file mode 100644 index 0000000000..2b5547864f --- /dev/null +++ b/src/main/java/lotto/PrizeMoney.java @@ -0,0 +1,20 @@ +package lotto; + +public enum PrizeMoney { + THREE_EQUAL_MONEY(5_000), + FOUR_EQUAL_MONEY(50_000), + FIVE_EQUAL_MONEY(1_500_000), + BONUS_EQUAL_MONEY(30_000_000), + SIX_EQUAL_MONEY(2_000_000_000); + + private final int number; + + PrizeMoney(final int number) { + this.number = number; + } + + public int getNumber() { + return number; + } + +} From 686d70650501b8e3b8e4531940c440737bd40974 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:07:51 +0900 Subject: [PATCH 17/50] =?UTF-8?q?docs:=20=EB=A1=9C=EB=98=90=20=EC=B6=94?= =?UTF-8?q?=EC=B2=A8=20=EC=8B=A4=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/docs/README.md b/docs/README.md index 44c7141b24..beb4909654 100644 --- a/docs/README.md +++ b/docs/README.md @@ -24,40 +24,54 @@ ## Application -- [ ] 로또 프로그램 작동 +- [x] 로또 프로그램 작동 + ### controller -## InputController +## PlayController - [ ] 구입 금액 입력 - [ ] 당첨 번호 입력 -- [ ] 보너스 번호 입력 +- [ ] 보너스 번호 + ### service -## LottoService +## PlayLottoService +- [x] 로또 번호 6개 & 보너스 번호 -> 하나의 DTO로 병합 +- [x] 로또 추첨 로직 실행 + +## LottoTicketService - [ ] 구입 금액에 따른 로또 개수 계산 - [ ] 로또 개수만큼 LottoNumberGenerator 호출 +## OutcomeService +- [ ] 일치 개수 계산 +- [ ] 3개 이상 일치한 로또 필터링 + +## PrizeMoneyService +- [ ] 당청금 계산 +- [ ] 수익률 계산 + + + ### repository ## LottoNumberGenerator -- [ ] 로또 번호 생성 +- [x] 로또 번호 생성 ## Lotto -- [ ] (예외처리) 숫자 6개 확인 -- [ ] (예외처리) 숫자 중복 없음 확인 -- [ ] (예외처리) 숫자 범위 1~45 확인 +- [x] (예외처리) 숫자 6개 확인 +- [x] (예외처리) 숫자 중복 없음 확인 +- [x] (예외처리) 숫자 범위 1~45 확인 ## BonusLotto -- [ ] (예외처리) 숫자 범위 1~45 확인 +- [x] (예외처리) 숫자 범위 1~45 확인 +- [x] (예외처리) 기존 6개 당첨 번호와 중복 없음 확인 +## InputProcessor +- [x] 로또 구입 금액 & 보너스 번호 정수 변환 +- [x] 당첨 번호 6개 정수 리스트 변환 -## Outcome -- [ ] 일치 개수 계산 -- [ ] 3개 이상 일치한 로또 필터링 -## PrizeMoney -- [ ] 당청금 계산 -- [ ] 수익률 계산 From e5afd8b958620bfb6adcf0297e6d8ca0c99a2b96 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:09:48 +0900 Subject: [PATCH 18/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EB=B0=98=ED=99=98=20get=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/repositroy/BonusLotto.java | 4 ++++ src/main/java/lotto/repositroy/Lotto.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/lotto/repositroy/BonusLotto.java b/src/main/java/lotto/repositroy/BonusLotto.java index 2966996cad..f5e9336516 100644 --- a/src/main/java/lotto/repositroy/BonusLotto.java +++ b/src/main/java/lotto/repositroy/BonusLotto.java @@ -29,4 +29,8 @@ private void checkNotDuplicated(int number, List winNumbers) { throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.getMessage()); } } + + public int getNumber() { + return number; + } } diff --git a/src/main/java/lotto/repositroy/Lotto.java b/src/main/java/lotto/repositroy/Lotto.java index 3a0a8f384f..b7f879787e 100644 --- a/src/main/java/lotto/repositroy/Lotto.java +++ b/src/main/java/lotto/repositroy/Lotto.java @@ -37,4 +37,8 @@ private void checkInRange(List numbers) { throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.getMessage()); } } + + public List getNumbers() { + return numbers; + } } From 372a03dd1c68963316efecdda6c417d8d56aee35 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:11:46 +0900 Subject: [PATCH 19/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9D=BC=EC=B9=98=20=EA=B0=9C=EC=88=98=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/MatchNum.java | 30 +++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/main/java/lotto/service/MatchNum.java diff --git a/src/main/java/lotto/service/MatchNum.java b/src/main/java/lotto/service/MatchNum.java new file mode 100644 index 0000000000..4c9335f55b --- /dev/null +++ b/src/main/java/lotto/service/MatchNum.java @@ -0,0 +1,30 @@ +package lotto.service; + + +public enum MatchNum { + THREE_MATCH(3), + FOUR_MATCH(4), + FIVE_MATCH(5), + BONUS_MATCH(7), + SIX_MATCH(6); + + private final int num; + + MatchNum(int num) { + this.num = num; + } + + public int getNum() { + return num; + } + + public static MatchNum valueOf(int check) { + for (MatchNum matchNum : MatchNum.values()) { + if (check == matchNum.getNum()) { + return matchNum; + } + } + return null; + } + +} From 59fb09ac3e95495ee249ad1b9d3de8d6ebab32d8 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:12:37 +0900 Subject: [PATCH 20/50] =?UTF-8?q?feat:=20=EC=B6=9C=EB=A0=A5=20=EA=B0=80?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/OutputGuide.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/lotto/service/OutputGuide.java diff --git a/src/main/java/lotto/service/OutputGuide.java b/src/main/java/lotto/service/OutputGuide.java new file mode 100644 index 0000000000..b7a2af22c2 --- /dev/null +++ b/src/main/java/lotto/service/OutputGuide.java @@ -0,0 +1,18 @@ +package lotto.service; + +public enum OutputGuide { + NUMBER_OF_PURCHASE("개를 구매했습니다."), + RESULT_STATISTICS("당첨 통계\n---"); + + private final String content; + + OutputGuide(final String content) { + this.content = content; + } + + public String getContent() { + return content; + } + + +} From 69209486722ff530965e6c9072deec5c3d562b2c Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:17:00 +0900 Subject: [PATCH 21/50] =?UTF-8?q?feat:=20=ED=8B=B0=EC=BC=93=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=ED=98=B8=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/repositroy/LottoTicketGenerator.java | 3 +++ src/main/java/lotto/service/LottoTicketService.java | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/lotto/repositroy/LottoTicketGenerator.java b/src/main/java/lotto/repositroy/LottoTicketGenerator.java index 03c5a4142d..ffd67ed031 100644 --- a/src/main/java/lotto/repositroy/LottoTicketGenerator.java +++ b/src/main/java/lotto/repositroy/LottoTicketGenerator.java @@ -28,4 +28,7 @@ public List> getSortedTickets() { return tickets; } + public List> getTickets() { + return tickets; + } } diff --git a/src/main/java/lotto/service/LottoTicketService.java b/src/main/java/lotto/service/LottoTicketService.java index 8ec4bd221a..e1c42034c2 100644 --- a/src/main/java/lotto/service/LottoTicketService.java +++ b/src/main/java/lotto/service/LottoTicketService.java @@ -4,6 +4,7 @@ import lotto.repositroy.LottoTicketGenerator; import java.util.Arrays; +import java.util.List; public class LottoTicketService { private static final int ZERO = 0; @@ -14,11 +15,12 @@ public LottoTicketService() { this.ticketGenerator = new LottoTicketGenerator(); } - public void createLottoTickets(int money) { + public List> createLottoTickets(int money) { validate(money); - int ticketNum = money / MONEY_UNIT; - ticketGenerator.generateTicket(ticketNum); + ticketGenerator.generateTicket(getTicketNum(money)); printTickets(); + + return ticketGenerator.getTickets(); } private void validate(int money) { From b592d6aa0403623f2cc3e671bac3dd6d4fd33e61 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:18:20 +0900 Subject: [PATCH 22/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=20=EA=B3=84=EC=82=B0=20&=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/LottoTicketService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/lotto/service/LottoTicketService.java b/src/main/java/lotto/service/LottoTicketService.java index e1c42034c2..53affcb74f 100644 --- a/src/main/java/lotto/service/LottoTicketService.java +++ b/src/main/java/lotto/service/LottoTicketService.java @@ -29,6 +29,16 @@ private void validate(int money) { } } + private int getTicketNum(int money) { + int ticketNum = money / MONEY_UNIT; + printTicketNum(ticketNum); + return ticketNum; + } + + private void printTicketNum(int num) { + System.out.println(num + OutputGuide.NUMBER_OF_PURCHASE.getContent()); + } + private void printTickets() { ticketGenerator.getSortedTickets().forEach(t -> System.out.println(Arrays.toString(t.stream().sorted().toArray()))); From 1bd4d53aaec2b5987b650c8f6d590494bf32b08d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:20:17 +0900 Subject: [PATCH 23/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=206=EA=B0=9C=20&=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/LottoAnswerController.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/lotto/controller/LottoAnswerController.java diff --git a/src/main/java/lotto/controller/LottoAnswerController.java b/src/main/java/lotto/controller/LottoAnswerController.java new file mode 100644 index 0000000000..f4eced92e3 --- /dev/null +++ b/src/main/java/lotto/controller/LottoAnswerController.java @@ -0,0 +1,36 @@ +package lotto.controller; + +import camp.nextstep.edu.missionutils.Console; +import lotto.InputProcessor; +import lotto.dto.AllLottoes; +import lotto.service.PlayLottoService; + +import java.util.List; + +public class LottoAnswerController { + private final InputProcessor inputProcessor; + private final PlayLottoService playLottoService; + + public LottoAnswerController() { + this.inputProcessor = new InputProcessor(); + this.playLottoService = new PlayLottoService(); + } + + public void playLotto(List> tickets) { + List lottoAnswers = inputAnswerNumber(); + int bonusAnswer = intputBonusNumber(); + AllLottoes allLottoes = playLottoService.setAllLottoes(lottoAnswers, bonusAnswer); + playLottoService.playLotto(allLottoes, tickets); + } + + private List inputAnswerNumber() { + System.out.println(InputGuide.INPUT_LOTTO_ANSWER); + return inputProcessor.changeToIntegerList(Console.readLine()); + } + + private int intputBonusNumber() { + System.out.println(InputGuide.INPUT_BONUS_ANSWER); + return inputProcessor.changeToInt(Console.readLine()); + } + +} From c72896ae6ea7d2abb51fa53a4e2970ea3c1bf64a Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:22:35 +0900 Subject: [PATCH 24/50] =?UTF-8?q?refactor:=20=EC=83=9D=EC=84=B1=EB=90=9C?= =?UTF-8?q?=20=EB=A1=9C=EB=98=90=20=ED=8B=B0=EC=BC=93=20playLotto=20?= =?UTF-8?q?=EB=A7=A4=EA=B0=9C=EB=B3=80=EC=88=98=EB=A1=9C=20=EC=A0=84?= =?UTF-8?q?=EB=8B=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/controller/PlayController.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/controller/PlayController.java b/src/main/java/lotto/controller/PlayController.java index f2a3cae63d..c194b11104 100644 --- a/src/main/java/lotto/controller/PlayController.java +++ b/src/main/java/lotto/controller/PlayController.java @@ -1,9 +1,7 @@ package lotto.controller; import camp.nextstep.edu.missionutils.Console; -import lotto.ErrorMessage; import lotto.InputProcessor; -import lotto.service.LottoAnswerService; import lotto.service.LottoTicketService; import lotto.service.OutputGuide; @@ -23,14 +21,13 @@ public PlayController() { public void start() { int money = inputMoney(); - ticketService.createLottoTickets(money); - answerController.playLotto(); + List> tickets = ticketService.createLottoTickets(money); + answerController.playLotto(tickets); } private int inputMoney() { System.out.println(InputGuide.INPUT_MONEY.getContent()); int money = inputProcessor.changeToInt(Console.readLine()); - System.out.println(money + OutputGuide.NUMBER_OF_PURCHASE.getContent()); return money; } From f957ced1fe9b070fe7bd0e01b54fa36ff69860f7 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:24:04 +0900 Subject: [PATCH 25/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=EB=B3=84=20=EC=83=81=EA=B8=88=20=EC=B4=88=EA=B8=B0?= =?UTF-8?q?=ED=99=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/PrizeResult.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/lotto/PrizeResult.java diff --git a/src/main/java/lotto/PrizeResult.java b/src/main/java/lotto/PrizeResult.java new file mode 100644 index 0000000000..51d5795734 --- /dev/null +++ b/src/main/java/lotto/PrizeResult.java @@ -0,0 +1,19 @@ +package lotto; + +import lotto.service.MatchNum; + +import java.util.*; + +public class PrizeResult { + private final Map playResult = new EnumMap<>(MatchNum.class); + private final Map prizeMoneyMap = new EnumMap<>(MatchNum.class); + + public void initialize() { + + Iterator prizeMoneyIterator = Arrays.stream(PrizeMoney.values()).iterator(); + for (MatchNum matchNum : MatchNum.values()) { + prizeMoneyMap.put(matchNum, prizeMoneyIterator.next()); + } + } + +} From aaf844bcbba496e7ee597a16ebe30aa80d1f376b Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 05:25:22 +0900 Subject: [PATCH 26/50] =?UTF-8?q?feat:=20=EC=A0=84=EC=B2=B4=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=20=EB=A1=9C=EB=98=90=20=EB=B2=88=ED=98=B8=EB=A5=BC=20?= =?UTF-8?q?=EA=B0=80=EC=A7=84=20DTO=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/dto/AllLottoes.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/lotto/dto/AllLottoes.java diff --git a/src/main/java/lotto/dto/AllLottoes.java b/src/main/java/lotto/dto/AllLottoes.java new file mode 100644 index 0000000000..18b0e3d072 --- /dev/null +++ b/src/main/java/lotto/dto/AllLottoes.java @@ -0,0 +1,22 @@ +package lotto.dto; + +import lotto.repositroy.BonusLotto; +import lotto.repositroy.Lotto; + +public class AllLottoes { + private final Lotto lotto; + private final BonusLotto bonusLotto; + + public AllLottoes(Lotto lotto, BonusLotto bonusLotto) { + this.lotto = lotto; + this.bonusLotto = bonusLotto; + } + + public Lotto getLotto() { + return lotto; + } + + public BonusLotto getBonusLotto() { + return bonusLotto; + } +} From 91be43786b31e064b64db56228138dd1780f209f Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 13:10:04 +0900 Subject: [PATCH 27/50] =?UTF-8?q?docs:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=20Controller=20=EB=B6=84?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index beb4909654..bf1edcccbe 100644 --- a/docs/README.md +++ b/docs/README.md @@ -29,10 +29,12 @@ ### controller ## PlayController -- [ ] 구입 금액 입력 -- [ ] 당첨 번호 입력 -- [ ] 보너스 번호 +- [x] 구입 금액 입력 + +## LottoAnswerController +- [x] 당첨 번호 입력 +- [x] 보너스 번호 ### service From b1c6a6f5a3f964dc8ec90512c7b6e26cdcc43d7e Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 13:34:07 +0900 Subject: [PATCH 28/50] =?UTF-8?q?refactor:=20=EC=83=81=EA=B8=88=20int=20->?= =?UTF-8?q?=20long?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/PrizeMoney.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/lotto/PrizeMoney.java b/src/main/java/lotto/PrizeMoney.java index 2b5547864f..a5547a96ac 100644 --- a/src/main/java/lotto/PrizeMoney.java +++ b/src/main/java/lotto/PrizeMoney.java @@ -1,19 +1,19 @@ package lotto; public enum PrizeMoney { - THREE_EQUAL_MONEY(5_000), - FOUR_EQUAL_MONEY(50_000), - FIVE_EQUAL_MONEY(1_500_000), - BONUS_EQUAL_MONEY(30_000_000), - SIX_EQUAL_MONEY(2_000_000_000); + THREE_EQUAL_MONEY(5_000L), + FOUR_EQUAL_MONEY(50_000L), + FIVE_EQUAL_MONEY(1_500_000L), + BONUS_EQUAL_MONEY(30_000_000L), + SIX_EQUAL_MONEY(2_000_000_000L); - private final int number; + private final long number; - PrizeMoney(final int number) { + PrizeMoney(final long number) { this.number = number; } - public int getNumber() { + public long getNumber() { return number; } From 8afe729ebddbb6145dee1dabe4ed2708fb7b6c48 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 14:06:07 +0900 Subject: [PATCH 29/50] =?UTF-8?q?feat:=20=EC=9D=BC=EC=B9=98=20=EA=B0=9C?= =?UTF-8?q?=EC=88=98=20=EB=B3=84=20=EC=83=81=EA=B8=88=20&=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=20=EB=A1=9C=EB=98=90=20=EA=B0=9C=EC=88=98=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/PrizeResult.java | 44 ++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/main/java/lotto/PrizeResult.java b/src/main/java/lotto/PrizeResult.java index 51d5795734..a0be8b08d2 100644 --- a/src/main/java/lotto/PrizeResult.java +++ b/src/main/java/lotto/PrizeResult.java @@ -1,19 +1,63 @@ package lotto; +import lotto.dto.AllLottoes; +import lotto.repositroy.BonusLotto; import lotto.service.MatchNum; import java.util.*; public class PrizeResult { + private static final int ZERO = 0; private final Map playResult = new EnumMap<>(MatchNum.class); private final Map prizeMoneyMap = new EnumMap<>(MatchNum.class); public void initialize() { + initializePlayResult(); + initializePrizeMoneyMap(); + } + + private void initializePlayResult() { + Arrays.stream(MatchNum.values()).distinct().forEach(m -> playResult.put(m, ZERO)); + } + private void initializePrizeMoneyMap() { Iterator prizeMoneyIterator = Arrays.stream(PrizeMoney.values()).iterator(); for (MatchNum matchNum : MatchNum.values()) { prizeMoneyMap.put(matchNum, prizeMoneyIterator.next()); } } + public void makeResult(AllLottoes allLottoes, List> tickets) { + for (List ticket : tickets) { + MatchNum match = checkTicket(ticket, allLottoes); + playResult.put(match, playResult.get(match) + 1); + } + } + + private MatchNum checkTicket(List ticket, AllLottoes allLottoes) { + int count = (int) ticket.stream().filter(num -> allLottoes.getLotto().getNumbers().contains(num)).count(); + if (count == MatchNum.FIVE_MATCH.getNum()) { + return checkBonusLotto(ticket, allLottoes.getBonusLotto()); + } + return MatchNum.valueOf(count); + } + + private MatchNum checkBonusLotto(List ticket, BonusLotto bonusLotto) { + if (isBonusLotto(ticket, bonusLotto)) { + return MatchNum.BONUS_MATCH; + } + return MatchNum.FIVE_MATCH; + } + + private boolean isBonusLotto(List ticket, BonusLotto bonusLotto) { + return ticket.contains(bonusLotto.getNumber()); + } + + public Map getPlayResult() { + return playResult; + } + + public Map getPrizeMoneyMap() { + return prizeMoneyMap; + } } From 90f2f3391fd61bd2d1fb8041c7100ae4a3b90cd2 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 14:07:29 +0900 Subject: [PATCH 30/50] =?UTF-8?q?docs:=20=EB=A1=9C=EB=98=90=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EA=B2=B0=EA=B3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index bf1edcccbe..962825ef42 100644 --- a/docs/README.md +++ b/docs/README.md @@ -37,14 +37,21 @@ - [x] 보너스 번호 +### dto +- [x] 로또 번호 6개 & 보너스 번호 + + ### service ## PlayLottoService - [x] 로또 번호 6개 & 보너스 번호 -> 하나의 DTO로 병합 - [x] 로또 추첨 로직 실행 ## LottoTicketService -- [ ] 구입 금액에 따른 로또 개수 계산 -- [ ] 로또 개수만큼 LottoNumberGenerator 호출 +- [x] 구입 금액에 따른 로또 개수 계산 + - [x] 구입 금액 1000원 단위 검증 +- [x] 로또 구입 개수 출력 +- [x] 로또 개수만큼 LottoNumberGenerator 호출 +- [x] 로또 티켓 번호 출력 ## OutcomeService - [ ] 일치 개수 계산 @@ -73,7 +80,9 @@ - [x] 로또 구입 금액 & 보너스 번호 정수 변환 - [x] 당첨 번호 6개 정수 리스트 변환 - +## PrizeResult +- [x] 일치 개수 별 상금 +- [x] 일치 개수 별 당첨 로또 개수 From 4fd506c4e23b202a49493b4873f399b41f34937d Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 14:08:31 +0900 Subject: [PATCH 31/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20&=20=EC=83=81=EA=B8=88=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/OutcomeService.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/main/java/lotto/service/OutcomeService.java diff --git a/src/main/java/lotto/service/OutcomeService.java b/src/main/java/lotto/service/OutcomeService.java new file mode 100644 index 0000000000..4d6ec49155 --- /dev/null +++ b/src/main/java/lotto/service/OutcomeService.java @@ -0,0 +1,64 @@ +package lotto.service; + +import lotto.PrizeMoney; +import lotto.PrizeResult; +import lotto.dto.AllLottoes; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +public class OutcomeService { + private final PrizeResult prizeResult; + + public OutcomeService() { + this.prizeResult = new PrizeResult(); + } + + public long getTotalPrizeMoney(final AllLottoes allLottoes, final List> tickets) { + prizeResult.initialize(); + prizeResult.makeResult(allLottoes, tickets); + printResult(); + + return calculateTotalMoney(); + } + + + private void printResult() { + Map prizeMoneyMap = prizeResult.getPrizeMoneyMap(); + Map playResult = prizeResult.getPlayResult(); + + Arrays.stream(MatchNum.values()).distinct().forEach(m -> { + printEqualNum(m); + printPrizeMoney(prizeMoneyMap.get(m)); + printLottoNumResult(playResult.get(m)); + }); + } + + + private void printEqualNum(MatchNum matchNum) { + System.out.print(matchNum + OutputGuide.EQUAL_NUM_GUIDE.getContent()); + } + + private void printPrizeMoney(PrizeMoney prizeMoney) { + System.out.print(prizeMoney.getNumber() + OutputGuide.PRIZE_MONEY_GUIDE.getContent()); + } + + + private void printLottoNumResult(Integer result) { + System.out.println(result + OutputGuide.LOTTO_NUM.getContent()); + } + + + private long calculateTotalMoney() { + long totalMoney = 0; + Map prizeMoneyMap = prizeResult.getPrizeMoneyMap(); + Map playResult = prizeResult.getPlayResult(); + + for (MatchNum matchNum : MatchNum.values()) { + totalMoney += prizeMoneyMap.get(matchNum).getNumber() * playResult.get(matchNum).longValue(); + } + return totalMoney; + } + +} From 17509112f31e49929a855388c7a25f92e8cf6833 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 14:10:44 +0900 Subject: [PATCH 32/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EA=B2=B0=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=20=EA=B0=80?= =?UTF-8?q?=EC=9D=B4=EB=93=9C=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/OutputGuide.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/service/OutputGuide.java b/src/main/java/lotto/service/OutputGuide.java index b7a2af22c2..a6afea0ef0 100644 --- a/src/main/java/lotto/service/OutputGuide.java +++ b/src/main/java/lotto/service/OutputGuide.java @@ -2,7 +2,11 @@ public enum OutputGuide { NUMBER_OF_PURCHASE("개를 구매했습니다."), - RESULT_STATISTICS("당첨 통계\n---"); + RESULT_STATISTICS("당첨 통계\n---"), + + EQUAL_NUM_GUIDE("개 일치 ("), + PRIZE_MONEY_GUIDE("원) - "), + LOTTO_NUM("개"); private final String content; From 5074a0db483355afb8c13612812908ca82bffbaf Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 14:11:43 +0900 Subject: [PATCH 33/50] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=206=EA=B0=9C=20&=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20DTO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/PlayLottoService.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/lotto/service/PlayLottoService.java diff --git a/src/main/java/lotto/service/PlayLottoService.java b/src/main/java/lotto/service/PlayLottoService.java new file mode 100644 index 0000000000..1175da19ef --- /dev/null +++ b/src/main/java/lotto/service/PlayLottoService.java @@ -0,0 +1,28 @@ +package lotto.service; + + +import lotto.PrizeResult; +import lotto.dto.AllLottoes; +import lotto.repositroy.BonusLotto; +import lotto.repositroy.Lotto; + +import java.util.List; +import java.util.Map; + +public class PlayLottoService { + private final OutcomeService outcomeService; + + public PlayLottoService() { + this.outcomeService = new OutcomeService(); + } + + public AllLottoes setAllLottoes(List lottoAnswers, int bonusAnswer) { + Lotto lotto = new Lotto(lottoAnswers); + BonusLotto bonusLotto = new BonusLotto(bonusAnswer, lotto.getNumbers()); + return new AllLottoes(lotto, bonusLotto); + } + + public void playLotto(AllLottoes allLottoes, List> tickets) { + long totalMoney = outcomeService.getTotalPrizeMoney(allLottoes, tickets); + } +} From e60ac0837bccf8399822e4268b44ee4b6331aa00 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 15:42:23 +0900 Subject: [PATCH 34/50] =?UTF-8?q?refactor:=20enum=20=EA=B0=92=20=EA=B0=80?= =?UTF-8?q?=EC=A0=B8=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/controller/LottoAnswerController.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/lotto/controller/LottoAnswerController.java b/src/main/java/lotto/controller/LottoAnswerController.java index f4eced92e3..cdb75b5ae4 100644 --- a/src/main/java/lotto/controller/LottoAnswerController.java +++ b/src/main/java/lotto/controller/LottoAnswerController.java @@ -16,20 +16,21 @@ public LottoAnswerController() { this.playLottoService = new PlayLottoService(); } - public void playLotto(List> tickets) { + public void playLotto(List> tickets, double paidMoney) { List lottoAnswers = inputAnswerNumber(); int bonusAnswer = intputBonusNumber(); AllLottoes allLottoes = playLottoService.setAllLottoes(lottoAnswers, bonusAnswer); - playLottoService.playLotto(allLottoes, tickets); + long totalPrizeMoney = playLottoService.playLotto(allLottoes, tickets); + playLottoService.printEarningRate(totalPrizeMoney / paidMoney); } private List inputAnswerNumber() { - System.out.println(InputGuide.INPUT_LOTTO_ANSWER); + System.out.println(InputGuide.INPUT_LOTTO_ANSWER.getContent()); return inputProcessor.changeToIntegerList(Console.readLine()); } private int intputBonusNumber() { - System.out.println(InputGuide.INPUT_BONUS_ANSWER); + System.out.println(InputGuide.INPUT_BONUS_ANSWER.getContent()); return inputProcessor.changeToInt(Console.readLine()); } From 67b7705054063b27df3a2978215ae619b2c3a5cc Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 15:44:03 +0900 Subject: [PATCH 35/50] =?UTF-8?q?refactor:=20=EB=8B=B9=EC=B2=A8=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=AA=BC=EA=B0=9C=EA=B8=B0=20=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20",=20"=20->=20","?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/InputProcessor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/lotto/InputProcessor.java b/src/main/java/lotto/InputProcessor.java index e91d6f5c93..8114b1ea48 100644 --- a/src/main/java/lotto/InputProcessor.java +++ b/src/main/java/lotto/InputProcessor.java @@ -5,7 +5,7 @@ import java.util.stream.Collectors; public class InputProcessor { - private static final String CRITERIA = ", "; + private static final String CRITERIA = ","; public int changeToInt(String money) { try { From 1290c22e714cabe53fbf9b7b070f4184d12dde35 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 15:45:01 +0900 Subject: [PATCH 36/50] refactor: valueOf() -> getOf() --- src/main/java/lotto/PrizeResult.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/lotto/PrizeResult.java b/src/main/java/lotto/PrizeResult.java index a0be8b08d2..fd296f1f08 100644 --- a/src/main/java/lotto/PrizeResult.java +++ b/src/main/java/lotto/PrizeResult.java @@ -17,7 +17,7 @@ public void initialize() { } private void initializePlayResult() { - Arrays.stream(MatchNum.values()).distinct().forEach(m -> playResult.put(m, ZERO)); + Arrays.stream(MatchNum.values()).forEach(m -> playResult.put(m, ZERO)); } private void initializePrizeMoneyMap() { @@ -30,7 +30,9 @@ private void initializePrizeMoneyMap() { public void makeResult(AllLottoes allLottoes, List> tickets) { for (List ticket : tickets) { MatchNum match = checkTicket(ticket, allLottoes); - playResult.put(match, playResult.get(match) + 1); + if (match != null) { + playResult.put(match, playResult.get(match) + 1); + } } } @@ -39,7 +41,7 @@ private MatchNum checkTicket(List ticket, AllLottoes allLottoes) { if (count == MatchNum.FIVE_MATCH.getNum()) { return checkBonusLotto(ticket, allLottoes.getBonusLotto()); } - return MatchNum.valueOf(count); + return MatchNum.getOf(count); } private MatchNum checkBonusLotto(List ticket, BonusLotto bonusLotto) { From 2fea1497b9fc883f99c31702c9c7bd7606f097eb Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 15:46:54 +0900 Subject: [PATCH 37/50] =?UTF-8?q?feat:=20=EC=88=98=EC=9D=B5=EB=A5=A0=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B0=80=EC=9D=B4=EB=93=9C=20enum?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/OutputGuide.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/service/OutputGuide.java b/src/main/java/lotto/service/OutputGuide.java index a6afea0ef0..47ed8a1ac9 100644 --- a/src/main/java/lotto/service/OutputGuide.java +++ b/src/main/java/lotto/service/OutputGuide.java @@ -5,8 +5,12 @@ public enum OutputGuide { RESULT_STATISTICS("당첨 통계\n---"), EQUAL_NUM_GUIDE("개 일치 ("), + BONUS_NUM_GUIDE("5개 일치, 보너스 볼 일치 ("), PRIZE_MONEY_GUIDE("원) - "), - LOTTO_NUM("개"); + LOTTO_NUM("개"), + + TOTAL_EARNING_FRONT("총 수익률은 "), + TOTAL_EARNING_BACK("%입니다."); private final String content; From d7436886f7a9aa93a3f864430e55e19bf595049b Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 15:48:58 +0900 Subject: [PATCH 38/50] =?UTF-8?q?refactor:=20=EB=B3=B4=EB=84=88=EC=8A=A4?= =?UTF-8?q?=20=EB=B3=BC=20=EC=B6=9C=EB=A0=A5=20&=20=EA=B8=88=EC=95=A1=20?= =?UTF-8?q?=EC=BD=A4=EB=A7=88=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/MatchNum.java | 2 +- src/main/java/lotto/service/OutcomeService.java | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/service/MatchNum.java b/src/main/java/lotto/service/MatchNum.java index 4c9335f55b..37e57c4df4 100644 --- a/src/main/java/lotto/service/MatchNum.java +++ b/src/main/java/lotto/service/MatchNum.java @@ -18,7 +18,7 @@ public int getNum() { return num; } - public static MatchNum valueOf(int check) { + public static MatchNum getOf(int check) { for (MatchNum matchNum : MatchNum.values()) { if (check == matchNum.getNum()) { return matchNum; diff --git a/src/main/java/lotto/service/OutcomeService.java b/src/main/java/lotto/service/OutcomeService.java index 4d6ec49155..831f2dc89d 100644 --- a/src/main/java/lotto/service/OutcomeService.java +++ b/src/main/java/lotto/service/OutcomeService.java @@ -4,11 +4,14 @@ import lotto.PrizeResult; import lotto.dto.AllLottoes; +import java.text.DecimalFormat; import java.util.Arrays; import java.util.List; import java.util.Map; public class OutcomeService { + DecimalFormat formatter = new DecimalFormat("#,###"); + private final PrizeResult prizeResult; public OutcomeService() { @@ -27,8 +30,8 @@ public long getTotalPrizeMoney(final AllLottoes allLottoes, final List prizeMoneyMap = prizeResult.getPrizeMoneyMap(); Map playResult = prizeResult.getPlayResult(); - - Arrays.stream(MatchNum.values()).distinct().forEach(m -> { + System.out.println(OutputGuide.RESULT_STATISTICS.getContent()); + Arrays.stream(MatchNum.values()).forEach(m -> { printEqualNum(m); printPrizeMoney(prizeMoneyMap.get(m)); printLottoNumResult(playResult.get(m)); @@ -37,11 +40,16 @@ private void printResult() { private void printEqualNum(MatchNum matchNum) { - System.out.print(matchNum + OutputGuide.EQUAL_NUM_GUIDE.getContent()); + if (matchNum.equals(MatchNum.BONUS_MATCH)) { + System.out.print(OutputGuide.BONUS_NUM_GUIDE.getContent()); + return; + } + System.out.print(matchNum.getNum() + OutputGuide.EQUAL_NUM_GUIDE.getContent()); } private void printPrizeMoney(PrizeMoney prizeMoney) { - System.out.print(prizeMoney.getNumber() + OutputGuide.PRIZE_MONEY_GUIDE.getContent()); + String formatMoney = formatter.format(prizeMoney.getNumber()); + System.out.print(formatMoney + OutputGuide.PRIZE_MONEY_GUIDE.getContent()); } From c202f47874044ffea4c658683a83709ff7407bc5 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 15:50:24 +0900 Subject: [PATCH 39/50] =?UTF-8?q?feat:=20=EC=88=98=EC=9D=B5=EB=A5=A0=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/controller/PlayController.java | 2 +- src/main/java/lotto/service/PlayLottoService.java | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/controller/PlayController.java b/src/main/java/lotto/controller/PlayController.java index c194b11104..e147db9116 100644 --- a/src/main/java/lotto/controller/PlayController.java +++ b/src/main/java/lotto/controller/PlayController.java @@ -22,7 +22,7 @@ public PlayController() { public void start() { int money = inputMoney(); List> tickets = ticketService.createLottoTickets(money); - answerController.playLotto(tickets); + answerController.playLotto(tickets, money); } private int inputMoney() { diff --git a/src/main/java/lotto/service/PlayLottoService.java b/src/main/java/lotto/service/PlayLottoService.java index 1175da19ef..dcb0692eb7 100644 --- a/src/main/java/lotto/service/PlayLottoService.java +++ b/src/main/java/lotto/service/PlayLottoService.java @@ -1,15 +1,14 @@ package lotto.service; -import lotto.PrizeResult; import lotto.dto.AllLottoes; import lotto.repositroy.BonusLotto; import lotto.repositroy.Lotto; import java.util.List; -import java.util.Map; public class PlayLottoService { + private static final int HUNDRED = 100; private final OutcomeService outcomeService; public PlayLottoService() { @@ -22,7 +21,13 @@ public AllLottoes setAllLottoes(List lottoAnswers, int bonusAnswer) { return new AllLottoes(lotto, bonusLotto); } - public void playLotto(AllLottoes allLottoes, List> tickets) { - long totalMoney = outcomeService.getTotalPrizeMoney(allLottoes, tickets); + public long playLotto(AllLottoes allLottoes, List> tickets) { + return outcomeService.getTotalPrizeMoney(allLottoes, tickets); + } + + public void printEarningRate(double earningRate) { + String earningPercent = String.format("%.1f", earningRate * HUNDRED); + System.out.println(OutputGuide.TOTAL_EARNING_FRONT.getContent() + earningPercent + + OutputGuide.TOTAL_EARNING_BACK.getContent()); } } From 1e7e4966c60b05a195d3a7ce2535a134d40147b0 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 16:19:21 +0900 Subject: [PATCH 40/50] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=84=B8=EC=A7=80=20=EC=B6=9C=EB=A0=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/ErrorMessage.java | 4 ++++ src/main/java/lotto/repositroy/BonusLotto.java | 2 ++ src/main/java/lotto/repositroy/Lotto.java | 13 ++++++++----- src/main/java/lotto/service/LottoTicketService.java | 1 + 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/ErrorMessage.java b/src/main/java/lotto/ErrorMessage.java index 92772535e6..195bb49a15 100644 --- a/src/main/java/lotto/ErrorMessage.java +++ b/src/main/java/lotto/ErrorMessage.java @@ -17,4 +17,8 @@ public enum ErrorMessage { public String getMessage() { return message; } + + public void print() { + System.out.println(message); + } } diff --git a/src/main/java/lotto/repositroy/BonusLotto.java b/src/main/java/lotto/repositroy/BonusLotto.java index f5e9336516..ff2a7f6cd0 100644 --- a/src/main/java/lotto/repositroy/BonusLotto.java +++ b/src/main/java/lotto/repositroy/BonusLotto.java @@ -20,12 +20,14 @@ private void validate(int number, List winNumbers) { private void checkInRage(int number) { if (number > LottoRangeNumber.MAX_LOTTO_NUM.getNum() || number < LottoRangeNumber.MIN_LOTTO_NUM.getNum()) { + ErrorMessage.OUT_OF_RANGE_NUMBER.print(); throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.getMessage()); } } private void checkNotDuplicated(int number, List winNumbers) { if (winNumbers.contains(number)) { + ErrorMessage.DUPLICATED_NUMBERS.print(); throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.getMessage()); } } diff --git a/src/main/java/lotto/repositroy/Lotto.java b/src/main/java/lotto/repositroy/Lotto.java index b7f879787e..1a3ce99938 100644 --- a/src/main/java/lotto/repositroy/Lotto.java +++ b/src/main/java/lotto/repositroy/Lotto.java @@ -21,19 +21,22 @@ private void validate(List numbers) { private void checkSixNumbers(List numbers) { if (numbers.size() != LottoRangeNumber.NUM_OF_LOTTO_NUMS.getNum()) { + ErrorMessage.NOT_SIX_NUMBERS.print(); throw new IllegalArgumentException(ErrorMessage.NOT_SIX_NUMBERS.getMessage()); } } - private void checkNotDuplicated(List numbers) { - if (numbers.size() != numbers.stream().distinct().count()) { - throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.getMessage()); - } - } + private void checkNotDuplicated(List numbers) { + if (numbers.size() != numbers.stream().distinct().count()) { + ErrorMessage.DUPLICATED_NUMBERS.print(); + throw new IllegalArgumentException(ErrorMessage.DUPLICATED_NUMBERS.getMessage()); + } + } private void checkInRange(List numbers) { if (!numbers.stream().allMatch(n -> n <= LottoRangeNumber.MAX_LOTTO_NUM.getNum() && n >= LottoRangeNumber.MIN_LOTTO_NUM.getNum())) { + ErrorMessage.OUT_OF_RANGE_NUMBER.print(); throw new IllegalArgumentException(ErrorMessage.OUT_OF_RANGE_NUMBER.getMessage()); } } diff --git a/src/main/java/lotto/service/LottoTicketService.java b/src/main/java/lotto/service/LottoTicketService.java index 53affcb74f..080faaa624 100644 --- a/src/main/java/lotto/service/LottoTicketService.java +++ b/src/main/java/lotto/service/LottoTicketService.java @@ -25,6 +25,7 @@ public List> createLottoTickets(int money) { private void validate(int money) { if (money % MONEY_UNIT != ZERO) { + ErrorMessage.INVALID_OF_MONEY_UNIT.print(); throw new IllegalArgumentException(ErrorMessage.INVALID_OF_MONEY_UNIT.getMessage()); } } From b4c76ddb98e9682cf792c8488ecb525bb4c28fb1 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 16:21:03 +0900 Subject: [PATCH 41/50] =?UTF-8?q?style:=20=EC=BD=94=EB=93=9C=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/LottoRangeNumber.java | 3 +-- src/main/java/lotto/controller/PlayController.java | 7 +------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/lotto/LottoRangeNumber.java b/src/main/java/lotto/LottoRangeNumber.java index 543d7b3d75..64a9e2d809 100644 --- a/src/main/java/lotto/LottoRangeNumber.java +++ b/src/main/java/lotto/LottoRangeNumber.java @@ -3,8 +3,7 @@ public enum LottoRangeNumber { MIN_LOTTO_NUM(1), MAX_LOTTO_NUM(45), - NUM_OF_LOTTO_NUMS(6) - ; + NUM_OF_LOTTO_NUMS(6); private int num; diff --git a/src/main/java/lotto/controller/PlayController.java b/src/main/java/lotto/controller/PlayController.java index e147db9116..1c0c17bae6 100644 --- a/src/main/java/lotto/controller/PlayController.java +++ b/src/main/java/lotto/controller/PlayController.java @@ -18,7 +18,6 @@ public PlayController() { this.answerController = new LottoAnswerController(); } - public void start() { int money = inputMoney(); List> tickets = ticketService.createLottoTickets(money); @@ -27,10 +26,6 @@ public void start() { private int inputMoney() { System.out.println(InputGuide.INPUT_MONEY.getContent()); - int money = inputProcessor.changeToInt(Console.readLine()); - - return money; + return inputProcessor.changeToInt(Console.readLine()); } - - } From a9aa8f666091b17e9d568482975ff0d18cd4747e Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 16:22:01 +0900 Subject: [PATCH 42/50] refactor: IllegalArgumentException -> NoSuchElementException --- src/main/java/lotto/InputProcessor.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/InputProcessor.java b/src/main/java/lotto/InputProcessor.java index 8114b1ea48..b903572398 100644 --- a/src/main/java/lotto/InputProcessor.java +++ b/src/main/java/lotto/InputProcessor.java @@ -2,6 +2,7 @@ import java.util.Arrays; import java.util.List; +import java.util.NoSuchElementException; import java.util.stream.Collectors; public class InputProcessor { @@ -11,7 +12,8 @@ public int changeToInt(String money) { try { return Integer.parseInt(money); } catch (NumberFormatException e) { - throw new IllegalArgumentException(ErrorMessage.NOT_NUMBER.getMessage()); + ErrorMessage.NOT_NUMBER.print(); + throw new NoSuchElementException(ErrorMessage.NOT_NUMBER.getMessage()); } } From 0a2b7c870c38d6929af8dc64c02c0bd4bc2fb3a8 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 16:22:30 +0900 Subject: [PATCH 43/50] =?UTF-8?q?fix:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/lotto/LottoTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/lotto/LottoTest.java b/src/test/java/lotto/LottoTest.java index cee29b5f23..c73d3cbbf4 100644 --- a/src/test/java/lotto/LottoTest.java +++ b/src/test/java/lotto/LottoTest.java @@ -1,5 +1,6 @@ package lotto; +import lotto.repositroy.Lotto; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From 43e1b998f0dba6f8961991edd5a8fba697c7836c Mon Sep 17 00:00:00 2001 From: yeonjy Date: Tue, 29 Aug 2023 16:27:16 +0900 Subject: [PATCH 44/50] =?UTF-8?q?docs:=20=EB=A1=9C=EB=98=90=20=EC=8B=A4?= =?UTF-8?q?=ED=96=89=20=EA=B2=B0=EA=B3=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index 962825ef42..e043b6adea 100644 --- a/docs/README.md +++ b/docs/README.md @@ -45,6 +45,7 @@ ## PlayLottoService - [x] 로또 번호 6개 & 보너스 번호 -> 하나의 DTO로 병합 - [x] 로또 추첨 로직 실행 +- [x] 수익률 출력 ## LottoTicketService - [x] 구입 금액에 따른 로또 개수 계산 @@ -54,12 +55,9 @@ - [x] 로또 티켓 번호 출력 ## OutcomeService -- [ ] 일치 개수 계산 -- [ ] 3개 이상 일치한 로또 필터링 - -## PrizeMoneyService -- [ ] 당청금 계산 -- [ ] 수익률 계산 +- [x] 일치 개수 계산 +- [x] 3개 이상 일치한 로또 필터링 +- [x] 총 수익금 계산 From ca92263b3353abf5aee89c514adec406952900da Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 30 Aug 2023 20:02:01 +0900 Subject: [PATCH 45/50] =?UTF-8?q?feat:=20=ED=8B=B0=EC=BC=93=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/repositroy/LottoTicket.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/lotto/repositroy/LottoTicket.java diff --git a/src/main/java/lotto/repositroy/LottoTicket.java b/src/main/java/lotto/repositroy/LottoTicket.java new file mode 100644 index 0000000000..df6a57954e --- /dev/null +++ b/src/main/java/lotto/repositroy/LottoTicket.java @@ -0,0 +1,25 @@ +package lotto.repositroy; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Collectors; + +public class LottoTicket { + private final List ticket; + + public LottoTicket() { + this.ticket = Randoms.pickUniqueNumbersInRange(LottoRangeNumber.MIN_LOTTO_NUM.getNum() + , LottoRangeNumber.MAX_LOTTO_NUM.getNum(), LottoRangeNumber.NUM_OF_LOTTO_NUMS.getNum()); + } + + public List getSorted() { + return ticket.stream().sorted().collect(Collectors.toList()); + } + + public List toList() { + return ticket; + } +} From 910c71410f5652a6cff49d4a760430b7725534a5 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 30 Aug 2023 20:02:52 +0900 Subject: [PATCH 46/50] refactor: List> -> List --- src/main/java/lotto/PrizeResult.java | 7 ++++--- .../lotto/controller/LottoAnswerController.java | 8 +++++--- .../java/lotto/controller/PlayController.java | 5 ++--- .../lotto/repositroy/LottoTicketGenerator.java | 15 +++++---------- .../java/lotto/service/LottoTicketService.java | 3 ++- src/main/java/lotto/service/OutcomeService.java | 3 ++- src/main/java/lotto/service/PlayLottoService.java | 5 +++-- 7 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/main/java/lotto/PrizeResult.java b/src/main/java/lotto/PrizeResult.java index fd296f1f08..497f219087 100644 --- a/src/main/java/lotto/PrizeResult.java +++ b/src/main/java/lotto/PrizeResult.java @@ -2,6 +2,7 @@ import lotto.dto.AllLottoes; import lotto.repositroy.BonusLotto; +import lotto.repositroy.LottoTicket; import lotto.service.MatchNum; import java.util.*; @@ -27,9 +28,9 @@ private void initializePrizeMoneyMap() { } } - public void makeResult(AllLottoes allLottoes, List> tickets) { - for (List ticket : tickets) { - MatchNum match = checkTicket(ticket, allLottoes); + public void makeResult(AllLottoes allLottoes, List tickets) { + for (LottoTicket ticket : tickets) { + MatchNum match = checkTicket(ticket.toList(), allLottoes); if (match != null) { playResult.put(match, playResult.get(match) + 1); } diff --git a/src/main/java/lotto/controller/LottoAnswerController.java b/src/main/java/lotto/controller/LottoAnswerController.java index cdb75b5ae4..011af02fb0 100644 --- a/src/main/java/lotto/controller/LottoAnswerController.java +++ b/src/main/java/lotto/controller/LottoAnswerController.java @@ -1,8 +1,8 @@ package lotto.controller; import camp.nextstep.edu.missionutils.Console; -import lotto.InputProcessor; import lotto.dto.AllLottoes; +import lotto.repositroy.LottoTicket; import lotto.service.PlayLottoService; import java.util.List; @@ -16,11 +16,13 @@ public LottoAnswerController() { this.playLottoService = new PlayLottoService(); } - public void playLotto(List> tickets, double paidMoney) { + public void playLotto(List tickets, double paidMoney) { List lottoAnswers = inputAnswerNumber(); int bonusAnswer = intputBonusNumber(); - AllLottoes allLottoes = playLottoService.setAllLottoes(lottoAnswers, bonusAnswer); + + AllLottoes allLottoes = playLottoService.getAllLottoes(lottoAnswers, bonusAnswer); long totalPrizeMoney = playLottoService.playLotto(allLottoes, tickets); + playLottoService.printEarningRate(totalPrizeMoney / paidMoney); } diff --git a/src/main/java/lotto/controller/PlayController.java b/src/main/java/lotto/controller/PlayController.java index 1c0c17bae6..7025234392 100644 --- a/src/main/java/lotto/controller/PlayController.java +++ b/src/main/java/lotto/controller/PlayController.java @@ -1,9 +1,8 @@ package lotto.controller; import camp.nextstep.edu.missionutils.Console; -import lotto.InputProcessor; +import lotto.repositroy.LottoTicket; import lotto.service.LottoTicketService; -import lotto.service.OutputGuide; import java.util.List; @@ -20,7 +19,7 @@ public PlayController() { public void start() { int money = inputMoney(); - List> tickets = ticketService.createLottoTickets(money); + List tickets = ticketService.createLottoTickets(money); answerController.playLotto(tickets, money); } diff --git a/src/main/java/lotto/repositroy/LottoTicketGenerator.java b/src/main/java/lotto/repositroy/LottoTicketGenerator.java index ffd67ed031..4b0a713cca 100644 --- a/src/main/java/lotto/repositroy/LottoTicketGenerator.java +++ b/src/main/java/lotto/repositroy/LottoTicketGenerator.java @@ -1,13 +1,13 @@ package lotto.repositroy; import camp.nextstep.edu.missionutils.Randoms; -import lotto.LottoRangeNumber; import java.util.ArrayList; import java.util.List; +import java.util.stream.Collectors; public class LottoTicketGenerator { - private final List> tickets; + private final List tickets; public LottoTicketGenerator() { tickets = new ArrayList<>(); @@ -15,20 +15,15 @@ public LottoTicketGenerator() { public void generateTicket(int ticketNum) { for (int i = 0; i < ticketNum; i++) { - tickets.add(generateNumber()); + tickets.add(new LottoTicket()); } } - private List generateNumber() { - return Randoms.pickUniqueNumbersInRange(LottoRangeNumber.MIN_LOTTO_NUM.getNum() - , LottoRangeNumber.MAX_LOTTO_NUM.getNum(), LottoRangeNumber.NUM_OF_LOTTO_NUMS.getNum()); - } - public List> getSortedTickets() { - return tickets; + return tickets.stream().map(LottoTicket::getSorted).collect(Collectors.toList()); } - public List> getTickets() { + public List getTickets() { return tickets; } } diff --git a/src/main/java/lotto/service/LottoTicketService.java b/src/main/java/lotto/service/LottoTicketService.java index 080faaa624..b7bc4ae668 100644 --- a/src/main/java/lotto/service/LottoTicketService.java +++ b/src/main/java/lotto/service/LottoTicketService.java @@ -1,6 +1,7 @@ package lotto.service; import lotto.ErrorMessage; +import lotto.repositroy.LottoTicket; import lotto.repositroy.LottoTicketGenerator; import java.util.Arrays; @@ -15,7 +16,7 @@ public LottoTicketService() { this.ticketGenerator = new LottoTicketGenerator(); } - public List> createLottoTickets(int money) { + public List createLottoTickets(int money) { validate(money); ticketGenerator.generateTicket(getTicketNum(money)); printTickets(); diff --git a/src/main/java/lotto/service/OutcomeService.java b/src/main/java/lotto/service/OutcomeService.java index 831f2dc89d..80e2a071c2 100644 --- a/src/main/java/lotto/service/OutcomeService.java +++ b/src/main/java/lotto/service/OutcomeService.java @@ -3,6 +3,7 @@ import lotto.PrizeMoney; import lotto.PrizeResult; import lotto.dto.AllLottoes; +import lotto.repositroy.LottoTicket; import java.text.DecimalFormat; import java.util.Arrays; @@ -18,7 +19,7 @@ public OutcomeService() { this.prizeResult = new PrizeResult(); } - public long getTotalPrizeMoney(final AllLottoes allLottoes, final List> tickets) { + public long getTotalPrizeMoney(final AllLottoes allLottoes, final List tickets) { prizeResult.initialize(); prizeResult.makeResult(allLottoes, tickets); printResult(); diff --git a/src/main/java/lotto/service/PlayLottoService.java b/src/main/java/lotto/service/PlayLottoService.java index dcb0692eb7..3ab0995ba5 100644 --- a/src/main/java/lotto/service/PlayLottoService.java +++ b/src/main/java/lotto/service/PlayLottoService.java @@ -4,6 +4,7 @@ import lotto.dto.AllLottoes; import lotto.repositroy.BonusLotto; import lotto.repositroy.Lotto; +import lotto.repositroy.LottoTicket; import java.util.List; @@ -15,13 +16,13 @@ public PlayLottoService() { this.outcomeService = new OutcomeService(); } - public AllLottoes setAllLottoes(List lottoAnswers, int bonusAnswer) { + public AllLottoes getAllLottoes(List lottoAnswers, int bonusAnswer) { Lotto lotto = new Lotto(lottoAnswers); BonusLotto bonusLotto = new BonusLotto(bonusAnswer, lotto.getNumbers()); return new AllLottoes(lotto, bonusLotto); } - public long playLotto(AllLottoes allLottoes, List> tickets) { + public long playLotto(AllLottoes allLottoes, List tickets) { return outcomeService.getTotalPrizeMoney(allLottoes, tickets); } From 1e4e6e217d16637d9216f80931061d2b147a77c6 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 30 Aug 2023 20:04:38 +0900 Subject: [PATCH 47/50] =?UTF-8?q?style:=20Lotto=20&=20LottoRangeNumber=20r?= =?UTF-8?q?epository=20=ED=8C=A8=ED=82=A4=EC=A7=80=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/repositroy/Lotto.java | 1 - src/main/java/lotto/{ => repositroy}/LottoRangeNumber.java | 4 +--- 2 files changed, 1 insertion(+), 4 deletions(-) rename src/main/java/lotto/{ => repositroy}/LottoRangeNumber.java (90%) diff --git a/src/main/java/lotto/repositroy/Lotto.java b/src/main/java/lotto/repositroy/Lotto.java index 1a3ce99938..596609e19b 100644 --- a/src/main/java/lotto/repositroy/Lotto.java +++ b/src/main/java/lotto/repositroy/Lotto.java @@ -1,7 +1,6 @@ package lotto.repositroy; import lotto.ErrorMessage; -import lotto.LottoRangeNumber; import java.util.List; diff --git a/src/main/java/lotto/LottoRangeNumber.java b/src/main/java/lotto/repositroy/LottoRangeNumber.java similarity index 90% rename from src/main/java/lotto/LottoRangeNumber.java rename to src/main/java/lotto/repositroy/LottoRangeNumber.java index 64a9e2d809..5279c5b35a 100644 --- a/src/main/java/lotto/LottoRangeNumber.java +++ b/src/main/java/lotto/repositroy/LottoRangeNumber.java @@ -1,11 +1,10 @@ -package lotto; +package lotto.repositroy; public enum LottoRangeNumber { MIN_LOTTO_NUM(1), MAX_LOTTO_NUM(45), NUM_OF_LOTTO_NUMS(6); - private int num; LottoRangeNumber(int num) { @@ -15,5 +14,4 @@ public enum LottoRangeNumber { public int getNum() { return num; } - } From 3d1fded5f55eb8ef524e7984a92d046c2a93f7b1 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 30 Aug 2023 20:05:47 +0900 Subject: [PATCH 48/50] =?UTF-8?q?style:=20InputProcessor=20controller=20?= =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/{ => controller}/InputProcessor.java | 4 +++- src/main/java/lotto/repositroy/BonusLotto.java | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) rename src/main/java/lotto/{ => controller}/InputProcessor.java (92%) diff --git a/src/main/java/lotto/InputProcessor.java b/src/main/java/lotto/controller/InputProcessor.java similarity index 92% rename from src/main/java/lotto/InputProcessor.java rename to src/main/java/lotto/controller/InputProcessor.java index b903572398..a76760833a 100644 --- a/src/main/java/lotto/InputProcessor.java +++ b/src/main/java/lotto/controller/InputProcessor.java @@ -1,4 +1,6 @@ -package lotto; +package lotto.controller; + +import lotto.ErrorMessage; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/lotto/repositroy/BonusLotto.java b/src/main/java/lotto/repositroy/BonusLotto.java index ff2a7f6cd0..f251a45979 100644 --- a/src/main/java/lotto/repositroy/BonusLotto.java +++ b/src/main/java/lotto/repositroy/BonusLotto.java @@ -1,7 +1,6 @@ package lotto.repositroy; import lotto.ErrorMessage; -import lotto.LottoRangeNumber; import java.util.List; From 616fd21bfac839c050766b35ba8b8c899d367e88 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Wed, 30 Aug 2023 20:06:08 +0900 Subject: [PATCH 49/50] =?UTF-8?q?style:=20=EC=98=88=EC=99=B8=20=EB=AC=B8?= =?UTF-8?q?=EA=B5=AC=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/ErrorMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/lotto/ErrorMessage.java b/src/main/java/lotto/ErrorMessage.java index 195bb49a15..5a46597747 100644 --- a/src/main/java/lotto/ErrorMessage.java +++ b/src/main/java/lotto/ErrorMessage.java @@ -5,7 +5,7 @@ public enum ErrorMessage { DUPLICATED_NUMBERS("[ERROR] 당첨 번호의 중복을 제거해 주세요."), OUT_OF_RANGE_NUMBER("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."), NOT_NUMBER("[ERROR] 정확한 숫자를 입력해 주세요."), - INVALID_OF_MONEY_UNIT("[ERROR] 구입 금액은 1000원 단위 입력해주세요."); + INVALID_OF_MONEY_UNIT("[ERROR] 구입 금액은 1000원 단위로 입력해 주세요."); private final String message; From 7c77afb43ad537316974629365435bd9396baee4 Mon Sep 17 00:00:00 2001 From: yeonjy Date: Thu, 31 Aug 2023 01:22:17 +0900 Subject: [PATCH 50/50] =?UTF-8?q?test:=201000=EC=9B=90=20=EB=8B=A8?= =?UTF-8?q?=EC=9C=84=20=EA=B5=AC=EB=A7=A4=20=EA=B2=80=EC=A6=9D=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/service/LottoTicketServiceTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/test/java/lotto/service/LottoTicketServiceTest.java diff --git a/src/test/java/lotto/service/LottoTicketServiceTest.java b/src/test/java/lotto/service/LottoTicketServiceTest.java new file mode 100644 index 0000000000..76af4692fd --- /dev/null +++ b/src/test/java/lotto/service/LottoTicketServiceTest.java @@ -0,0 +1,21 @@ +package lotto.service; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +class LottoTicketServiceTest { + private final LottoTicketService lottoTicketService = new LottoTicketService(); + + @DisplayName("구매 금액을 1000원 단위로 입력하지 않으면 예외가 발생한다.") + @Test + void createLottoTicketsByInvalidMoneyUnit() { + //given + int testMoney = 1001; + + //when, then + assertThatThrownBy(() -> lottoTicketService.createLottoTickets(testMoney)) + .isInstanceOf(IllegalArgumentException.class); + } +} \ No newline at end of file