From 9cf8de8ffe84bbba800f5e439ea045fbe0df0a31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=99=EC=9B=90?= Date: Mon, 4 Nov 2024 18:05:45 +0900 Subject: [PATCH 1/6] docs : checkPoint --- README.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fa2560b46..f6313677ef 100644 --- a/README.md +++ b/README.md @@ -1 +1,25 @@ -# java-lotto-precourse +# 로또 + +### 체크포인트 + +- [ ] 로또 숫자 범위 상수화 +- [ ] 번호 발행, 중복되지 않는 숫자 6개 +- [ ] 당첨 금액 상수화 +- [ ] 입력 + - [ ] 로또 구입 금액에 따른 로또 발행 + - [ ] 로또 1장 가격 상수화 + - [ ] 당첨 번호 입력 + - [ ] 보너스 번호 입력 +- [ ] 출력 + - [ ] 당첨 내역, 수익률 출력 +- [ ] 예외 처리 + - [ ] 잘못된 값 입력 +- [ ] 테스트 + - [ ] 각 테스트별 메서드 테스트 + - [ ] 실패 태스트 + - [ ] 성공 테스트 + +
+ +### 고민 사항, 생각해볼 점 + From 8613092ea6477f5118a97b675ffaf0e87420ac7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=99=EC=9B=90?= Date: Mon, 4 Nov 2024 19:15:09 +0900 Subject: [PATCH 2/6] docs : checkPoint enum price data --- README.md | 19 ++++++++++++++++--- src/main/java/lotto/Application.java | 11 ++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f6313677ef..fe08021e95 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,8 @@ ### 체크포인트 -- [ ] 로또 숫자 범위 상수화 -- [ ] 번호 발행, 중복되지 않는 숫자 6개 -- [ ] 당첨 금액 상수화 +- [x] 로또 숫자 범위 상수화 +- [x] 당첨 금액 상수화 - [ ] 입력 - [ ] 로또 구입 금액에 따른 로또 발행 - [ ] 로또 1장 가격 상수화 @@ -21,5 +20,19 @@
+ +### 풀이 방향 + +문제의 조건을 위에서 부터 차례대로 만들어가면서 생각나는 대로 만든 후 + +리팩토링을 통해서 정돈할 생각. + +1. 로또 범위, 상금과 같은 상수는 enum 으로 모두 관리 + + (enum 에서 _ 사용해도 되었나?) +2. + + + ### 고민 사항, 생각해볼 점 diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index d190922ba4..a349ea2518 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,7 +1,16 @@ package lotto; +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.List; + +import static lotto.LottoData.*; + + public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + + List winPrice = Randoms.pickUniqueNumbersInRange(START_NUM.getNum(), END_NUM.getNum(), BALLS.getNum()); + Lotto lotto = new Lotto(winPrice); } } From 662bb1422c1e264b44edc142390fd6badfabb799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=99=EC=9B=90?= Date: Mon, 4 Nov 2024 19:47:42 +0900 Subject: [PATCH 3/6] feat : Input class userMoney, checkNumber method --- README.md | 4 ++-- src/main/java/lotto/Input.java | 38 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/java/lotto/Input.java diff --git a/README.md b/README.md index fe08021e95..81f0e3d658 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ - [x] 당첨 금액 상수화 - [ ] 입력 - [ ] 로또 구입 금액에 따른 로또 발행 - - [ ] 로또 1장 가격 상수화 - - [ ] 당첨 번호 입력 + - [x] 로또 1장 가격 상수화 + - [x] 당첨 번호 입력 - [ ] 보너스 번호 입력 - [ ] 출력 - [ ] 당첨 내역, 수익률 출력 diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java new file mode 100644 index 0000000000..beee2aed29 --- /dev/null +++ b/src/main/java/lotto/Input.java @@ -0,0 +1,38 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Console; + +import java.util.ArrayList; +import java.util.List; + +public class Input { + + private int money; + public int useMoney() { + try { + money = Integer.parseInt(input()); + if (money % 1000 == 0) + throw new IllegalArgumentException("[ERROR] : 가격은 1000 단위여야 합니다"); + } catch (NumberFormatException e) { + System.out.println("[ERROR] : 올바른 가격 입력값이 아닙니다"); + useMoney(); + } catch (IllegalArgumentException e) { + useMoney(); + } + + return money; + } + + public List checkNumber() { + String[] numbers = input().split(","); + List balls = new ArrayList<>(); + for (String number : numbers) { + balls.add(Integer.parseInt(number)); + } + return balls; + } + + private String input() { + return Console.readLine(); + } +} From 2d116232faf2839319d458a9125b720bcb425c87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=99=EC=9B=90?= Date: Mon, 4 Nov 2024 21:39:45 +0900 Subject: [PATCH 4/6] feat : MyLotto class save lottos infomatio --- README.md | 31 +++++++++++++++++++++++---- src/main/java/lotto/Application.java | 15 +++++++++++-- src/main/java/lotto/Input.java | 8 +++++-- src/main/java/lotto/LottoData.java | 23 ++++++++++++++++++++ src/main/java/lotto/LottoMachine.java | 20 +++++++++++++++++ src/main/java/lotto/MyLotto.java | 23 ++++++++++++++++++++ src/main/java/lotto/Output.java | 4 ++++ 7 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 src/main/java/lotto/LottoData.java create mode 100644 src/main/java/lotto/LottoMachine.java create mode 100644 src/main/java/lotto/MyLotto.java create mode 100644 src/main/java/lotto/Output.java diff --git a/README.md b/README.md index 81f0e3d658..b8c01be6f2 100644 --- a/README.md +++ b/README.md @@ -4,13 +4,15 @@ - [x] 로또 숫자 범위 상수화 - [x] 당첨 금액 상수화 -- [ ] 입력 - - [ ] 로또 구입 금액에 따른 로또 발행 +- [x] 입력 + - [x] 로또 구입 금액에 따른 로또 발행 - [x] 로또 1장 가격 상수화 - [x] 당첨 번호 입력 - - [ ] 보너스 번호 입력 + - [x] 보너스 번호 입력 - [ ] 출력 - [ ] 당첨 내역, 수익률 출력 +- [ ] 로또 객체 + - [ ] 로또 번호를 오름차순으로 저장 - [ ] 예외 처리 - [ ] 잘못된 값 입력 - [ ] 테스트 @@ -30,9 +32,30 @@ 1. 로또 범위, 상금과 같은 상수는 enum 으로 모두 관리 (enum 에서 _ 사용해도 되었나?) -2. +2. 필요한 객체라 생각되는 것들 + > 로또(객체), 로또번호 생성기, 내가 가지고 있을 로또 용지들, 당첨 결과 계산 할 객체 +3. 로또 머신에서 랜덤 볼들을 받아서 `MyLotto` 에 채워 넣음 +4. 당첨 결과를 계산하고 그 정보를 저장 ### 고민 사항, 생각해볼 점 +고민 1 + +로또를 몇가지 자동 번호를 통해서 만들었을때 그 로또 번호들을 어디에 저장해야 할지? -> 로또 머신에서 번호를 발행하고 모두 저장? + +결론 + +최대한 작은 단위로 나누는게 정답일 것 같아서 `[로또 머신]`, `[나의 로또 현황]`, `[하나의 로또]` 로 나누기로 결정 + + +
+ +고민2 + +`MyLotto` 클래스 안에 로또 용지의 정보와 당첨번호를 저장한다고 할때, 당첨 결과도 저장해야 하는가?, 너무 객체가 커지지 않나? + +결론 + + diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index a349ea2518..b125fe478f 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -10,7 +10,18 @@ public class Application { public static void main(String[] args) { - List winPrice = Randoms.pickUniqueNumbersInRange(START_NUM.getNum(), END_NUM.getNum(), BALLS.getNum()); - Lotto lotto = new Lotto(winPrice); + Input input = new Input(); + LottoMachine lottoMachine = new LottoMachine(); + + int money = input.useMoney(); + Lotto winPrice = input.checkNumber(); + int bonus = input.bonus(); + + MyLotto myLotto = new MyLotto(winPrice, bonus); + + lottoMachine.action(money / 1000, myLotto); + } + + // b z } diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java index beee2aed29..3a5faa40e0 100644 --- a/src/main/java/lotto/Input.java +++ b/src/main/java/lotto/Input.java @@ -23,16 +23,20 @@ public int useMoney() { return money; } - public List checkNumber() { + public Lotto checkNumber() { String[] numbers = input().split(","); List balls = new ArrayList<>(); for (String number : numbers) { balls.add(Integer.parseInt(number)); } - return balls; + return new Lotto(balls); } private String input() { return Console.readLine(); } + + public int bonus() { + return Integer.parseInt(input()); + } } diff --git a/src/main/java/lotto/LottoData.java b/src/main/java/lotto/LottoData.java new file mode 100644 index 0000000000..b386495975 --- /dev/null +++ b/src/main/java/lotto/LottoData.java @@ -0,0 +1,23 @@ +package lotto; + +public enum LottoData { + START_NUM(1), + END_NUM(45), + BALLS(6), + FIRST_PRICE(2000000000), + SECOND_PRICE(30000000), + THIRD_PRICE(1500000), + FOURTH_PRICE(50000), + FIFTH_PRICE(5000), + LOTTO_PRICE(1000) + ; + + private final int num; + LottoData(int range) { + this.num = range; + } + + public int getNum() { + return num; + } +} diff --git a/src/main/java/lotto/LottoMachine.java b/src/main/java/lotto/LottoMachine.java new file mode 100644 index 0000000000..c277004da5 --- /dev/null +++ b/src/main/java/lotto/LottoMachine.java @@ -0,0 +1,20 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Randoms; +import java.util.List; + +import static lotto.LottoData.*; + +public class LottoMachine { + + public void action(int count, MyLotto myLotto) { + int index = 0; + while (index++ < count) { + myLotto.add(randomLottoNumbers()); + } + } + + private Lotto randomLottoNumbers() { + return new Lotto(Randoms.pickUniqueNumbersInRange(START_NUM.getNum(), END_NUM.getNum(), BALLS.getNum())); + } +} diff --git a/src/main/java/lotto/MyLotto.java b/src/main/java/lotto/MyLotto.java new file mode 100644 index 0000000000..6bebac3e0e --- /dev/null +++ b/src/main/java/lotto/MyLotto.java @@ -0,0 +1,23 @@ +package lotto; + +import java.util.ArrayList; +import java.util.List; + +public class MyLotto { + private final List lottos; + private final Lotto winPrice; + private final int bonus; + + public MyLotto(Lotto winPrice, int bonus) { + this.lottos = new ArrayList<>(); + this.winPrice = winPrice; + this.bonus = bonus; + } + + // 이를 통해서만 데이터 추가 가능 + public void add(Lotto lotto) { + lottos.add(lotto); + } + + +} diff --git a/src/main/java/lotto/Output.java b/src/main/java/lotto/Output.java new file mode 100644 index 0000000000..c89aead879 --- /dev/null +++ b/src/main/java/lotto/Output.java @@ -0,0 +1,4 @@ +package lotto; + +public class Output { +} From 93e92142218a9ce62c17680597b8774969317b63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=99=EC=9B=90?= Date: Mon, 4 Nov 2024 23:36:51 +0900 Subject: [PATCH 5/6] feat : method lotto price result --- src/main/java/lotto/LottoData.java | 23 ---------------- src/main/java/lotto/LottoPrice.java | 39 +++++++++++++++++++++++++++ src/main/java/lotto/MyLotto.java | 41 +++++++++++++++++++++++++++++ src/main/java/lotto/PriceStats.java | 18 +++++++++++++ 4 files changed, 98 insertions(+), 23 deletions(-) delete mode 100644 src/main/java/lotto/LottoData.java create mode 100644 src/main/java/lotto/LottoPrice.java create mode 100644 src/main/java/lotto/PriceStats.java diff --git a/src/main/java/lotto/LottoData.java b/src/main/java/lotto/LottoData.java deleted file mode 100644 index b386495975..0000000000 --- a/src/main/java/lotto/LottoData.java +++ /dev/null @@ -1,23 +0,0 @@ -package lotto; - -public enum LottoData { - START_NUM(1), - END_NUM(45), - BALLS(6), - FIRST_PRICE(2000000000), - SECOND_PRICE(30000000), - THIRD_PRICE(1500000), - FOURTH_PRICE(50000), - FIFTH_PRICE(5000), - LOTTO_PRICE(1000) - ; - - private final int num; - LottoData(int range) { - this.num = range; - } - - public int getNum() { - return num; - } -} diff --git a/src/main/java/lotto/LottoPrice.java b/src/main/java/lotto/LottoPrice.java new file mode 100644 index 0000000000..1b63157457 --- /dev/null +++ b/src/main/java/lotto/LottoPrice.java @@ -0,0 +1,39 @@ +package lotto; + +public enum LottoData { + START_NUM(1), + END_NUM(45), + BALLS(6), + FIRST_PRICE(6, 2000000000), + SECOND_PRICE(7, 30000000), + THIRD_PRICE(5, 1500000), + FOURTH_PRICE(4, 50000), + FIFTH_PRICE(3, 5000), + LOTTO_PRICE(1000) + ; + + private final int num; + private final int match; + private final int price; + + LottoData(int range) { + this.num = range; + } + + LottoData(int match, int price) { + this.match = match; + this.price = price; + } + + public int getNum() { + return num; + } + + public int getMatch() { + return match; + } + + public int getPrice() { + return price; + } +} diff --git a/src/main/java/lotto/MyLotto.java b/src/main/java/lotto/MyLotto.java index 6bebac3e0e..3999549690 100644 --- a/src/main/java/lotto/MyLotto.java +++ b/src/main/java/lotto/MyLotto.java @@ -3,12 +3,16 @@ import java.util.ArrayList; import java.util.List; +import static lotto.LottoPrice.*; + public class MyLotto { private final List lottos; private final Lotto winPrice; private final int bonus; + private final PriceStats priceStats; public MyLotto(Lotto winPrice, int bonus) { + this.priceStats = new PriceStats(); this.lottos = new ArrayList<>(); this.winPrice = winPrice; this.bonus = bonus; @@ -19,5 +23,42 @@ public void add(Lotto lotto) { lottos.add(lotto); } + public PriceStats priceResult() { + for (Lotto lotto : lottos) { + isMatchLottoNumbers(lotto); + } + return priceStats; + } + private void isMatchLottoNumbers(Lotto lotto) { + int cnt = 0; + for (Integer number : winPrice.getNumbers()) { + if (lotto.getNumbers().contains(number)) { + cnt++; + } + } + if (cnt == FIRST.getMatch()) { + priceStats.add(4); + return; + } + if (cnt == SECOND.getMatch()) { + isBonusNumber(lotto); + return; + } + if (cnt == FOURTH.getMatch()) { + priceStats.add(1); + return; + } + if (cnt == FIFTH.getMatch()) { + priceStats.add(0); + } + } + + private void isBonusNumber(Lotto lotto) { + if (lotto.getNumbers().contains(bonus)) { + priceStats.add(3); + return; + } + priceStats.add(2); + } } diff --git a/src/main/java/lotto/PriceStats.java b/src/main/java/lotto/PriceStats.java new file mode 100644 index 0000000000..646c59bc91 --- /dev/null +++ b/src/main/java/lotto/PriceStats.java @@ -0,0 +1,18 @@ +package lotto; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class PriceStats { + private final List status; + + public PriceStats() { + status = new ArrayList<>(5); + Collections.fill(status, 0); + } + + public void add(int index) { + status.set(index, status.get(index) + 1); + } +} From fcc16653596408642a80f5e961b62d7da0bfa03e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=99=EC=9B=90?= Date: Mon, 4 Nov 2024 23:57:29 +0900 Subject: [PATCH 6/6] feat : output method --- README.md | 19 +++++++++---------- src/main/java/lotto/Application.java | 17 ++++++++--------- src/main/java/lotto/Input.java | 3 ++- src/main/java/lotto/Lotto.java | 6 +++++- src/main/java/lotto/LottoMachine.java | 12 ++++++++---- src/main/java/lotto/LottoPrice.java | 26 +++++++------------------- src/main/java/lotto/MyLotto.java | 5 +++++ src/main/java/lotto/Output.java | 25 +++++++++++++++++++++++++ src/main/java/lotto/PriceStats.java | 8 ++++++++ 9 files changed, 77 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index b8c01be6f2..6bd112db7a 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,13 @@ - [x] 로또 1장 가격 상수화 - [x] 당첨 번호 입력 - [x] 보너스 번호 입력 -- [ ] 출력 - - [ ] 당첨 내역, 수익률 출력 -- [ ] 로또 객체 - - [ ] 로또 번호를 오름차순으로 저장 -- [ ] 예외 처리 - - [ ] 잘못된 값 입력 -- [ ] 테스트 - - [ ] 각 테스트별 메서드 테스트 - - [ ] 실패 태스트 - - [ ] 성공 테스트 +- [x] 출력 + - [x] 당첨 내역, 수익률 출력 +- [x] 로또 객체 + - [x] 로또 번호를 오름차순으로 저장 +- [x] 예외 처리 + - [x] 잘못된 값 입력 +
@@ -58,4 +55,6 @@ 결론 +실생활로 생각해봤을때 '나' 가 로또 용지를 가지고 있고 당첨 번호를 확인하고 결과를 내가 예측하기에 결과 연산도 `MyLotto` 안에서 이루어지고 결과도 저장하도록 결정 + diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index b125fe478f..204747e310 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,27 +1,26 @@ package lotto; -import camp.nextstep.edu.missionutils.Randoms; - -import java.util.List; - -import static lotto.LottoData.*; - public class Application { public static void main(String[] args) { Input input = new Input(); + Output output = new Output(); LottoMachine lottoMachine = new LottoMachine(); - int money = input.useMoney(); + int lottoTry = input.useMoney(); Lotto winPrice = input.checkNumber(); int bonus = input.bonus(); MyLotto myLotto = new MyLotto(winPrice, bonus); - lottoMachine.action(money / 1000, myLotto); + lottoMachine.action(lottoTry / 1000, myLotto); + Output.currentLottos(myLotto); + + myLotto.priceResult(); + + output.totalPrice(myLotto.priceResult()); } - // b z } diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java index 3a5faa40e0..4bdf28cb73 100644 --- a/src/main/java/lotto/Input.java +++ b/src/main/java/lotto/Input.java @@ -7,6 +7,7 @@ public class Input { + private static final String BUY_RESULT = "개를 구매했습니다."; private int money; public int useMoney() { try { @@ -19,7 +20,7 @@ public int useMoney() { } catch (IllegalArgumentException e) { useMoney(); } - + System.out.println(money / 1000 + BUY_RESULT); return money; } diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java index 88fc5cf12b..12009bc3c9 100644 --- a/src/main/java/lotto/Lotto.java +++ b/src/main/java/lotto/Lotto.java @@ -1,5 +1,6 @@ package lotto; +import java.util.Collections; import java.util.List; public class Lotto { @@ -14,7 +15,10 @@ private void validate(List numbers) { if (numbers.size() != 6) { throw new IllegalArgumentException("[ERROR] 로또 번호는 6개여야 합니다."); } + Collections.sort(numbers); } - // TODO: 추가 기능 구현 + public List getNumbers() { + return numbers; + } } diff --git a/src/main/java/lotto/LottoMachine.java b/src/main/java/lotto/LottoMachine.java index c277004da5..44984dcc1e 100644 --- a/src/main/java/lotto/LottoMachine.java +++ b/src/main/java/lotto/LottoMachine.java @@ -1,12 +1,14 @@ package lotto; import camp.nextstep.edu.missionutils.Randoms; -import java.util.List; - -import static lotto.LottoData.*; public class LottoMachine { + static final int START_NUM = 1; + static final int END_NUM = 45; + static final int BALLS = 6; + + public void action(int count, MyLotto myLotto) { int index = 0; while (index++ < count) { @@ -15,6 +17,8 @@ public void action(int count, MyLotto myLotto) { } private Lotto randomLottoNumbers() { - return new Lotto(Randoms.pickUniqueNumbersInRange(START_NUM.getNum(), END_NUM.getNum(), BALLS.getNum())); + return new Lotto(Randoms.pickUniqueNumbersInRange(START_NUM, END_NUM, BALLS)); } + + } diff --git a/src/main/java/lotto/LottoPrice.java b/src/main/java/lotto/LottoPrice.java index 1b63157457..1197325e7e 100644 --- a/src/main/java/lotto/LottoPrice.java +++ b/src/main/java/lotto/LottoPrice.java @@ -1,34 +1,22 @@ package lotto; -public enum LottoData { - START_NUM(1), - END_NUM(45), - BALLS(6), - FIRST_PRICE(6, 2000000000), - SECOND_PRICE(7, 30000000), - THIRD_PRICE(5, 1500000), - FOURTH_PRICE(4, 50000), - FIFTH_PRICE(3, 5000), - LOTTO_PRICE(1000) +public enum LottoPrice { + FIRST(6, 2000000000), + SECOND(5, 30000000), + THIRD(5, 1500000), + FOURTH(4, 50000), + FIFTH(3, 5000) ; - private final int num; private final int match; private final int price; - LottoData(int range) { - this.num = range; - } - LottoData(int match, int price) { + LottoPrice(int match, int price) { this.match = match; this.price = price; } - public int getNum() { - return num; - } - public int getMatch() { return match; } diff --git a/src/main/java/lotto/MyLotto.java b/src/main/java/lotto/MyLotto.java index 3999549690..cb9715582b 100644 --- a/src/main/java/lotto/MyLotto.java +++ b/src/main/java/lotto/MyLotto.java @@ -6,6 +6,7 @@ import static lotto.LottoPrice.*; public class MyLotto { + private final List lottos; private final Lotto winPrice; private final int bonus; @@ -30,6 +31,10 @@ public PriceStats priceResult() { return priceStats; } + public List getLottos() { + return lottos; + } + private void isMatchLottoNumbers(Lotto lotto) { int cnt = 0; for (Integer number : winPrice.getNumbers()) { diff --git a/src/main/java/lotto/Output.java b/src/main/java/lotto/Output.java index c89aead879..5b7ce6be2a 100644 --- a/src/main/java/lotto/Output.java +++ b/src/main/java/lotto/Output.java @@ -1,4 +1,29 @@ package lotto; +import java.time.LocalDate; +import java.util.stream.Collectors; + public class Output { + static final String FIFTH = "3개 일치 (5,000원) - "; + static final String FOURTH = "4개 일치 (50,000원) - 개"; + static final String THIRD = "5개 일치 (1,500,000원) - 개"; + static final String SECOND = "5개 일치, 보너스 볼 일치 (30,000,000원) - 개"; + static final String FIRST = "6개 일치 (2,000,000,000원) - 개"; + public static void currentLottos(MyLotto myLotto) { + for (Lotto lotto : myLotto.getLottos()) { + String balls = lotto.getNumbers().stream() + .map(String::valueOf) + .collect(Collectors.joining(", ")); + System.out.println("[" + balls + "]"); + } + System.out.println(); + } + + public void totalPrice(PriceStats priceStats) { + System.out.println(FIFTH + priceStats.get(0) + "개"); + System.out.println(FOURTH + priceStats.get(1) + "개"); + System.out.println(THIRD + priceStats.get(2) + "개"); + System.out.println(SECOND + priceStats.get(3) + "개"); + System.out.println(FIRST + priceStats.get(4) + "개"); + } } diff --git a/src/main/java/lotto/PriceStats.java b/src/main/java/lotto/PriceStats.java index 646c59bc91..de80c98eb3 100644 --- a/src/main/java/lotto/PriceStats.java +++ b/src/main/java/lotto/PriceStats.java @@ -15,4 +15,12 @@ public PriceStats() { public void add(int index) { status.set(index, status.get(index) + 1); } + + public List getStatus() { + return status; + } + + public Integer get(int i) { + return status.get(i); + } }