From f0573f79fdc8cfcdadf46b75d1f5aff90553b5c5 Mon Sep 17 00:00:00 2001 From: rkolx Date: Thu, 24 Feb 2022 22:42:52 +0900 Subject: [PATCH 01/14] =?UTF-8?q?feat=20:=20Input=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4,=20Main=20=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 | 2 +- src/views/Input.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 4a76e67d..f07a7d1a 100644 --- a/src/Main.java +++ b/src/Main.java @@ -27,7 +27,7 @@ public static void main(String[] args) { List winningNumbers = inputWinningNumbers(); List threeOrMore = lottos.numberOfWinningAboveThree(winningNumbers); - + int bonusNumber = getBonusNumber(); getResultOfLotto(purchaseAmount, threeOrMore); scanClose(); diff --git a/src/views/Input.java b/src/views/Input.java index c3a52e0d..a613cc2a 100644 --- a/src/views/Input.java +++ b/src/views/Input.java @@ -17,6 +17,12 @@ public class Input { public Input() { } + public static int getBonusNumber(){ + println.accept("보너스 볼을 입력해주세요."); + int bonusNumber = nextInt(); + return bonusNumber; + } + public static List inputWinningNumbers(){ println.accept(OUTPUT_ASK_WINNING_NUMBER); String textNumbers = nextLine(); From d069d61a633604798e15949b3a155351794f505b Mon Sep 17 00:00:00 2001 From: rkolx Date: Thu, 24 Feb 2022 22:56:51 +0900 Subject: [PATCH 02/14] =?UTF-8?q?refactor=20:=20=EB=8B=B9=EC=B2=A8?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EB=AA=A8=EC=9D=8C=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=B0=8F=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EB=AA=85?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - WinningNumber 클래스 생성 - Winnings 클래스에서 WinningNumberCouter로 클래스 명 수정 --- src/Main.java | 4 ++-- src/domains/Ranking.java | 8 +++---- src/domains/WinningNumbers.java | 21 +++++++++++++++++++ ...nnings.java => WinningNumbersCounter.java} | 4 ++-- 4 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 src/domains/WinningNumbers.java rename src/domains/{Winnings.java => WinningNumbersCounter.java} (85%) diff --git a/src/Main.java b/src/Main.java index f07a7d1a..c2eaec0f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -8,7 +8,7 @@ import domains.LottoMachine; import domains.Lottos; import domains.Ranking; -import domains.Winnings; +import domains.WinningNumbersCounter; public class Main { private static final int IDX_PURCHASED_AMOUNT = 0; @@ -34,7 +34,7 @@ public static void main(String[] args) { } private static void getResultOfLotto(int purchaseAmount, List threeOrMore) { - Winnings winnings = new Winnings(threeOrMore); + WinningNumbersCounter winnings = new WinningNumbersCounter(threeOrMore); Ranking ranking = new Ranking(winnings); Map ranks = ranking.resultOfRanks(); diff --git a/src/domains/Ranking.java b/src/domains/Ranking.java index b363cf27..8a726c9f 100644 --- a/src/domains/Ranking.java +++ b/src/domains/Ranking.java @@ -7,9 +7,9 @@ public class Ranking { public static final int TO_PERCENT = 100; private Map ranks = new LinkedHashMap<>(); - private Winnings winnings; + private WinningNumbersCounter winnings; - public Ranking(Winnings winnings) { + public Ranking(WinningNumbersCounter winnings) { this.ranks = initializeRanks(); this.winnings = winnings; } @@ -36,8 +36,8 @@ private boolean isSame(int number) { private Rank of(int number) { return Arrays.stream(values()) - .filter(ranks -> ranks.isSame(number)) - .findFirst().get(); + .filter(ranks -> ranks.isSame(number)) + .findFirst().get(); } public String getText() { diff --git a/src/domains/WinningNumbers.java b/src/domains/WinningNumbers.java new file mode 100644 index 00000000..9e0c4372 --- /dev/null +++ b/src/domains/WinningNumbers.java @@ -0,0 +1,21 @@ +package domains; + +import java.util.List; + +public class WinningNumbers { + private final List winningNumbers; + private int bonusBall; + + public WinningNumbers(List winningNumbers, int bonusBall) { + this.winningNumbers = winningNumbers; + this.bonusBall = bonusBall; + } + + public List getNumbers() { + return this.winningNumbers; + } + + public int getBonusBall() { + return bonusBall; + } +} diff --git a/src/domains/Winnings.java b/src/domains/WinningNumbersCounter.java similarity index 85% rename from src/domains/Winnings.java rename to src/domains/WinningNumbersCounter.java index 30a1c0ea..79e9f8cb 100644 --- a/src/domains/Winnings.java +++ b/src/domains/WinningNumbersCounter.java @@ -4,10 +4,10 @@ import java.util.List; import java.util.Map; -public class Winnings { +public class WinningNumbersCounter { private final Map counts; - public Winnings(List threeOrMore) { + public WinningNumbersCounter(List threeOrMore) { this.counts = getNumberOfEachRanks(threeOrMore); } From 8d41897f1398cb2dd888f88540d8f037873ca76c Mon Sep 17 00:00:00 2001 From: rkolx Date: Thu, 24 Feb 2022 23:00:55 +0900 Subject: [PATCH 03/14] =?UTF-8?q?=20feat=20:=20=EB=B3=B4=EB=84=88=EC=8A=A4?= =?UTF-8?q?=20=EB=B2=88=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 - Lottos 클래스 : 보너스 번호 추가하여 개수 세기 --- src/Main.java | 10 ++++++++-- src/domains/Lotto.java | 9 ++++++++- src/domains/Lottos.java | 43 ++++++++++++++++++++++++++++++++++------- 3 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/Main.java b/src/Main.java index c2eaec0f..e449910c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -9,6 +9,7 @@ import domains.Lottos; import domains.Ranking; import domains.WinningNumbersCounter; +import domains.WinningNumbers; public class Main { private static final int IDX_PURCHASED_AMOUNT = 0; @@ -25,9 +26,14 @@ public static void main(String[] args) { List> totalLottos = lottos.getTotalLottos(tickets); showLottos(totalLottos); - List winningNumbers = inputWinningNumbers(); - List threeOrMore = lottos.numberOfWinningAboveThree(winningNumbers); + List inputValueOfWinningNumbers = inputWinningNumbers(); int bonusNumber = getBonusNumber(); + WinningNumbers winningNumbers = new WinningNumbers(inputValueOfWinningNumbers, bonusNumber); + + + + List threeOrMore = lottos.getNumberOfWinningAboveThree(winningNumbers); + getResultOfLotto(purchaseAmount, threeOrMore); scanClose(); diff --git a/src/domains/Lotto.java b/src/domains/Lotto.java index d7fa304e..f7d11a5b 100644 --- a/src/domains/Lotto.java +++ b/src/domains/Lotto.java @@ -23,7 +23,7 @@ public List numbers() { return this.sixNumbers; } - public int numberOfWinnings(List winningNumbers){ + public int countNumberOfWinnings(List winningNumbers){ int count = 0; for (Integer winningNumber : winningNumbers) { count = getCount(count, winningNumber); @@ -37,4 +37,11 @@ private int getCount(int count, Integer winningNumber) { } return count; } + + public boolean getBonus(int bonusNumber) { + if (sixNumbers.contains(bonusNumber)){ + return true; + } + return false; + } } diff --git a/src/domains/Lottos.java b/src/domains/Lottos.java index c18a58f3..48b120a5 100644 --- a/src/domains/Lottos.java +++ b/src/domains/Lottos.java @@ -1,5 +1,7 @@ package domains; +import domains.WinningNumbers; + import static java.util.stream.Collectors.*; import java.util.ArrayList; @@ -32,12 +34,39 @@ private void purchased(ArrayList pickedNumber){ this.lottos.add(lotto); } - public List numberOfWinningAboveThree(List winningNumbers) { - List resultOfLottos = this.lottos.stream() - .mapToInt(lotto -> lotto.numberOfWinnings(winningNumbers)) - .filter(value -> value >= MINIMUM_NUMBER_OF_WINNING) - .boxed() - .collect(toList()); - return resultOfLottos; + public ArrayList get(){ + return this.lottos; + } + + public List getNumberOfWinningAboveThree(WinningNumbers winningNumbers) { + List winning = winningNumbers.getNumbers(); + int threeBall = 0; + int fourBall = 0; + int fiveBall = 0; + int bonusFiveBall = 0; + int sixBall = 0; + for (Lotto lotto : lottos) { + int winningCount = lotto.countNumberOfWinnings(winning); + if (winningCount >= MINIMUM_NUMBER_OF_WINNING){ + switch (winningCount) { + case 3 : + threeBall++; + break; + case 4 : + if (lotto.getBonus(winningNumbers.getBonusBall())){ + fiveBall++; + break; + }fourBall++; + break; + case 5 : + fiveBall++; + break; + case 6 : + sixBall++; + break; + } + } + } + return null; } } From d69a5eed9ef07a41c959df5ab23ab073f3ac56d0 Mon Sep 17 00:00:00 2001 From: sally-ksh Date: Fri, 25 Feb 2022 01:37:23 +0900 Subject: [PATCH 04/14] =?UTF-8?q?refactor:=20=EB=A1=9C=EB=98=90=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=20=EB=A1=9C=EC=A7=81=20=EB=A6=AC=ED=8C=A9?= =?UTF-8?q?=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Main.class -> LottoPlay - Lottos getNumberOfWinningAboveThree() -> Ranking 에게 전달 - Ranking - this.ranking 반환을 수정하게 위해 String으로의 변경로직을 옮김 --- src/{Main.java => LottoPlay.java} | 23 +++--- src/domains/Lottos.java | 40 ++--------- src/domains/Ranking.java | 98 +++++++++++++++++++++----- src/domains/WinningNumbersCounter.java | 25 ------- src/views/Output.java | 51 +++----------- 5 files changed, 104 insertions(+), 133 deletions(-) rename src/{Main.java => LottoPlay.java} (64%) delete mode 100644 src/domains/WinningNumbersCounter.java diff --git a/src/Main.java b/src/LottoPlay.java similarity index 64% rename from src/Main.java rename to src/LottoPlay.java index e449910c..515dbb61 100644 --- a/src/Main.java +++ b/src/LottoPlay.java @@ -3,15 +3,13 @@ import java.util.ArrayList; import java.util.List; -import java.util.Map; import domains.LottoMachine; import domains.Lottos; import domains.Ranking; -import domains.WinningNumbersCounter; import domains.WinningNumbers; -public class Main { +public class LottoPlay { private static final int IDX_PURCHASED_AMOUNT = 0; private static final int IDX_NUMBER_OF_TICKET = 1; private static LottoMachine lottoMachine = new LottoMachine(); @@ -28,23 +26,18 @@ public static void main(String[] args) { List inputValueOfWinningNumbers = inputWinningNumbers(); int bonusNumber = getBonusNumber(); - WinningNumbers winningNumbers = new WinningNumbers(inputValueOfWinningNumbers, bonusNumber); - - - List threeOrMore = lottos.getNumberOfWinningAboveThree(winningNumbers); + WinningNumbers winningNumbers = new WinningNumbers(inputValueOfWinningNumbers, bonusNumber); + Ranking ranking = lottos.getNumberOfWinningAboveThree(winningNumbers); - getResultOfLotto(purchaseAmount, threeOrMore); + getResultOfLotto(ranking, purchaseAmount); scanClose(); } - private static void getResultOfLotto(int purchaseAmount, List threeOrMore) { - WinningNumbersCounter winnings = new WinningNumbersCounter(threeOrMore); - Ranking ranking = new Ranking(winnings); - - Map ranks = ranking.resultOfRanks(); - double yields = ranking.totalYields(purchaseAmount); - printResultOfLottoAndYield(ranks, yields); + private static void getResultOfLotto(Ranking ranking, int purchaseAmount) { + String winningStatistics = ranking.getWinningStatistics(); + String rateOfReturn = ranking.getRateOfReturn(purchaseAmount); + printResultOfLottoAndYield(winningStatistics, rateOfReturn); } } diff --git a/src/domains/Lottos.java b/src/domains/Lottos.java index 48b120a5..998d1e7d 100644 --- a/src/domains/Lottos.java +++ b/src/domains/Lottos.java @@ -1,9 +1,5 @@ package domains; -import domains.WinningNumbers; - -import static java.util.stream.Collectors.*; - import java.util.ArrayList; import java.util.List; @@ -34,39 +30,17 @@ private void purchased(ArrayList pickedNumber){ this.lottos.add(lotto); } - public ArrayList get(){ - return this.lottos; - } - - public List getNumberOfWinningAboveThree(WinningNumbers winningNumbers) { + public Ranking getNumberOfWinningAboveThree(WinningNumbers winningNumbers) { + Ranking ranking = new Ranking(); List winning = winningNumbers.getNumbers(); - int threeBall = 0; - int fourBall = 0; - int fiveBall = 0; - int bonusFiveBall = 0; - int sixBall = 0; + for (Lotto lotto : lottos) { int winningCount = lotto.countNumberOfWinnings(winning); - if (winningCount >= MINIMUM_NUMBER_OF_WINNING){ - switch (winningCount) { - case 3 : - threeBall++; - break; - case 4 : - if (lotto.getBonus(winningNumbers.getBonusBall())){ - fiveBall++; - break; - }fourBall++; - break; - case 5 : - fiveBall++; - break; - case 6 : - sixBall++; - break; - } + if (winningCount >= MINIMUM_NUMBER_OF_WINNING) { + boolean checkedBonus = lotto.getBonus(winningNumbers.getBonusBall()); + ranking.record(checkedBonus, winningCount); } } - return null; + return ranking; } } diff --git a/src/domains/Ranking.java b/src/domains/Ranking.java index 8a726c9f..8dd87fee 100644 --- a/src/domains/Ranking.java +++ b/src/domains/Ranking.java @@ -1,5 +1,9 @@ package domains; +import static views.Output.*; + +import java.math.RoundingMode; +import java.text.DecimalFormat; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.Map; @@ -7,17 +11,19 @@ public class Ranking { public static final int TO_PERCENT = 100; private Map ranks = new LinkedHashMap<>(); - private WinningNumbersCounter winnings; + // private WinningNumbersCounter winnings; - public Ranking(WinningNumbersCounter winnings) { + public Ranking() { this.ranks = initializeRanks(); - this.winnings = winnings; + // this.winnings = winnings; } public enum Rank { + NONE(0, "0개", Money.of(0)), FOURTH(3, "3개", Money.of(5000)), THIRD(4,"4개", Money.of(50_000)), SECOND(5,"5개", Money.of(1_500_000)), + BONUS_BALL(5, "5개 일치, 보너스 볼 일치", Money.of(30_000_000)), FIRST(6,"6개", Money.of(2_000_000_000)); private int count; @@ -34,10 +40,11 @@ private boolean isSame(int number) { return count == number; } - private Rank of(int number) { + private Rank from(int count) { return Arrays.stream(values()) - .filter(ranks -> ranks.isSame(number)) - .findFirst().get(); + .filter(ranks -> ranks.isSame(count)) + .findAny() + .orElse(Rank.NONE); } public String getText() { @@ -61,32 +68,87 @@ private static Map initializeRanks() { return results; } - public Map resultOfRanks() { - Map counts = this.winnings.getCounts(); - for (Integer key : counts.keySet()) { - Rank rank = findRank(key); - this.ranks.put(rank, counts.get(key)); + public void record(boolean checkedBonus, int winningCount) { + if (winningCount != 4) { + includeRank(winningCount); + return; } - return this.ranks; + toBonus(checkedBonus, winningCount); } - private Rank findRank(Integer key) { - return Arrays.stream(Rank.values()).map(rank -> rank.of(key)).findFirst().get(); + private void toBonus(boolean checkedBonus, int winningCount) { + if (checkedBonus) { + includeBonusRank(); + return; + } + includeRank(winningCount); + } + + private void includeRank(int winningCount) { + Rank rank = findRank(winningCount); + this.ranks.put(rank, this.ranks.getOrDefault(rank, 0)+1); + } + + public void includeBonusRank() { + this.ranks.put(Rank.BONUS_BALL, this.ranks.getOrDefault(Rank.BONUS_BALL, 0)+1); + } + + private Rank findRank(Integer count) { + for (Rank rank : Rank.values()) { + return rank.from(count); + } + return Rank.NONE; } /* 수익률(%) = 손익/투자원금 * 100 = (평가금액-투자원금)/투자원금 * 100 */ public double totalYields(int purchaseAmount) { - Map counts = this.winnings.getCounts(); double totalEarningsByRank = 0; - for (Integer key : counts.keySet()) { - Rank rank = findRank(key); + for (Rank rank : this.ranks.keySet()) { int amount = rank.amount(); - totalEarningsByRank += amount * counts.get(key); + Integer numberOfMachedLotto = this.ranks.get(rank); + totalEarningsByRank += amount * numberOfMachedLotto; } double profit = (totalEarningsByRank - purchaseAmount) / purchaseAmount; double rateOfReturn = profit * TO_PERCENT; return rateOfReturn; } + + public String getWinningStatistics() { + StringBuilder sb = new StringBuilder(); + sb.append(OUTPUT_WINNING_STATISTICS) + .append(System.lineSeparator()) + .append(OUTPUT_WINNING_STATISTICS_LINE) + .append(System.lineSeparator()); + rankLines(sb); + return sb.toString(); + } + + private void rankLines(StringBuilder sb) { + for (Ranking.Rank rank : ranks.keySet()) { + if (rank.NONE.isSame(rank.count)) { + continue; + } + sb.append(rank.getText()) + .append(OUTPUT_IDX_FIRST) + .append(rank.money()) + .append(OUTPUT_IDX_SECOND) + .append(ranks.get(rank)) + .append(OUTPUT_IDX_THIRD) + .append(System.lineSeparator()); + } + } + + public String getRateOfReturn(int purchaseAmount) { + double yields = totalYields(purchaseAmount); + StringBuilder sb = new StringBuilder(); + sb.append(OUTPUT_TOTAL_YIELD_MESSAGE); + DecimalFormat df = new DecimalFormat(PATTERN_ROUND_DOWN); + df.setRoundingMode(RoundingMode.DOWN); + String rateOfReturn = df.format(yields); + sb.append(rateOfReturn) + .append(OUTPUT_TOTAL_YIELD_MESSAGE_SUFFIX); + return sb.toString(); + } } diff --git a/src/domains/WinningNumbersCounter.java b/src/domains/WinningNumbersCounter.java deleted file mode 100644 index 79e9f8cb..00000000 --- a/src/domains/WinningNumbersCounter.java +++ /dev/null @@ -1,25 +0,0 @@ -package domains; - -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -public class WinningNumbersCounter { - private final Map counts; - - public WinningNumbersCounter(List threeOrMore) { - this.counts = getNumberOfEachRanks(threeOrMore); - } - - private static Map getNumberOfEachRanks(List threeOrMore) { - Map countInfo = new LinkedHashMap<>(); - for (Integer numberOfLottos : threeOrMore) { - countInfo.put(numberOfLottos, countInfo.getOrDefault(numberOfLottos, 0) + 1); - } - return countInfo; - } - - public Map getCounts() { - return counts; - } -} diff --git a/src/views/Output.java b/src/views/Output.java index fcbaf975..b250d040 100644 --- a/src/views/Output.java +++ b/src/views/Output.java @@ -9,14 +9,14 @@ import domains.Ranking; public class Output { - private static final String PATTERN_ROUND_DOWN = "0.00"; - private static final String OUTPUT_IDX_FIRST = " 일치 ("; - private static final String OUTPUT_IDX_SECOND = ") - "; - private static final String OUTPUT_IDX_THIRD = "개"; - private static final String OUTPUT_WINNING_STATISTICS = "당첨 통계"; - private static final String OUTPUT_WINNING_STATISTICS_LINE = "--------------------"; - private static final String OUTPUT_TOTAL_YIELD_MESSAGE = "총 수익율은 "; - private static final String OUTPUT_TOTAL_YIELD_MESSAGE_SUFFIX = "%입니다"; + public static final String PATTERN_ROUND_DOWN = "0.00"; + public static final String OUTPUT_IDX_FIRST = " 일치 ("; + public static final String OUTPUT_IDX_SECOND = ") - "; + public static final String OUTPUT_IDX_THIRD = "개"; + public static final String OUTPUT_WINNING_STATISTICS = "당첨 통계"; + public static final String OUTPUT_WINNING_STATISTICS_LINE = "--------------------"; + public static final String OUTPUT_TOTAL_YIELD_MESSAGE = "총 수익율은 "; + public static final String OUTPUT_TOTAL_YIELD_MESSAGE_SUFFIX = "%입니다"; public static Consumer print = (text) -> System.out.print(text); public static Consumer println = (text) -> System.out.println(text); @@ -27,44 +27,11 @@ public static void showLottos(List> purchasedLottos) { prints.accept(lotto); } } - - public static void printResultOfLottoAndYield(Map ranks, double yields) { - String winningStatistics = getWinningStatistics(ranks); - String rateOfReturn = getRateOfReturn(yields); + public static void printResultOfLottoAndYield(String winningStatistics, String rateOfReturn) { println.accept(winningStatistics); println.accept(rateOfReturn); } - private static String getWinningStatistics(Map ranks) { - StringBuilder sb = new StringBuilder(); - sb.append(OUTPUT_WINNING_STATISTICS) - .append(System.lineSeparator()) - .append(OUTPUT_WINNING_STATISTICS_LINE) - .append(System.lineSeparator()); - rankLines(ranks, sb); - return sb.toString(); - } - private static void rankLines(Map ranks, StringBuilder sb) { - for (Ranking.Rank rank : ranks.keySet()) { - sb.append(rank.getText()) - .append(OUTPUT_IDX_FIRST) - .append(rank.money()) - .append(OUTPUT_IDX_SECOND) - .append(ranks.get(rank)) - .append(OUTPUT_IDX_THIRD) - .append(System.lineSeparator()); - } - } - private static String getRateOfReturn(double yields) { - StringBuilder sb = new StringBuilder(); - sb.append(OUTPUT_TOTAL_YIELD_MESSAGE); - DecimalFormat df = new DecimalFormat(PATTERN_ROUND_DOWN); - df.setRoundingMode(RoundingMode.DOWN); - String rateOfReturn = df.format(yields); - sb.append(rateOfReturn) - .append(OUTPUT_TOTAL_YIELD_MESSAGE_SUFFIX); - return sb.toString(); - } } From 141f826b5e1100dbffb3ea27548d91622630afee Mon Sep 17 00:00:00 2001 From: sally-ksh Date: Fri, 25 Feb 2022 03:18:29 +0900 Subject: [PATCH 05/14] =?UTF-8?q?refactor:=20=EB=B3=B4=EB=84=88=EC=8A=A4?= =?UTF-8?q?=EB=B3=BC=20=EC=B6=94=EA=B0=80=20=EC=82=AC=ED=95=AD=20=EC=B6=94?= =?UTF-8?q?=EC=83=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BasicWinningNumbers - 기존의 로또 결과 출력 기능 - AddedWinningNumbers - 기존의 로또 결과에 추가되는 보너스 숫자들 전달 - BonusWinningNumbers 구현체 --- src/LottoPlay.java | 4 +++- src/domains/AddedWinningNumbers.java | 5 +++++ src/domains/BasicWinningNumbers.java | 7 +++++++ src/domains/BonusWinningNumbers.java | 23 +++++++++++++++++++++++ src/domains/Lottos.java | 7 ++++--- src/domains/Ranking.java | 4 +--- src/domains/WinningNumbers.java | 8 +------- 7 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 src/domains/AddedWinningNumbers.java create mode 100644 src/domains/BasicWinningNumbers.java create mode 100644 src/domains/BonusWinningNumbers.java diff --git a/src/LottoPlay.java b/src/LottoPlay.java index 515dbb61..4c44611c 100644 --- a/src/LottoPlay.java +++ b/src/LottoPlay.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import java.util.List; +import domains.BasicWinningNumbers; +import domains.BonusWinningNumbers; import domains.LottoMachine; import domains.Lottos; import domains.Ranking; @@ -27,7 +29,7 @@ public static void main(String[] args) { List inputValueOfWinningNumbers = inputWinningNumbers(); int bonusNumber = getBonusNumber(); - WinningNumbers winningNumbers = new WinningNumbers(inputValueOfWinningNumbers, bonusNumber); + BonusWinningNumbers winningNumbers = new BonusWinningNumbers(inputValueOfWinningNumbers, bonusNumber); Ranking ranking = lottos.getNumberOfWinningAboveThree(winningNumbers); getResultOfLotto(ranking, purchaseAmount); diff --git a/src/domains/AddedWinningNumbers.java b/src/domains/AddedWinningNumbers.java new file mode 100644 index 00000000..d81ebe1c --- /dev/null +++ b/src/domains/AddedWinningNumbers.java @@ -0,0 +1,5 @@ +package domains; + +public interface AddedWinningNumbers extends BasicWinningNumbers{ + int getBonus(); +} diff --git a/src/domains/BasicWinningNumbers.java b/src/domains/BasicWinningNumbers.java new file mode 100644 index 00000000..9720753b --- /dev/null +++ b/src/domains/BasicWinningNumbers.java @@ -0,0 +1,7 @@ +package domains; + +import java.util.List; + +public interface BasicWinningNumbers { + List getNumbers(); +} diff --git a/src/domains/BonusWinningNumbers.java b/src/domains/BonusWinningNumbers.java new file mode 100644 index 00000000..7eb4d5a9 --- /dev/null +++ b/src/domains/BonusWinningNumbers.java @@ -0,0 +1,23 @@ +package domains; + +import java.util.List; + +public class BonusWinningNumbers implements AddedWinningNumbers{ + private final List winningNumbers; + private final int bonusBall; + + public BonusWinningNumbers(List winningNumbers, int bonusBall) { + this.winningNumbers = winningNumbers; + this.bonusBall = bonusBall; + } + + @Override + public int getBonus() { + return this.bonusBall; + } + + @Override + public List getNumbers() { + return this.winningNumbers; + } +} diff --git a/src/domains/Lottos.java b/src/domains/Lottos.java index 998d1e7d..b81ab2df 100644 --- a/src/domains/Lottos.java +++ b/src/domains/Lottos.java @@ -12,11 +12,12 @@ public Lottos() { } public List> getTotalLottos(ArrayList> tickets) { - + // 번호들을 로또에 담다 for (ArrayList ticket : tickets) { this.purchased(ticket); } + // 내가가진 로또 목록을 반환 List> purchasedLottos = new ArrayList<>(); for (Lotto lotto : this.lottos) { List numbers = lotto.numbers(); @@ -30,14 +31,14 @@ private void purchased(ArrayList pickedNumber){ this.lottos.add(lotto); } - public Ranking getNumberOfWinningAboveThree(WinningNumbers winningNumbers) { + public Ranking getNumberOfWinningAboveThree(AddedWinningNumbers winningNumbers) { Ranking ranking = new Ranking(); List winning = winningNumbers.getNumbers(); for (Lotto lotto : lottos) { int winningCount = lotto.countNumberOfWinnings(winning); if (winningCount >= MINIMUM_NUMBER_OF_WINNING) { - boolean checkedBonus = lotto.getBonus(winningNumbers.getBonusBall()); + boolean checkedBonus = lotto.getBonus(winningNumbers.getBonus()); ranking.record(checkedBonus, winningCount); } } diff --git a/src/domains/Ranking.java b/src/domains/Ranking.java index 8dd87fee..50c379e5 100644 --- a/src/domains/Ranking.java +++ b/src/domains/Ranking.java @@ -11,14 +11,12 @@ public class Ranking { public static final int TO_PERCENT = 100; private Map ranks = new LinkedHashMap<>(); - // private WinningNumbersCounter winnings; public Ranking() { this.ranks = initializeRanks(); - // this.winnings = winnings; } - public enum Rank { + private enum Rank { NONE(0, "0개", Money.of(0)), FOURTH(3, "3개", Money.of(5000)), THIRD(4,"4개", Money.of(50_000)), diff --git a/src/domains/WinningNumbers.java b/src/domains/WinningNumbers.java index 9e0c4372..63fa66b7 100644 --- a/src/domains/WinningNumbers.java +++ b/src/domains/WinningNumbers.java @@ -2,20 +2,14 @@ import java.util.List; -public class WinningNumbers { +public class WinningNumbers implements BasicWinningNumbers{ private final List winningNumbers; - private int bonusBall; public WinningNumbers(List winningNumbers, int bonusBall) { this.winningNumbers = winningNumbers; - this.bonusBall = bonusBall; } public List getNumbers() { return this.winningNumbers; } - - public int getBonusBall() { - return bonusBall; - } } From 696896e6fdbc182f32f232a9ea6bc9e7670b9f47 Mon Sep 17 00:00:00 2001 From: sally-ksh Date: Fri, 25 Feb 2022 03:56:50 +0900 Subject: [PATCH 06/14] =?UTF-8?q?refactor:=20LottoPlay=20=EB=B9=84?= =?UTF-8?q?=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C=EC=A7=81=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 - UserLotto - 입력받은 사용자 요청을 통해 로또 생성, 보관, 당첨 결과와의 매칭 기능을 가진다. --- src/LottoPlay.java | 28 +++++++--------------------- src/domains/UserLotto.java | 27 +++++++++++++++++++++++++++ src/views/Input.java | 4 ++-- src/views/Output.java | 6 +++++- src/views/PurchasedLotto.java | 19 +++++++++++++++++++ 5 files changed, 60 insertions(+), 24 deletions(-) create mode 100644 src/domains/UserLotto.java create mode 100644 src/views/PurchasedLotto.java diff --git a/src/LottoPlay.java b/src/LottoPlay.java index 4c44611c..4d5b4ba1 100644 --- a/src/LottoPlay.java +++ b/src/LottoPlay.java @@ -1,45 +1,31 @@ import static views.Input.*; import static views.Output.*; -import java.util.ArrayList; import java.util.List; -import domains.BasicWinningNumbers; -import domains.BonusWinningNumbers; import domains.LottoMachine; import domains.Lottos; import domains.Ranking; -import domains.WinningNumbers; +import domains.UserLotto; +import views.PurchasedLotto; public class LottoPlay { - private static final int IDX_PURCHASED_AMOUNT = 0; - private static final int IDX_NUMBER_OF_TICKET = 1; private static LottoMachine lottoMachine = new LottoMachine(); private static Lottos lottos = new Lottos(); + private static UserLotto userLotto = new UserLotto(lottoMachine, lottos); public static void main(String[] args) { - int[] purchasedLotto = purchaseLotto(); - int purchaseAmount = purchasedLotto[IDX_PURCHASED_AMOUNT]; - int numberOfTicket = purchasedLotto[IDX_NUMBER_OF_TICKET]; + PurchasedLotto purchasedLotto = purchaseLotto(); - ArrayList> tickets = lottoMachine.getTicket(numberOfTicket); - List> totalLottos = lottos.getTotalLottos(tickets); + List> totalLottos = userLotto.getTickets(purchasedLotto); showLottos(totalLottos); List inputValueOfWinningNumbers = inputWinningNumbers(); int bonusNumber = getBonusNumber(); - BonusWinningNumbers winningNumbers = new BonusWinningNumbers(inputValueOfWinningNumbers, bonusNumber); - Ranking ranking = lottos.getNumberOfWinningAboveThree(winningNumbers); - - getResultOfLotto(ranking, purchaseAmount); + Ranking ranking = userLotto.getRankingFromWinningNumbers(inputValueOfWinningNumbers, bonusNumber); + getResultOfLotto(ranking, purchasedLotto.getPurchaseAmount()); scanClose(); } - - private static void getResultOfLotto(Ranking ranking, int purchaseAmount) { - String winningStatistics = ranking.getWinningStatistics(); - String rateOfReturn = ranking.getRateOfReturn(purchaseAmount); - printResultOfLottoAndYield(winningStatistics, rateOfReturn); - } } diff --git a/src/domains/UserLotto.java b/src/domains/UserLotto.java new file mode 100644 index 00000000..f45c7a3c --- /dev/null +++ b/src/domains/UserLotto.java @@ -0,0 +1,27 @@ +package domains; + +import java.util.ArrayList; +import java.util.List; + +import views.PurchasedLotto; + +public class UserLotto { + private final LottoMachine lottoMachine; + private final Lottos lottos; + + public UserLotto(LottoMachine lottoMachine, Lottos lottos) { + this.lottoMachine = lottoMachine; + this.lottos = lottos; + } + + public List> getTickets(PurchasedLotto purchasedLotto) { + ArrayList> tickets = lottoMachine.getTicket(purchasedLotto.getNumberOfTicket()); + return lottos.getTotalLottos(tickets); + } + + public Ranking getRankingFromWinningNumbers(List inputValueOfWinningNumbers, int bonusNumber) { + BonusWinningNumbers winningNumbers = new BonusWinningNumbers(inputValueOfWinningNumbers, bonusNumber); + Ranking ranking = lottos.getNumberOfWinningAboveThree(winningNumbers); + return ranking; + } +} diff --git a/src/views/Input.java b/src/views/Input.java index a613cc2a..c7c2b427 100644 --- a/src/views/Input.java +++ b/src/views/Input.java @@ -36,10 +36,10 @@ private static List toInteger(String textNumbers) { .collect(toList()); } - public static int[] purchaseLotto() { + public static PurchasedLotto purchaseLotto() { int purchaseAmount = getPurchaseAmount(); int numberOfTicket = getTicketAccount(purchaseAmount); - return new int[] {purchaseAmount, numberOfTicket}; + return new PurchasedLotto(purchaseAmount, numberOfTicket); } public static int getPurchaseAmount() { diff --git a/src/views/Output.java b/src/views/Output.java index b250d040..c665b4f3 100644 --- a/src/views/Output.java +++ b/src/views/Output.java @@ -32,6 +32,10 @@ public static void printResultOfLottoAndYield(String winningStatistics, String r println.accept(rateOfReturn); } - + public static void getResultOfLotto(Ranking ranking, int purchaseAmount) { + String winningStatistics = ranking.getWinningStatistics(); + String rateOfReturn = ranking.getRateOfReturn(purchaseAmount); + printResultOfLottoAndYield(winningStatistics, rateOfReturn); + } } diff --git a/src/views/PurchasedLotto.java b/src/views/PurchasedLotto.java new file mode 100644 index 00000000..65c34a5f --- /dev/null +++ b/src/views/PurchasedLotto.java @@ -0,0 +1,19 @@ +package views; + +public class PurchasedLotto { + private final int purchaseAmount; + private final int numberOfTicket; + + public PurchasedLotto(int purchaseAmount, int numberOfTicket) { + this.purchaseAmount = purchaseAmount; + this.numberOfTicket = numberOfTicket; + } + + public int getPurchaseAmount() { + return purchaseAmount; + } + + public int getNumberOfTicket() { + return numberOfTicket; + } +} From ec5169b558f39d7d59bfee474d49aa9bca3fcf4f Mon Sep 17 00:00:00 2001 From: sally-ksh Date: Fri, 25 Feb 2022 03:59:30 +0900 Subject: [PATCH 07/14] =?UTF-8?q?feat:=20=ED=8C=A8=ED=82=A4=EC=A7=80=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 비즈니스 로직을 나누면서 사용자가 가진 티켓 정보와 당첨 정보를 패키지로 분리 --- src/LottoPlay.java | 8 ++++---- src/domains/{ => users}/Lotto.java | 2 +- src/domains/{ => users}/LottoMachine.java | 2 +- src/domains/{ => users}/Lottos.java | 5 ++++- src/domains/{ => users}/Money.java | 2 +- src/domains/{ => users}/UserLotto.java | 4 +++- src/domains/{ => winnings}/AddedWinningNumbers.java | 2 +- src/domains/{ => winnings}/BasicWinningNumbers.java | 2 +- src/domains/{ => winnings}/BonusWinningNumbers.java | 2 +- src/domains/{ => winnings}/Ranking.java | 4 +++- src/domains/{ => winnings}/WinningNumbers.java | 2 +- src/views/Output.java | 5 +---- 12 files changed, 22 insertions(+), 18 deletions(-) rename src/domains/{ => users}/Lotto.java (97%) rename src/domains/{ => users}/LottoMachine.java (98%) rename src/domains/{ => users}/Lottos.java (93%) rename src/domains/{ => users}/Money.java (93%) rename src/domains/{ => users}/UserLotto.java (89%) rename src/domains/{ => winnings}/AddedWinningNumbers.java (76%) rename src/domains/{ => winnings}/BasicWinningNumbers.java (78%) rename src/domains/{ => winnings}/BonusWinningNumbers.java (94%) rename src/domains/{ => winnings}/Ranking.java (98%) rename src/domains/{ => winnings}/WinningNumbers.java (92%) diff --git a/src/LottoPlay.java b/src/LottoPlay.java index 4d5b4ba1..db14176e 100644 --- a/src/LottoPlay.java +++ b/src/LottoPlay.java @@ -3,10 +3,10 @@ import java.util.List; -import domains.LottoMachine; -import domains.Lottos; -import domains.Ranking; -import domains.UserLotto; +import domains.users.LottoMachine; +import domains.users.Lottos; +import domains.winnings.Ranking; +import domains.users.UserLotto; import views.PurchasedLotto; public class LottoPlay { diff --git a/src/domains/Lotto.java b/src/domains/users/Lotto.java similarity index 97% rename from src/domains/Lotto.java rename to src/domains/users/Lotto.java index f7d11a5b..a6224c25 100644 --- a/src/domains/Lotto.java +++ b/src/domains/users/Lotto.java @@ -1,4 +1,4 @@ -package domains; +package domains.users; import java.util.Collections; import java.util.List; diff --git a/src/domains/LottoMachine.java b/src/domains/users/LottoMachine.java similarity index 98% rename from src/domains/LottoMachine.java rename to src/domains/users/LottoMachine.java index 1d457d59..58abe89e 100644 --- a/src/domains/LottoMachine.java +++ b/src/domains/users/LottoMachine.java @@ -1,4 +1,4 @@ -package domains; +package domains.users; import java.util.ArrayList; import java.util.Collections; diff --git a/src/domains/Lottos.java b/src/domains/users/Lottos.java similarity index 93% rename from src/domains/Lottos.java rename to src/domains/users/Lottos.java index b81ab2df..e853d35b 100644 --- a/src/domains/Lottos.java +++ b/src/domains/users/Lottos.java @@ -1,8 +1,11 @@ -package domains; +package domains.users; import java.util.ArrayList; import java.util.List; +import domains.winnings.AddedWinningNumbers; +import domains.winnings.Ranking; + public class Lottos { public static final int MINIMUM_NUMBER_OF_WINNING = 3; private ArrayList lottos = new ArrayList<>(); diff --git a/src/domains/Money.java b/src/domains/users/Money.java similarity index 93% rename from src/domains/Money.java rename to src/domains/users/Money.java index 9bc148a1..94a815e6 100644 --- a/src/domains/Money.java +++ b/src/domains/users/Money.java @@ -1,4 +1,4 @@ -package domains; +package domains.users; public class Money { private static final String WON = "원"; diff --git a/src/domains/UserLotto.java b/src/domains/users/UserLotto.java similarity index 89% rename from src/domains/UserLotto.java rename to src/domains/users/UserLotto.java index f45c7a3c..6155316f 100644 --- a/src/domains/UserLotto.java +++ b/src/domains/users/UserLotto.java @@ -1,8 +1,10 @@ -package domains; +package domains.users; import java.util.ArrayList; import java.util.List; +import domains.winnings.BonusWinningNumbers; +import domains.winnings.Ranking; import views.PurchasedLotto; public class UserLotto { diff --git a/src/domains/AddedWinningNumbers.java b/src/domains/winnings/AddedWinningNumbers.java similarity index 76% rename from src/domains/AddedWinningNumbers.java rename to src/domains/winnings/AddedWinningNumbers.java index d81ebe1c..dd207c4b 100644 --- a/src/domains/AddedWinningNumbers.java +++ b/src/domains/winnings/AddedWinningNumbers.java @@ -1,4 +1,4 @@ -package domains; +package domains.winnings; public interface AddedWinningNumbers extends BasicWinningNumbers{ int getBonus(); diff --git a/src/domains/BasicWinningNumbers.java b/src/domains/winnings/BasicWinningNumbers.java similarity index 78% rename from src/domains/BasicWinningNumbers.java rename to src/domains/winnings/BasicWinningNumbers.java index 9720753b..b751abec 100644 --- a/src/domains/BasicWinningNumbers.java +++ b/src/domains/winnings/BasicWinningNumbers.java @@ -1,4 +1,4 @@ -package domains; +package domains.winnings; import java.util.List; diff --git a/src/domains/BonusWinningNumbers.java b/src/domains/winnings/BonusWinningNumbers.java similarity index 94% rename from src/domains/BonusWinningNumbers.java rename to src/domains/winnings/BonusWinningNumbers.java index 7eb4d5a9..92217dd1 100644 --- a/src/domains/BonusWinningNumbers.java +++ b/src/domains/winnings/BonusWinningNumbers.java @@ -1,4 +1,4 @@ -package domains; +package domains.winnings; import java.util.List; diff --git a/src/domains/Ranking.java b/src/domains/winnings/Ranking.java similarity index 98% rename from src/domains/Ranking.java rename to src/domains/winnings/Ranking.java index 50c379e5..0f36c13c 100644 --- a/src/domains/Ranking.java +++ b/src/domains/winnings/Ranking.java @@ -1,4 +1,4 @@ -package domains; +package domains.winnings; import static views.Output.*; @@ -8,6 +8,8 @@ import java.util.LinkedHashMap; import java.util.Map; +import domains.users.Money; + public class Ranking { public static final int TO_PERCENT = 100; private Map ranks = new LinkedHashMap<>(); diff --git a/src/domains/WinningNumbers.java b/src/domains/winnings/WinningNumbers.java similarity index 92% rename from src/domains/WinningNumbers.java rename to src/domains/winnings/WinningNumbers.java index 63fa66b7..f0b2d249 100644 --- a/src/domains/WinningNumbers.java +++ b/src/domains/winnings/WinningNumbers.java @@ -1,4 +1,4 @@ -package domains; +package domains.winnings; import java.util.List; diff --git a/src/views/Output.java b/src/views/Output.java index c665b4f3..93baad46 100644 --- a/src/views/Output.java +++ b/src/views/Output.java @@ -1,12 +1,9 @@ package views; -import java.math.RoundingMode; -import java.text.DecimalFormat; import java.util.List; -import java.util.Map; import java.util.function.Consumer; -import domains.Ranking; +import domains.winnings.Ranking; public class Output { public static final String PATTERN_ROUND_DOWN = "0.00"; From d7ca355348c358d0c3719fd87b715941bef251a5 Mon Sep 17 00:00:00 2001 From: sally-ksh Date: Fri, 25 Feb 2022 09:08:32 +0900 Subject: [PATCH 08/14] =?UTF-8?q?refactor:=20=EB=B3=B4=EB=84=88=EC=8A=A4?= =?UTF-8?q?=EB=B3=BC=20=EC=83=81=EC=86=8D=EC=9C=BC=EB=A1=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domains/users/Lottos.java | 4 ++-- src/domains/winnings/AddedWinningNumbers.java | 5 ----- .../winnings/AdditionalWinningNumbers.java | 18 ++++++++++++++++++ src/domains/winnings/BasicWinningNumbers.java | 7 ------- src/domains/winnings/BonusWinningNumbers.java | 19 ++++++------------- src/domains/winnings/WinningNumbers.java | 4 ++-- 6 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 src/domains/winnings/AddedWinningNumbers.java create mode 100644 src/domains/winnings/AdditionalWinningNumbers.java delete mode 100644 src/domains/winnings/BasicWinningNumbers.java diff --git a/src/domains/users/Lottos.java b/src/domains/users/Lottos.java index e853d35b..3c07a278 100644 --- a/src/domains/users/Lottos.java +++ b/src/domains/users/Lottos.java @@ -3,7 +3,7 @@ import java.util.ArrayList; import java.util.List; -import domains.winnings.AddedWinningNumbers; +import domains.winnings.BonusWinningNumbers; import domains.winnings.Ranking; public class Lottos { @@ -34,7 +34,7 @@ private void purchased(ArrayList pickedNumber){ this.lottos.add(lotto); } - public Ranking getNumberOfWinningAboveThree(AddedWinningNumbers winningNumbers) { + public Ranking getNumberOfWinningAboveThree(BonusWinningNumbers winningNumbers) { Ranking ranking = new Ranking(); List winning = winningNumbers.getNumbers(); diff --git a/src/domains/winnings/AddedWinningNumbers.java b/src/domains/winnings/AddedWinningNumbers.java deleted file mode 100644 index dd207c4b..00000000 --- a/src/domains/winnings/AddedWinningNumbers.java +++ /dev/null @@ -1,5 +0,0 @@ -package domains.winnings; - -public interface AddedWinningNumbers extends BasicWinningNumbers{ - int getBonus(); -} diff --git a/src/domains/winnings/AdditionalWinningNumbers.java b/src/domains/winnings/AdditionalWinningNumbers.java new file mode 100644 index 00000000..1e7bd8be --- /dev/null +++ b/src/domains/winnings/AdditionalWinningNumbers.java @@ -0,0 +1,18 @@ +package domains.winnings; + +import java.util.List; + +public abstract class AdditionalWinningNumbers implements BasicWinningNumbers{ + private final BasicWinningNumbers winningNumbers; + + protected AdditionalWinningNumbers(BasicWinningNumbers winningNumbers) { + this.winningNumbers = winningNumbers; + } + + @Override + public List getNumbers() { + return winningNumbers.getNumbers(); + } + + protected abstract int getBonus(); +} diff --git a/src/domains/winnings/BasicWinningNumbers.java b/src/domains/winnings/BasicWinningNumbers.java deleted file mode 100644 index b751abec..00000000 --- a/src/domains/winnings/BasicWinningNumbers.java +++ /dev/null @@ -1,7 +0,0 @@ -package domains.winnings; - -import java.util.List; - -public interface BasicWinningNumbers { - List getNumbers(); -} diff --git a/src/domains/winnings/BonusWinningNumbers.java b/src/domains/winnings/BonusWinningNumbers.java index 92217dd1..176bf627 100644 --- a/src/domains/winnings/BonusWinningNumbers.java +++ b/src/domains/winnings/BonusWinningNumbers.java @@ -2,22 +2,15 @@ import java.util.List; -public class BonusWinningNumbers implements AddedWinningNumbers{ - private final List winningNumbers; - private final int bonusBall; +public class BonusWinningNumbers extends WinningNumbers{ + private final int bonus; - public BonusWinningNumbers(List winningNumbers, int bonusBall) { - this.winningNumbers = winningNumbers; - this.bonusBall = bonusBall; + public BonusWinningNumbers(List winningNumbers, int bonus) { + super(winningNumbers); + this.bonus = bonus; } - @Override public int getBonus() { - return this.bonusBall; - } - - @Override - public List getNumbers() { - return this.winningNumbers; + return bonus; } } diff --git a/src/domains/winnings/WinningNumbers.java b/src/domains/winnings/WinningNumbers.java index f0b2d249..2a15e617 100644 --- a/src/domains/winnings/WinningNumbers.java +++ b/src/domains/winnings/WinningNumbers.java @@ -2,10 +2,10 @@ import java.util.List; -public class WinningNumbers implements BasicWinningNumbers{ +public class WinningNumbers { private final List winningNumbers; - public WinningNumbers(List winningNumbers, int bonusBall) { + public WinningNumbers(List winningNumbers) { this.winningNumbers = winningNumbers; } From 72bc92709421cd9a4f1b814c4f2d61e9a87e407e Mon Sep 17 00:00:00 2001 From: sally-ksh Date: Fri, 25 Feb 2022 09:11:44 +0900 Subject: [PATCH 09/14] fix --- .../winnings/AdditionalWinningNumbers.java | 18 ------------------ 1 file changed, 18 deletions(-) delete mode 100644 src/domains/winnings/AdditionalWinningNumbers.java diff --git a/src/domains/winnings/AdditionalWinningNumbers.java b/src/domains/winnings/AdditionalWinningNumbers.java deleted file mode 100644 index 1e7bd8be..00000000 --- a/src/domains/winnings/AdditionalWinningNumbers.java +++ /dev/null @@ -1,18 +0,0 @@ -package domains.winnings; - -import java.util.List; - -public abstract class AdditionalWinningNumbers implements BasicWinningNumbers{ - private final BasicWinningNumbers winningNumbers; - - protected AdditionalWinningNumbers(BasicWinningNumbers winningNumbers) { - this.winningNumbers = winningNumbers; - } - - @Override - public List getNumbers() { - return winningNumbers.getNumbers(); - } - - protected abstract int getBonus(); -} From b9df53d162966fc497eb38350734bde5cf1f9f91 Mon Sep 17 00:00:00 2001 From: rkolx Date: Fri, 25 Feb 2022 09:51:36 +0900 Subject: [PATCH 10/14] =?UTF-8?q?refactor=20:=20=EB=A1=9C=EB=98=90=20?= =?UTF-8?q?=EB=8B=B4=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=97=AD?= =?UTF-8?q?=ED=95=A0=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Lottos 클래스 : getTotalLottos()에서 구매한 개수만큼 로또 번호 담는 getPurchassedLotoos() 추가 분리 --- src/domains/users/Lottos.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/domains/users/Lottos.java b/src/domains/users/Lottos.java index 3c07a278..ad708782 100644 --- a/src/domains/users/Lottos.java +++ b/src/domains/users/Lottos.java @@ -15,12 +15,14 @@ public Lottos() { } public List> getTotalLottos(ArrayList> tickets) { - // 번호들을 로또에 담다 for (ArrayList ticket : tickets) { this.purchased(ticket); } - // 내가가진 로또 목록을 반환 + return getPurchasedLottos(); + } + + private List> getPurchasedLottos() { List> purchasedLottos = new ArrayList<>(); for (Lotto lotto : this.lottos) { List numbers = lotto.numbers(); From 7ac4a2bb44f8c12030e3141482325bb075c1da69 Mon Sep 17 00:00:00 2001 From: rkolx Date: Fri, 25 Feb 2022 09:55:16 +0900 Subject: [PATCH 11/14] =?UTF-8?q?docs=20:=202=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EA=B2=8C=20RADME.md=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index bfeebed5..18e5eebb 100644 --- a/README.md +++ b/README.md @@ -6,23 +6,14 @@ #### 기능요구사항 -- [x] 로또 구입 금액을 입력하면 구입 금액에 해당하는 로또를 발급해야 한다. -- [x] 로또 1장의 가격은 1000원이다. -- [x] 당첨 번호를 입력받아서 수익률을 출력한다. -- [x] 기대 수익은 동작 예시를 참고하자. +- [x] 2등을 위해 추가 번호를 하나 더 추첨한다. 당첨 통계에 2등도 추가해야 한다. #### 프로그래밍 요구사항 -- [x] indent(인덴트, 들여쓰기) depth를 1단계로 구현한다. -- [x] depth의 경우 if문을 사용하는 경우 1단계의 depth가 증가한다. if문 안에 while문을 사용한다면 depth가 2단계가 된다. -- [x] else를 사용하지 마라. -- [x] 메소드의 크기가 최대 10라인을 넘지 않도록 구현한다. -- [x] method가 한 가지 일만 하도록 최대한 작게 만들어라. -- [x] ArrayList를 사용해서 구현한다. - +- [x] enum을 적용해 프로그래밍을 구현한다. #### 출력 결과 - \ No newline at end of file + \ No newline at end of file From ee3deaa0fd603ace2a5bdb7d0e37971b93f7a004 Mon Sep 17 00:00:00 2001 From: rkolx Date: Fri, 25 Feb 2022 10:45:00 +0900 Subject: [PATCH 12/14] =?UTF-8?q?refacfor=20:=20gettotalLottos=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Lottos 클래스 : getTotalLottos() 내 로또 번호 담는 부분 toLottos() 생성하여 분리 --- src/domains/users/Lottos.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/domains/users/Lottos.java b/src/domains/users/Lottos.java index ad708782..2a450f22 100644 --- a/src/domains/users/Lottos.java +++ b/src/domains/users/Lottos.java @@ -15,11 +15,15 @@ public Lottos() { } public List> getTotalLottos(ArrayList> tickets) { + toLottos(tickets); + + return getPurchasedLottos(); + } + + private void toLottos(ArrayList> tickets) { for (ArrayList ticket : tickets) { this.purchased(ticket); } - - return getPurchasedLottos(); } private List> getPurchasedLottos() { From 79bfcec8e1e4fc7b88994b991aeaf4b20ca0544c Mon Sep 17 00:00:00 2001 From: rkolx Date: Fri, 25 Feb 2022 10:46:58 +0900 Subject: [PATCH 13/14] =?UTF-8?q?refactor=20:=20=EB=8F=99=EC=9E=91=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - LottoPlay클래스명에서 LottoApplication클래스명으로 변경 --- src/{LottoPlay.java => LottoApplication.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/{LottoPlay.java => LottoApplication.java} (96%) diff --git a/src/LottoPlay.java b/src/LottoApplication.java similarity index 96% rename from src/LottoPlay.java rename to src/LottoApplication.java index db14176e..bf5075f5 100644 --- a/src/LottoPlay.java +++ b/src/LottoApplication.java @@ -9,7 +9,7 @@ import domains.users.UserLotto; import views.PurchasedLotto; -public class LottoPlay { +public class LottoApplication { private static LottoMachine lottoMachine = new LottoMachine(); private static Lottos lottos = new Lottos(); private static UserLotto userLotto = new UserLotto(lottoMachine, lottos); From 73388b273c3e27e141098bdfbd4806268d5a1461 Mon Sep 17 00:00:00 2001 From: sally-ksh Date: Sat, 26 Feb 2022 14:51:33 +0900 Subject: [PATCH 14/14] =?UTF-8?q?refactor:=20=EB=A6=AC=EB=B7=B0=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Lotto 객체 내부에서 직접 Ranking 체크 - Tickets : 사용자가 구매한 로또 목록들 (WinningNumber : 당첨번호 리스트) - ArrayList -> List 변경 - 패키지명 단수형으로 변경 - for문 stream으로 개선 - boolean 반환하는 함수이용시 불필요한 조건문 제거 --- README.md | 17 +++++- src/LottoApplication.java | 22 ++++---- src/domains/user/Lotto.java | 53 ++++++++++++++++++ src/domains/{users => user}/LottoMachine.java | 26 +++++---- src/domains/user/Lottos.java | 39 +++++++++++++ src/domains/{users => user}/Money.java | 2 +- src/domains/user/Tickets.java | 20 +++++++ src/domains/{users => user}/UserLotto.java | 16 +++--- src/domains/users/Lotto.java | 47 ---------------- src/domains/users/Lottos.java | 56 ------------------- .../BonusWinningNumbers.java | 2 +- .../{winnings => winning}/Ranking.java | 6 +- .../{winnings => winning}/WinningNumbers.java | 2 +- src/{views => view}/Input.java | 4 +- src/{views => view}/Output.java | 8 ++- src/{views => view}/PurchasedLotto.java | 2 +- 16 files changed, 173 insertions(+), 149 deletions(-) create mode 100644 src/domains/user/Lotto.java rename src/domains/{users => user}/LottoMachine.java (50%) create mode 100644 src/domains/user/Lottos.java rename src/domains/{users => user}/Money.java (93%) create mode 100644 src/domains/user/Tickets.java rename src/domains/{users => user}/UserLotto.java (60%) delete mode 100644 src/domains/users/Lotto.java delete mode 100644 src/domains/users/Lottos.java rename src/domains/{winnings => winning}/BonusWinningNumbers.java (91%) rename src/domains/{winnings => winning}/Ranking.java (97%) rename src/domains/{winnings => winning}/WinningNumbers.java (92%) rename src/{views => view}/Input.java (97%) rename src/{views => view}/Output.java (87%) rename src/{views => view}/PurchasedLotto.java (96%) diff --git a/README.md b/README.md index 18e5eebb..d0fc8321 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,18 @@ # java-lotto 마스터즈 멤버스 2022 로또 게임 프로젝트 - +- ✍️ from reviewer + - countNumberOfWinnings() for문 대신 stream으로 개선 + - boolean 함수형 반환 이용한 결과 리턴시 불필요한 조건문을 쓰지 않기 + - 패키지명에 복수형을 잘 쓰지 않습니다. + - Lotto 객체가 직접 Ranking 결과값을 주는 방식으로 개선해야 하지 않을까요? + - 당첨번호 리스트를 보관할 만한 객체를 설계해서 그 객체의 리스트로 전달해주면 더 좋을텐데요? + - java.util.ArrayList 에만 존재하는 메서드나 로직에 애플리케이션이 강결합되어야 할 특별한 이유가 있을까요? + 그렇지 않다면 항상 List 를 사용하는 것이 좋습니다. + - [link](https://stackoverflow.com/questions/9852831/polymorphism-why-use-list-list-new-arraylist-instead-of-arraylist-list-n) + +
+🌱 step2. 자바 로또 2단계 - 보너스 번호 추가 - pair programming (hanse, sally) #### 기능요구사항 @@ -16,4 +27,6 @@ #### 출력 결과 - \ No newline at end of file + + +
diff --git a/src/LottoApplication.java b/src/LottoApplication.java index bf5075f5..bc853fd7 100644 --- a/src/LottoApplication.java +++ b/src/LottoApplication.java @@ -1,13 +1,14 @@ -import static views.Input.*; -import static views.Output.*; +import static view.Input.*; +import static view.Output.*; import java.util.List; -import domains.users.LottoMachine; -import domains.users.Lottos; -import domains.winnings.Ranking; -import domains.users.UserLotto; -import views.PurchasedLotto; +import domains.user.LottoMachine; +import domains.user.Lottos; +import domains.user.Tickets; +import domains.winning.Ranking; +import domains.user.UserLotto; +import view.PurchasedLotto; public class LottoApplication { private static LottoMachine lottoMachine = new LottoMachine(); @@ -17,13 +18,10 @@ public class LottoApplication { public static void main(String[] args) { PurchasedLotto purchasedLotto = purchaseLotto(); - List> totalLottos = userLotto.getTickets(purchasedLotto); + Tickets totalLottos = userLotto.getTickets(purchasedLotto); showLottos(totalLottos); - List inputValueOfWinningNumbers = inputWinningNumbers(); - int bonusNumber = getBonusNumber(); - - Ranking ranking = userLotto.getRankingFromWinningNumbers(inputValueOfWinningNumbers, bonusNumber); + Ranking ranking = userLotto.getRankingFromWinningNumbers(inputWinningNumbers(), getBonusNumber()); getResultOfLotto(ranking, purchasedLotto.getPurchaseAmount()); scanClose(); diff --git a/src/domains/user/Lotto.java b/src/domains/user/Lotto.java new file mode 100644 index 00000000..a645dcb3 --- /dev/null +++ b/src/domains/user/Lotto.java @@ -0,0 +1,53 @@ +package domains.user; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import domains.winning.BonusWinningNumbers; +import domains.winning.Ranking; + +public class Lotto { + public static final int MINIMUM_NUMBER_OF_WINNING = 3; + public static final String ERROR_OF_LOTTO_PARAMS = "error of lotto params"; + private final List sixNumbers; + + public Lotto(List sixNumbers) { + if (Objects.isNull(sixNumbers)) { + throw new IllegalArgumentException(ERROR_OF_LOTTO_PARAMS); + } + if (sixNumbers.size() < 6) { + throw new IllegalArgumentException(ERROR_OF_LOTTO_PARAMS); + } + Collections.sort(sixNumbers); + this.sixNumbers = sixNumbers; + } + + public void recordRanking(BonusWinningNumbers winningNumbers, Ranking ranking){ + boolean checkedBonus = false; + List winning = winningNumbers.getNumbers(); + int winningCount = countWinningNumber(winning); + + if (winningCount >= MINIMUM_NUMBER_OF_WINNING) { + checkedBonus = this.getBonus(winningNumbers.getBonus()); + } + ranking.record(checkedBonus, winningCount); + } + + private int countWinningNumber(List winning) { + return Math.toIntExact(winning.stream() + .filter(winningNumber -> this.sixNumbers.contains(winningNumber)) + .count()); + } + + private int getCount(int count, Integer winningNumber) { + if (sixNumbers.contains(winningNumber)) { + count++; + } + return count; + } + + public boolean getBonus(int bonusNumber) { + return sixNumbers.contains(bonusNumber); + } +} diff --git a/src/domains/users/LottoMachine.java b/src/domains/user/LottoMachine.java similarity index 50% rename from src/domains/users/LottoMachine.java rename to src/domains/user/LottoMachine.java index 58abe89e..f767b302 100644 --- a/src/domains/users/LottoMachine.java +++ b/src/domains/user/LottoMachine.java @@ -1,38 +1,40 @@ -package domains.users; +package domains.user; import java.util.ArrayList; import java.util.Collections; +import java.util.List; public class LottoMachine { private static final int LOTTO_START_NUMBER = 1; private static final int LOTTO_MAX_LIMITED_NUMBER = 46; private static final int RANGE_OF_AUTO_MAX = 6; - public ArrayList> getTicket(int numberOfTicket) { - ArrayList lottoNumbers = getLottoNumbers(); - ArrayList> picked = new ArrayList<>(); + public Tickets getTicket(int numberOfTicket) { + List lottoNumbers = getLottoNumbers(); + Tickets tickets = new Tickets(); + for (int i = 0; i < numberOfTicket; i++) { mixNumber(lottoNumbers); - ArrayList autoPicked = pickAutoSixNumber(lottoNumbers); - picked.add(autoPicked); + List autoPicked = pickAutoSixNumber(lottoNumbers); + tickets.takeIt(autoPicked); } - return picked; + return tickets; } - private ArrayList getLottoNumbers() { - ArrayList lottoNumbers = new ArrayList<>(); + private List getLottoNumbers() { + List lottoNumbers = new ArrayList<>(); for (int i = LOTTO_START_NUMBER; i < LOTTO_MAX_LIMITED_NUMBER; i++) { lottoNumbers.add(i); } return lottoNumbers; } - private void mixNumber(ArrayList lottoNumbers) { + private void mixNumber(List lottoNumbers) { Collections.shuffle(lottoNumbers); } - private ArrayList pickAutoSixNumber(ArrayList lottoNumbers) { - ArrayList autoPickedNumber = new ArrayList<>(); + private List pickAutoSixNumber(List lottoNumbers) { + List autoPickedNumber = new ArrayList<>(); for (int j = 0; j < RANGE_OF_AUTO_MAX; j++) { autoPickedNumber.add(lottoNumbers.get(j)); } diff --git a/src/domains/user/Lottos.java b/src/domains/user/Lottos.java new file mode 100644 index 00000000..9ec7f7e7 --- /dev/null +++ b/src/domains/user/Lottos.java @@ -0,0 +1,39 @@ +package domains.user; + +import java.util.ArrayList; +import java.util.List; + +import domains.winning.BonusWinningNumbers; +import domains.winning.Ranking; + +public class Lottos { + private ArrayList lottos = new ArrayList<>(); + + public Lottos() { + this.lottos = new ArrayList<>(); + } + + public void of(Tickets tickets) { + toLottos(tickets); + } + + private void toLottos(Tickets tickets) { + for (List ticket : tickets.getTotalLottos()) { + this.purchased(ticket); + } + } + + private void purchased(List pickedNumber){ + Lotto lotto = new Lotto(pickedNumber); + this.lottos.add(lotto); + } + + + public Ranking getNumberOfWinningAboveThree(BonusWinningNumbers winningNumbers) { + Ranking ranking = new Ranking(); + for (Lotto lotto : lottos) { + lotto.recordRanking(winningNumbers, ranking); + } + return ranking; + } +} diff --git a/src/domains/users/Money.java b/src/domains/user/Money.java similarity index 93% rename from src/domains/users/Money.java rename to src/domains/user/Money.java index 94a815e6..7f000033 100644 --- a/src/domains/users/Money.java +++ b/src/domains/user/Money.java @@ -1,4 +1,4 @@ -package domains.users; +package domains.user; public class Money { private static final String WON = "원"; diff --git a/src/domains/user/Tickets.java b/src/domains/user/Tickets.java new file mode 100644 index 00000000..a5ad4c96 --- /dev/null +++ b/src/domains/user/Tickets.java @@ -0,0 +1,20 @@ +package domains.user; + +import java.util.ArrayList; +import java.util.List; + +public class Tickets { + private List> totalLottos = new ArrayList<>(); + + public Tickets() { + this.totalLottos = new ArrayList<>(); + } + + public void takeIt(List lottoNumbers) { + this.totalLottos.add(lottoNumbers); + } + + public List> getTotalLottos() { + return totalLottos; + } +} diff --git a/src/domains/users/UserLotto.java b/src/domains/user/UserLotto.java similarity index 60% rename from src/domains/users/UserLotto.java rename to src/domains/user/UserLotto.java index 6155316f..b8275eec 100644 --- a/src/domains/users/UserLotto.java +++ b/src/domains/user/UserLotto.java @@ -1,11 +1,10 @@ -package domains.users; +package domains.user; -import java.util.ArrayList; import java.util.List; -import domains.winnings.BonusWinningNumbers; -import domains.winnings.Ranking; -import views.PurchasedLotto; +import domains.winning.BonusWinningNumbers; +import domains.winning.Ranking; +import view.PurchasedLotto; public class UserLotto { private final LottoMachine lottoMachine; @@ -16,9 +15,10 @@ public UserLotto(LottoMachine lottoMachine, Lottos lottos) { this.lottos = lottos; } - public List> getTickets(PurchasedLotto purchasedLotto) { - ArrayList> tickets = lottoMachine.getTicket(purchasedLotto.getNumberOfTicket()); - return lottos.getTotalLottos(tickets); + public Tickets getTickets(PurchasedLotto purchasedLotto) { + Tickets tickets = lottoMachine.getTicket(purchasedLotto.getNumberOfTicket()); + lottos.of(tickets); + return tickets; } public Ranking getRankingFromWinningNumbers(List inputValueOfWinningNumbers, int bonusNumber) { diff --git a/src/domains/users/Lotto.java b/src/domains/users/Lotto.java deleted file mode 100644 index a6224c25..00000000 --- a/src/domains/users/Lotto.java +++ /dev/null @@ -1,47 +0,0 @@ -package domains.users; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -public class Lotto { - public static final String ERROR_OF_LOTTO_PARAMS = "error of lotto params"; - private final List sixNumbers; - - public Lotto(List sixNumbers) { - if (Objects.isNull(sixNumbers)) { - throw new IllegalArgumentException(ERROR_OF_LOTTO_PARAMS); - } - if (sixNumbers.size() < 6) { - throw new IllegalArgumentException(ERROR_OF_LOTTO_PARAMS); - } - Collections.sort(sixNumbers); - this.sixNumbers = sixNumbers; - } - - public List numbers() { - return this.sixNumbers; - } - - public int countNumberOfWinnings(List winningNumbers){ - int count = 0; - for (Integer winningNumber : winningNumbers) { - count = getCount(count, winningNumber); - } - return count; - } - - private int getCount(int count, Integer winningNumber) { - if (sixNumbers.contains(winningNumber)) { - count++; - } - return count; - } - - public boolean getBonus(int bonusNumber) { - if (sixNumbers.contains(bonusNumber)){ - return true; - } - return false; - } -} diff --git a/src/domains/users/Lottos.java b/src/domains/users/Lottos.java deleted file mode 100644 index 2a450f22..00000000 --- a/src/domains/users/Lottos.java +++ /dev/null @@ -1,56 +0,0 @@ -package domains.users; - -import java.util.ArrayList; -import java.util.List; - -import domains.winnings.BonusWinningNumbers; -import domains.winnings.Ranking; - -public class Lottos { - public static final int MINIMUM_NUMBER_OF_WINNING = 3; - private ArrayList lottos = new ArrayList<>(); - - public Lottos() { - this.lottos = new ArrayList<>(); - } - - public List> getTotalLottos(ArrayList> tickets) { - toLottos(tickets); - - return getPurchasedLottos(); - } - - private void toLottos(ArrayList> tickets) { - for (ArrayList ticket : tickets) { - this.purchased(ticket); - } - } - - private List> getPurchasedLottos() { - List> purchasedLottos = new ArrayList<>(); - for (Lotto lotto : this.lottos) { - List numbers = lotto.numbers(); - purchasedLottos.add(numbers); - } - return purchasedLottos; - } - - private void purchased(ArrayList pickedNumber){ - Lotto lotto = new Lotto(pickedNumber); - this.lottos.add(lotto); - } - - public Ranking getNumberOfWinningAboveThree(BonusWinningNumbers winningNumbers) { - Ranking ranking = new Ranking(); - List winning = winningNumbers.getNumbers(); - - for (Lotto lotto : lottos) { - int winningCount = lotto.countNumberOfWinnings(winning); - if (winningCount >= MINIMUM_NUMBER_OF_WINNING) { - boolean checkedBonus = lotto.getBonus(winningNumbers.getBonus()); - ranking.record(checkedBonus, winningCount); - } - } - return ranking; - } -} diff --git a/src/domains/winnings/BonusWinningNumbers.java b/src/domains/winning/BonusWinningNumbers.java similarity index 91% rename from src/domains/winnings/BonusWinningNumbers.java rename to src/domains/winning/BonusWinningNumbers.java index 176bf627..e8f47cd9 100644 --- a/src/domains/winnings/BonusWinningNumbers.java +++ b/src/domains/winning/BonusWinningNumbers.java @@ -1,4 +1,4 @@ -package domains.winnings; +package domains.winning; import java.util.List; diff --git a/src/domains/winnings/Ranking.java b/src/domains/winning/Ranking.java similarity index 97% rename from src/domains/winnings/Ranking.java rename to src/domains/winning/Ranking.java index 0f36c13c..3562d0a1 100644 --- a/src/domains/winnings/Ranking.java +++ b/src/domains/winning/Ranking.java @@ -1,6 +1,6 @@ -package domains.winnings; +package domains.winning; -import static views.Output.*; +import static view.Output.*; import java.math.RoundingMode; import java.text.DecimalFormat; @@ -8,7 +8,7 @@ import java.util.LinkedHashMap; import java.util.Map; -import domains.users.Money; +import domains.user.Money; public class Ranking { public static final int TO_PERCENT = 100; diff --git a/src/domains/winnings/WinningNumbers.java b/src/domains/winning/WinningNumbers.java similarity index 92% rename from src/domains/winnings/WinningNumbers.java rename to src/domains/winning/WinningNumbers.java index 2a15e617..6b76429e 100644 --- a/src/domains/winnings/WinningNumbers.java +++ b/src/domains/winning/WinningNumbers.java @@ -1,4 +1,4 @@ -package domains.winnings; +package domains.winning; import java.util.List; diff --git a/src/views/Input.java b/src/view/Input.java similarity index 97% rename from src/views/Input.java rename to src/view/Input.java index c7c2b427..0f34b483 100644 --- a/src/views/Input.java +++ b/src/view/Input.java @@ -1,11 +1,11 @@ -package views; +package view; import java.util.Arrays; import java.util.List; import java.util.Scanner; import static java.util.stream.Collectors.toList; -import static views.Output.println; +import static view.Output.println; public class Input { private static final Scanner scanner = new Scanner(System.in); diff --git a/src/views/Output.java b/src/view/Output.java similarity index 87% rename from src/views/Output.java rename to src/view/Output.java index 93baad46..d6f491d7 100644 --- a/src/views/Output.java +++ b/src/view/Output.java @@ -1,9 +1,10 @@ -package views; +package view; import java.util.List; import java.util.function.Consumer; -import domains.winnings.Ranking; +import domains.user.Tickets; +import domains.winning.Ranking; public class Output { public static final String PATTERN_ROUND_DOWN = "0.00"; @@ -19,7 +20,8 @@ public class Output { public static Consumer println = (text) -> System.out.println(text); public static Consumer prints = (obj) -> System.out.println(obj); - public static void showLottos(List> purchasedLottos) { + public static void showLottos(Tickets tickets) { + List> purchasedLottos = tickets.getTotalLottos(); for (List lotto : purchasedLottos) { prints.accept(lotto); } diff --git a/src/views/PurchasedLotto.java b/src/view/PurchasedLotto.java similarity index 96% rename from src/views/PurchasedLotto.java rename to src/view/PurchasedLotto.java index 65c34a5f..30dec928 100644 --- a/src/views/PurchasedLotto.java +++ b/src/view/PurchasedLotto.java @@ -1,4 +1,4 @@ -package views; +package view; public class PurchasedLotto { private final int purchaseAmount;