From 5363326c7cb1766c8389b662a3a807e89ac7c15e Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Wed, 1 May 2024 20:47:37 +0900 Subject: [PATCH 01/12] =?UTF-8?q?Docs:=20readme=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..bd8dc4c2 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +## Lotto +- 크기가 6인 int List : numbers + - 1 ~ 45 사이의 숫자 + - 중복되지 않아야 함 + +[ ] 로또 금액을 입력 받아야 함 + [ ] 1000원 단위로 입력 + [ ] 최소 1000원 이상 +[ ] 로또 번호는 랜덤으로 설정 + [ ] 숫자들끼리 중복되지 않도록 + [ ] 1 ~ 45 사이 +[ ] 출력 시 숫자들이 오름차순으로 정렬 From 2f27c66c150cc83e9e85751952c7cf8b283cce1c Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Wed, 1 May 2024 20:58:38 +0900 Subject: [PATCH 02/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/LottoNumber.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/main/java/LottoNumber.java diff --git a/README.md b/README.md index bd8dc4c2..558a02f4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Lotto - 크기가 6인 int List : numbers - - 1 ~ 45 사이의 숫자 + - [x] 1 ~ 45 사이의 숫자 - 중복되지 않아야 함 [ ] 로또 금액을 입력 받아야 함 diff --git a/src/main/java/LottoNumber.java b/src/main/java/LottoNumber.java new file mode 100644 index 00000000..cbb542d0 --- /dev/null +++ b/src/main/java/LottoNumber.java @@ -0,0 +1,18 @@ +public class LottoNumber { + + public static final int MIN_VALUE = 0; + public static final int MAX_VALUE = 45; + + private final int number; + + public LottoNumber(int number) { + validateRange(number); + this.number = number; + } + + private void validateRange(int number) { + if (number < MIN_VALUE || number > MAX_VALUE) { + throw new IllegalArgumentException(); + } + } +} From ffec0c5138f43de44eb045ec831c38ee6199bd78 Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Wed, 1 May 2024 21:13:42 +0900 Subject: [PATCH 03/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 ++++++++------ src/main/java/Lotto.java | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 src/main/java/Lotto.java diff --git a/README.md b/README.md index 558a02f4..e4346601 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,14 @@ ## Lotto + - 크기가 6인 int List : numbers - - [x] 1 ~ 45 사이의 숫자 - - 중복되지 않아야 함 + - [x] 1 ~ 45 사이의 숫자 + - [x] 중복되지 않아야 함 + - [x] 크기가 6이어야 함 [ ] 로또 금액을 입력 받아야 함 - [ ] 1000원 단위로 입력 - [ ] 최소 1000원 이상 +[ ] 1000원 단위로 입력 +[ ] 최소 1000원 이상 [ ] 로또 번호는 랜덤으로 설정 - [ ] 숫자들끼리 중복되지 않도록 - [ ] 1 ~ 45 사이 +[ ] 숫자들끼리 중복되지 않도록 +[ ] 1 ~ 45 사이 [ ] 출력 시 숫자들이 오름차순으로 정렬 diff --git a/src/main/java/Lotto.java b/src/main/java/Lotto.java new file mode 100644 index 00000000..7dd3e695 --- /dev/null +++ b/src/main/java/Lotto.java @@ -0,0 +1,32 @@ +import java.util.List; + +public class Lotto { + + public static final int LOTTO_SIZE = 6; + + private final List numbers; + + public Lotto(List numbers) { + validate(numbers); + this.numbers = numbers; + } + + private void validate(List numbers) { + validateSize(numbers); + validateDuplication(numbers); + } + + private void validateSize(List numbers) { + if (numbers.size() != LOTTO_SIZE) { + throw new IllegalArgumentException(); + } + } + + private void validateDuplication(List numbers) { + long duplicatedSize = numbers.stream().distinct().count(); + if (numbers.size() != duplicatedSize) { + throw new IllegalArgumentException(); + } + } + +} From 36e7a0d59c0de97a69a4e181fe5259512651fccd Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Wed, 1 May 2024 21:20:50 +0900 Subject: [PATCH 04/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B0=80?= =?UTF-8?q?=EA=B2=A9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +++++++------- src/main/java/LottoPrice.java | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 src/main/java/LottoPrice.java diff --git a/README.md b/README.md index e4346601..3761c131 100644 --- a/README.md +++ b/README.md @@ -5,10 +5,10 @@ - [x] 중복되지 않아야 함 - [x] 크기가 6이어야 함 -[ ] 로또 금액을 입력 받아야 함 -[ ] 1000원 단위로 입력 -[ ] 최소 1000원 이상 -[ ] 로또 번호는 랜덤으로 설정 -[ ] 숫자들끼리 중복되지 않도록 -[ ] 1 ~ 45 사이 -[ ] 출력 시 숫자들이 오름차순으로 정렬 +- [ ] 로또 금액을 입력 받아야 함 +- [x] 1000원 단위로 입력 +- [x] 최소 1000원 이상 +- [ ] 로또 번호는 랜덤으로 설정 +- [ ] 숫자들끼리 중복되지 않도록 +- [ ] 1 ~ 45 사이 +- [ ] 출력 시 숫자들이 오름차순으로 정렬 diff --git a/src/main/java/LottoPrice.java b/src/main/java/LottoPrice.java new file mode 100644 index 00000000..2f81a3b6 --- /dev/null +++ b/src/main/java/LottoPrice.java @@ -0,0 +1,30 @@ +public class LottoPrice { + + public static final int MIN_PRICE = 0; + public static final int PRICE_UNIT = 1_000; + + private final int price; + + public LottoPrice(int price) { + validate(price); + this.price = price; + } + + private void validate(int price) { + validateRange(price); + validateUnit(price); + } + + + private void validateRange(int price) { + if (price < MIN_PRICE) { + throw new IllegalArgumentException(); + } + } + + private void validateUnit(int price) { + if (price % PRICE_UNIT != 0) { + throw new IllegalArgumentException(); + } + } +} From 178bc0ea0ee6c77ac10cc1275ac9f8be35ee3a11 Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Wed, 1 May 2024 21:26:17 +0900 Subject: [PATCH 05/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B0=80?= =?UTF-8?q?=EA=B2=A9=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/InputView.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 src/main/java/InputView.java diff --git a/README.md b/README.md index 3761c131..ae143eb1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ - [x] 중복되지 않아야 함 - [x] 크기가 6이어야 함 -- [ ] 로또 금액을 입력 받아야 함 +- [x] 로또 금액을 입력 받아야 함 - [x] 1000원 단위로 입력 - [x] 최소 1000원 이상 - [ ] 로또 번호는 랜덤으로 설정 diff --git a/src/main/java/InputView.java b/src/main/java/InputView.java new file mode 100644 index 00000000..779c0ee4 --- /dev/null +++ b/src/main/java/InputView.java @@ -0,0 +1,11 @@ +import java.util.Scanner; + +public class InputView { + + public static final Scanner SCANNER = new Scanner(System.in); + + public int inputLottoPrice() { + System.out.println("구입금액을 입력해 주세요."); + return SCANNER.nextInt(); + } +} From 6d2244cc2c1cb68faadd3bc8356e92abdcb4820b Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Wed, 1 May 2024 21:38:21 +0900 Subject: [PATCH 06/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=9E=9C?= =?UTF-8?q?=EB=8D=A4=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 6 +++--- src/main/java/RandomLottoGenerator.java | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/main/java/RandomLottoGenerator.java diff --git a/README.md b/README.md index ae143eb1..81cd3f16 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ - [x] 로또 금액을 입력 받아야 함 - [x] 1000원 단위로 입력 - [x] 최소 1000원 이상 -- [ ] 로또 번호는 랜덤으로 설정 -- [ ] 숫자들끼리 중복되지 않도록 -- [ ] 1 ~ 45 사이 +- [x] 로또 번호는 랜덤으로 설정 +- [x] 숫자들끼리 중복되지 않도록 +- [x] 1 ~ 45 사이 - [ ] 출력 시 숫자들이 오름차순으로 정렬 diff --git a/src/main/java/RandomLottoGenerator.java b/src/main/java/RandomLottoGenerator.java new file mode 100644 index 00000000..cd18fcbf --- /dev/null +++ b/src/main/java/RandomLottoGenerator.java @@ -0,0 +1,23 @@ +import java.util.HashSet; +import java.util.List; +import java.util.Random; +import java.util.Set; + +public class RandomLottoGenerator { + + + public static final Random RANDOM = new Random(); + + public Lotto generateLotto() { + Set numbers = new HashSet<>(); + while (numbers.size() < 6) { + int randomNumber = RANDOM.nextInt(1, 45); + numbers.add(randomNumber); + } + + List lottoNumbers = numbers.stream() + .map(LottoNumber::new) + .toList(); + return new Lotto(lottoNumbers); + } +} From 82d43772f6b762cfd6a96d92b78f0624c664fd2b Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Sun, 5 May 2024 14:02:44 +0900 Subject: [PATCH 07/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=88=AB?= =?UTF-8?q?=EC=9E=90=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Lotto.java | 6 ++++++ src/main/java/LottoNumber.java | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/Lotto.java b/src/main/java/Lotto.java index 7dd3e695..19226081 100644 --- a/src/main/java/Lotto.java +++ b/src/main/java/Lotto.java @@ -1,3 +1,4 @@ +import java.util.Collections; import java.util.List; public class Lotto { @@ -8,6 +9,7 @@ public class Lotto { public Lotto(List numbers) { validate(numbers); + sortNumbers(numbers); this.numbers = numbers; } @@ -29,4 +31,8 @@ private void validateDuplication(List numbers) { } } + private void sortNumbers(List numbers) { + Collections.sort(numbers); + } + } diff --git a/src/main/java/LottoNumber.java b/src/main/java/LottoNumber.java index cbb542d0..77a9366a 100644 --- a/src/main/java/LottoNumber.java +++ b/src/main/java/LottoNumber.java @@ -1,4 +1,4 @@ -public class LottoNumber { +public class LottoNumber implements Comparable { public static final int MIN_VALUE = 0; public static final int MAX_VALUE = 45; @@ -15,4 +15,9 @@ private void validateRange(int number) { throw new IllegalArgumentException(); } } + + @Override + public int compareTo(LottoNumber o) { + return Integer.compare(this.number, o.number); + } } From ec97e4ed607f4f6d6a3e0ae14f7d06c6fe22824b Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Mon, 6 May 2024 15:59:27 +0900 Subject: [PATCH 08/12] =?UTF-8?q?test:=20=EB=A1=9C=EB=98=90=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=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/main/java/LottoPrice.java | 4 ++-- src/test/java/LottoPriceTest.java | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 src/test/java/LottoPriceTest.java diff --git a/src/main/java/LottoPrice.java b/src/main/java/LottoPrice.java index 2f81a3b6..79d5d122 100644 --- a/src/main/java/LottoPrice.java +++ b/src/main/java/LottoPrice.java @@ -18,13 +18,13 @@ private void validate(int price) { private void validateRange(int price) { if (price < MIN_PRICE) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("로또 금액은 0이상 이어야 한다."); } } private void validateUnit(int price) { if (price % PRICE_UNIT != 0) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("로또 금액은 1000원 단위여야 한다."); } } } diff --git a/src/test/java/LottoPriceTest.java b/src/test/java/LottoPriceTest.java new file mode 100644 index 00000000..660b3c64 --- /dev/null +++ b/src/test/java/LottoPriceTest.java @@ -0,0 +1,19 @@ +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; + +public class LottoPriceTest { + @Test + void 로또_금액은_0이상_이어야_한다() { + int price = -1000; + + assertThatThrownBy(() -> new LottoPrice(price)).isInstanceOf(IllegalArgumentException.class).hasMessage("로또 금액은 0이상 이어야 한다."); + } + + @Test + void 로또_금액은_1000원_단위여야_한다() { + int price = 9999; + + assertThatThrownBy(() -> new LottoPrice(price)).isInstanceOf(IllegalArgumentException.class).hasMessage("로또 금액은 1000원 단위여야 한다."); + } +} From f3dd79d7c2db27678aec4c7125fcd49a35d6add6 Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Mon, 6 May 2024 16:23:03 +0900 Subject: [PATCH 09/12] =?UTF-8?q?test:=20=EB=A1=9C=EB=98=90=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 --- src/main/java/Lotto.java | 7 ++-- src/test/java/LottoTest.java | 36 +++++++++++++++++++++ src/test/java/RandomLottoGeneratorTest.java | 15 +++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/test/java/LottoTest.java create mode 100644 src/test/java/RandomLottoGeneratorTest.java diff --git a/src/main/java/Lotto.java b/src/main/java/Lotto.java index 19226081..065f6b72 100644 --- a/src/main/java/Lotto.java +++ b/src/main/java/Lotto.java @@ -20,14 +20,14 @@ private void validate(List numbers) { private void validateSize(List numbers) { if (numbers.size() != LOTTO_SIZE) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("로또는 6개의 수로 이루어져야 한다. "); } } private void validateDuplication(List numbers) { long duplicatedSize = numbers.stream().distinct().count(); if (numbers.size() != duplicatedSize) { - throw new IllegalArgumentException(); + throw new IllegalArgumentException("로또 숫자는 중복이 없어야 한다. "); } } @@ -35,4 +35,7 @@ private void sortNumbers(List numbers) { Collections.sort(numbers); } + public List numbers() { + return List.copyOf(numbers); + } } diff --git a/src/test/java/LottoTest.java b/src/test/java/LottoTest.java new file mode 100644 index 00000000..2c1149b8 --- /dev/null +++ b/src/test/java/LottoTest.java @@ -0,0 +1,36 @@ +import org.junit.jupiter.api.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; + +public class LottoTest { + @Test + void 로또는_6개의_수로_이루어져야_한다() { + var numbers = List.of(new LottoNumber(1), new LottoNumber(2), new LottoNumber(3)); + + assertThatThrownBy(() -> new Lotto(numbers)).isInstanceOf(IllegalArgumentException.class).hasMessage("로또는 6개의 수로 이루어져야 한다. "); + } + + // fail + @Test + void 로또_숫자는_중복이_없어야_한다() { + var numbers = List.of(new LottoNumber(1), new LottoNumber(1), new LottoNumber(2), new LottoNumber(3), new LottoNumber(4), new LottoNumber(5)); + + assertThatThrownBy(() -> new Lotto(numbers)).isInstanceOf(IllegalArgumentException.class).hasMessage("로또 숫자는 중복이 없어야 한다. "); + } + + // fail + @Test + void 로또_숫자는_오름차순_정렬되어있다() { + var unsortedNumbers = List.of(new LottoNumber(6), new LottoNumber(5), new LottoNumber(4), new LottoNumber(3), new LottoNumber(2), new LottoNumber(1)); + var sortedNumbers = List.of(new LottoNumber(1), new LottoNumber(2), new LottoNumber(3), new LottoNumber(4), new LottoNumber(5), new LottoNumber(6)); + + var unsortedLotto = new Lotto(unsortedNumbers); + var sortedLotto = new Lotto(sortedNumbers); + + assertThat(unsortedLotto.numbers().equals(sortedLotto.numbers())); + // assertThat(unsortedLotto.numbers()).isSorted(); + } +} diff --git a/src/test/java/RandomLottoGeneratorTest.java b/src/test/java/RandomLottoGeneratorTest.java new file mode 100644 index 00000000..e58e1288 --- /dev/null +++ b/src/test/java/RandomLottoGeneratorTest.java @@ -0,0 +1,15 @@ +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.RepeatedTest; + +import java.util.Random; + +class RandomLottoGeneratorTest { + + @RepeatedTest(1000) + void test() { + int result = new Random().nextInt(1, 45); + + Assertions.assertThat(result).isBetween(1, 45); + } + +} \ No newline at end of file From 94e3c00aafa7806c7a6cfbde4dfe637a13e16930 Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Mon, 6 May 2024 22:49:46 +0900 Subject: [PATCH 10/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B2=8C?= =?UTF-8?q?=EC=9E=84=20=EC=8B=A4=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Lotto.java | 6 +++--- src/main/java/LottoGame.java | 32 ++++++++++++++++++++++++++++++++ src/main/java/LottoPrice.java | 4 ++++ src/main/java/OutputView.java | 11 +++++++++++ src/test/java/LottoTest.java | 8 ++++---- 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 src/main/java/LottoGame.java create mode 100644 src/main/java/OutputView.java diff --git a/src/main/java/Lotto.java b/src/main/java/Lotto.java index 065f6b72..fac83aa2 100644 --- a/src/main/java/Lotto.java +++ b/src/main/java/Lotto.java @@ -9,8 +9,7 @@ public class Lotto { public Lotto(List numbers) { validate(numbers); - sortNumbers(numbers); - this.numbers = numbers; + this.numbers = sortNumbers(numbers); } private void validate(List numbers) { @@ -31,8 +30,9 @@ private void validateDuplication(List numbers) { } } - private void sortNumbers(List numbers) { + private List sortNumbers(List numbers) { Collections.sort(numbers); + return numbers; } public List numbers() { diff --git a/src/main/java/LottoGame.java b/src/main/java/LottoGame.java new file mode 100644 index 00000000..4141d83a --- /dev/null +++ b/src/main/java/LottoGame.java @@ -0,0 +1,32 @@ +import java.util.ArrayList; +import java.util.List; + +public class LottoGame { + + private final InputView inputView; + private final OutputView outputView; + + public LottoGame(InputView inputView, OutputView outputView) { + this.inputView = inputView; + this.outputView = outputView; + } + + public void run() { + int inputPrice = inputView.inputLottoPrice(); + LottoPrice price = new LottoPrice(inputPrice); + List lottos = getLottos(price); + outputView.printLotto(lottos); + } + + private List getLottos(LottoPrice price) { + List lottos = new ArrayList<>(); + + RandomLottoGenerator randomLottoGenerator = new RandomLottoGenerator(); + + for (int i = 0; i < price.getPrice() / 1000; i++) { + lottos.add(new Lotto(randomLottoGenerator.generateLotto().numbers())); + } + + return lottos; + } +} diff --git a/src/main/java/LottoPrice.java b/src/main/java/LottoPrice.java index 79d5d122..5cb4dc42 100644 --- a/src/main/java/LottoPrice.java +++ b/src/main/java/LottoPrice.java @@ -27,4 +27,8 @@ private void validateUnit(int price) { throw new IllegalArgumentException("로또 금액은 1000원 단위여야 한다."); } } + + public int getPrice() { + return price; + } } diff --git a/src/main/java/OutputView.java b/src/main/java/OutputView.java new file mode 100644 index 00000000..5bd6a6f5 --- /dev/null +++ b/src/main/java/OutputView.java @@ -0,0 +1,11 @@ +import java.util.List; + +public class OutputView { + + public void printLotto(List lottos) { + System.out.println(); + System.out.println(lottos.size() + "개를 구매했습니다."); + lottos.stream().map(Lotto::numbers).forEach(System.out::println); + } + +} diff --git a/src/test/java/LottoTest.java b/src/test/java/LottoTest.java index 2c1149b8..470d63b6 100644 --- a/src/test/java/LottoTest.java +++ b/src/test/java/LottoTest.java @@ -25,12 +25,12 @@ public class LottoTest { @Test void 로또_숫자는_오름차순_정렬되어있다() { var unsortedNumbers = List.of(new LottoNumber(6), new LottoNumber(5), new LottoNumber(4), new LottoNumber(3), new LottoNumber(2), new LottoNumber(1)); - var sortedNumbers = List.of(new LottoNumber(1), new LottoNumber(2), new LottoNumber(3), new LottoNumber(4), new LottoNumber(5), new LottoNumber(6)); + // var sortedNumbers = List.of(new LottoNumber(1), new LottoNumber(2), new LottoNumber(3), new LottoNumber(4), new LottoNumber(5), new LottoNumber(6)); var unsortedLotto = new Lotto(unsortedNumbers); - var sortedLotto = new Lotto(sortedNumbers); + // var sortedLotto = new Lotto(sortedNumbers); - assertThat(unsortedLotto.numbers().equals(sortedLotto.numbers())); - // assertThat(unsortedLotto.numbers()).isSorted(); + //assertThat(unsortedLotto.numbers().equals(sortedLotto.numbers())); + assertThat(unsortedLotto.numbers()).isSorted(); } } From 357ac73da99c519ab7376934188ebf792758e508 Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Mon, 6 May 2024 23:11:21 +0900 Subject: [PATCH 11/12] =?UTF-8?q?docs:=20step2=20readme=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 81cd3f16..c60fb9c7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ ## Lotto +### step1 + - 크기가 6인 int List : numbers - [x] 1 ~ 45 사이의 숫자 - [x] 중복되지 않아야 함 @@ -11,4 +13,20 @@ - [x] 로또 번호는 랜덤으로 설정 - [x] 숫자들끼리 중복되지 않도록 - [x] 1 ~ 45 사이 -- [ ] 출력 시 숫자들이 오름차순으로 정렬 +- [x] 출력 시 숫자들이 오름차순으로 정렬 + +### step2 + +<프로그래밍 요구사항> + +- [ ] 원시값 포장 +- [ ] 문자열 포장 +- [ ] 일급 컬렉션 사용 + +<구현 해야하는 기능> + +- [ ] 당첨 번호 입력 + - [ ] 문자열의 형태로 입력 +- [ ] 당첨 통계 출력 + - [ ] 당첨 금액 & 개수 별 출력 + - [ ] 총 수익률 계산 \ No newline at end of file From 709f187ee1f8b796e4e1d39e2eb4a60920217dad Mon Sep 17 00:00:00 2001 From: "jieun4510@sju.ac.kr" Date: Mon, 6 May 2024 23:31:27 +0900 Subject: [PATCH 12/12] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- src/main/java/InputView.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c60fb9c7..ce9bcbeb 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ <구현 해야하는 기능> -- [ ] 당첨 번호 입력 - - [ ] 문자열의 형태로 입력 +- [x] 당첨 번호 입력 + - [x] 문자열의 형태로 입력 - [ ] 당첨 통계 출력 - [ ] 당첨 금액 & 개수 별 출력 - [ ] 총 수익률 계산 \ No newline at end of file diff --git a/src/main/java/InputView.java b/src/main/java/InputView.java index 779c0ee4..20ff2fcb 100644 --- a/src/main/java/InputView.java +++ b/src/main/java/InputView.java @@ -1,3 +1,5 @@ +import java.util.Arrays; +import java.util.List; import java.util.Scanner; public class InputView { @@ -8,4 +10,17 @@ public int inputLottoPrice() { System.out.println("구입금액을 입력해 주세요."); return SCANNER.nextInt(); } + + public Lotto inputLottoNumbers() { + System.out.println("지난 주 당첨 번호를 입력해 주세요."); + return stringToLotto(SCANNER.nextLine()); + } + + public Lotto stringToLotto(String string) { + List numbers = Arrays.stream(string.split(",")).map(Integer::parseInt).toList(); + List lottoNumbers = numbers.stream() + .map(LottoNumber::new) + .toList(); + return new Lotto(lottoNumbers); + } }