From 97da692a4d4fa6a671bcf4ddd1b692a0a9be62e6 Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Wed, 23 Feb 2022 10:36:15 +0900 Subject: [PATCH 01/19] =?UTF-8?q?[step2]=20=EC=8B=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/OutputView.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index d378e59e..f9f38b51 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -7,8 +7,6 @@ import java.util.Map; public class OutputView { - private final int SELECTED_NUMBER = 6; - public static void completePurchase(int numberOfTickets, int change, List tickets) { System.out.println(numberOfTickets + "개를 구매했습니다."); System.out.println("거스름돈은 " + change + "원 입니다."); From edf45b65bbdace1a826a3f89a833d202c149a0df Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Wed, 23 Feb 2022 10:50:04 +0900 Subject: [PATCH 02/19] =?UTF-8?q?[step2]=20Enum=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9D=B4=EB=A6=84=20=EB=B3=80=EA=B2=BD(Rank)=20?= =?UTF-8?q?=EB=B0=8F=20switch=EB=AC=B8=20Enum=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=82=B4=EB=B6=80=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enum 클래스의 이름을 Rank로 변경 designateRank 메서드(switch문)를 Enum 클래스 내부로 이동 --- .../domain/{ProfitAmount.java => Rank.java} | 17 +++++++++++++++-- src/main/java/domain/TicketOffice.java | 12 +----------- src/main/java/view/OutputView.java | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) rename src/main/java/domain/{ProfitAmount.java => Rank.java} (50%) diff --git a/src/main/java/domain/ProfitAmount.java b/src/main/java/domain/Rank.java similarity index 50% rename from src/main/java/domain/ProfitAmount.java rename to src/main/java/domain/Rank.java index e0a5d4de..e22447b5 100644 --- a/src/main/java/domain/ProfitAmount.java +++ b/src/main/java/domain/Rank.java @@ -1,6 +1,6 @@ package domain; -public enum ProfitAmount { +public enum Rank { FORTH(3, 5000), THIRD(4, 50000), SECOND(5, 1500000), @@ -9,7 +9,7 @@ public enum ProfitAmount { private final int matchedNumber; private final int prize; - ProfitAmount(int matchedNumber, int prize) { + private Rank(int matchedNumber, int prize) { this.matchedNumber = matchedNumber; this.prize = prize; } @@ -21,4 +21,17 @@ public int getMatchedNumber() { public int getPrize(){ return prize; } + + public static Rank designateRank(int matchedNumber) { + switch (matchedNumber) { + case 3: + return FORTH; + case 4: + return THIRD; + case 5: + return SECOND; + default: + return FIRST; + } + } } diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index 89f71a62..8fe5613a 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -80,17 +80,7 @@ public double calculateProfit() { } private int switchPrize(int matchedNumber) { - switch (matchedNumber) { - case 3: - return ProfitAmount.FORTH.getPrize(); - case 4: - return ProfitAmount.THIRD.getPrize(); - case 5: - return ProfitAmount.SECOND.getPrize(); - default: - return ProfitAmount.FIRST.getPrize(); - } - + return Rank.designateRank(matchedNumber).getPrize(); } private int checkWinningNumber(List ticketInfo) { diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index f9f38b51..ed9c7fec 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -1,7 +1,7 @@ package view; import domain.LottoTicket; -import domain.ProfitAmount; +import domain.Rank; import java.util.List; import java.util.Map; @@ -21,7 +21,7 @@ public static void showWinningResult(Map statistics, double pr System.out.println("__________"); int matchedNumber; int prize; - for (ProfitAmount pa : ProfitAmount.values()) { + for (Rank pa : Rank.values()) { matchedNumber = pa.getMatchedNumber(); prize = pa.getPrize(); System.out.printf("%d개 일치 (%d원) - %d개", matchedNumber, prize, statistics.get(matchedNumber)); From c59c7d5acbb4495d9768bfd9d1bee81790b61048 Mon Sep 17 00:00:00 2001 From: Kyle Choi Date: Wed, 23 Feb 2022 11:20:32 +0900 Subject: [PATCH 03/19] =?UTF-8?q?[step2]=20makeAutoTicket(),=20makeManualT?= =?UTF-8?q?icket=20=EB=B6=84=EB=A6=AC=ED=95=B4=20=EC=88=98=EB=8F=99=20?= =?UTF-8?q?=EC=B6=94=EC=B2=A8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TicketOffice.issueTicket() 메서드 내에서 자동 추첨/수동 추첨 여부를 유저에게 입력받음. 이후 makeAutoTicket(), makeManualTicket()으로 분기하도록 구현. 수동 추첨의 경우 InputView.getManualNumber()를 통해 번호를 입력받은 후 로또 생성. --- .../6.7/executionHistory/executionHistory.bin | Bin 24158 -> 28640 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/6.7/fileHashes/fileHashes.bin | Bin 19797 -> 19897 bytes .gradle/6.7/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .gradle/6.7/javaCompile/javaCompile.lock | Bin 17 -> 17 bytes .gradle/6.7/javaCompile/taskHistory.bin | Bin 18613 -> 18613 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../compileJava/source-classes-mapping.txt | 4 ++-- src/main/java/domain/TicketOffice.java | 20 ++++++++++++++--- src/main/java/view/InputView.java | 21 ++++++++++++++++++ 10 files changed, 40 insertions(+), 5 deletions(-) diff --git a/.gradle/6.7/executionHistory/executionHistory.bin b/.gradle/6.7/executionHistory/executionHistory.bin index cb365fbb52d4777642eab52caf4c931bc451ac52..61a8fac05bf488af2caec43b038f23366fb1d0e5 100644 GIT binary patch delta 919 zcmcb&hw;IE#t9;Vj0|Al$HKrM5Cvo^ZdCjtK3P&iizzN{v#W%pn~^aCgJ2~P7lQEY z(u%U=TyxXP;<7~Jl+@yaqOy|Wyu3>D^hAh3>?asDPY(1F-R$ib!E9(cr8vK|C^^+R zKer&UBr_>9C$prIxfv*4l30|UT7n@y`AT30qv>SZpd7~SlNZKnPJR=_%go5M56YHh zJU@9stQJsIWU_g%u+XJrr`al)1)b$gJOA|*@BG9#W3pkeIO7SJB7Oa!#Jp_1ti-ZJ zW&z!^alsL}TDi=(?;KE_s6Cl+VoH8)VrCvf%>|gg$^0QALb|6OCMz_lH>XYFV0f2b zCB`^&vSWk@E6A{eP=$QzzCZ(@=9_=CmI_&@b5!`>|E`7-$)}86aLGMT_w(_TWu}%h zGPZ)K(=bCOe+v;+i+n!C@tOCT*w3flE@zqcWH;j!kQ#l@yn@n_Fdz$T$r-qoh)^*B z)A<(B?7YDnO=3<2?p`}fbaGv&I3m~t1&++>VRQ>fUVi_xHe;hl&fdvqf$|`y8%)-Z z5M*XVu)!e)5|sdofX1oPuNlvy1=9v`EF0|}{V*dIYpRYd1S>U#vRpKqW3f9T< zV-11ENXmf2Jvk?_xR_bsdjj*)UHg_@`={G7GsZB|Yx2BUBak9)greI}n{-LExzHcNA$Z#$#Z` z=cB}cK7z9uuR%q{C%=jm6ms`mo^&=z*oCo%?MLd7d3h+({EXM3iq%D!1!R-df4*+E{-!!AA{hW_Sy7FYpXbr~uKx3RHo5#okT>@t_ R!I{3mFbf3+$v!5*Isn{3XH)ek_|^B_!Pdyk`lO diff --git a/.gradle/6.7/executionHistory/executionHistory.lock b/.gradle/6.7/executionHistory/executionHistory.lock index d27311c9a93028ebeff204b16613bfcf57744db7..e8cddedd3db67251992c0246d3fb43ba237e16a3 100644 GIT binary patch literal 17 UcmZQRm-OvpPqKR_0|Y1n06!cA`v3p{ literal 17 UcmZQRm-OvpPqKR_0|dwd06!Q6_W%F@ diff --git a/.gradle/6.7/fileHashes/fileHashes.bin b/.gradle/6.7/fileHashes/fileHashes.bin index 5b917a3fb90a7fb6013a953c4802597963703f9b..b62c096365b2df8696ad668b748ca4e8928c4859 100644 GIT binary patch delta 664 zcmcaQi*e^{#tkMCj53o=B@PIj(fDi>xzvZ10StUYC%=_AAt1YR5l3#CVHi}fee+sL zW=6)18x?zXz9G`igiT!-)?Q)iB zPj-WK#GPRSs;mcTd5Njz(y`NQ70iOpa;BaCdWv^`f;vkHs1gVmGk^q|CAy~`CMz_l zH>XYFV0f2bB?h&GAFP3aHyBfgY?AuV`WO0~FCQ3Rb^O*D2-R|D8AJ=$4NNWWp39TY zCJDPR*0B9ZJu)v3V#%F<5FH%hm^uW)<}G5FCO6^3)xHS=M}@ybb%0a?0aNN>Ac^La zWe*hd*WdVj^+C=8x9zMFZ=qWDf^{%3fh^k$LcVx4u7vqC36JqyuscOpcG z$gRyky<(VBP@_@zY+P_eu2wGd?K=llCu&ay>v1=5huZQR)0XcE%u9FeTXyZAZp+LV U!$@F+1CvVJU1f+4Herws0903^0{{R3 delta 528 zcmdlvoAK%_#tkMCj8c`2gFk zw?lP~yL%WiFfi83mzWnaK)`w+rDqHzG=W$VgaulE`91bmQ8ihyzlHEf5_{k1%z- z+r%$+?0$;4?TV-eca~lRhAS|9%a5;v=wM8Jjj6?OYwx}wqeZGN*QDn*{$b&UYPkrt nqzzNYhWH?sKncgC!8I2e>s}u&hIk|f7&Rck?y~u(R}2#XGDU*z diff --git a/.gradle/6.7/fileHashes/fileHashes.lock b/.gradle/6.7/fileHashes/fileHashes.lock index 59d7ba9c882965d6a19a5ef999ccaaec18122162..c19e5a8d86431fa09651a4dbc4213daf2118810c 100644 GIT binary patch literal 17 TcmZSPn$i6;&M+vG0Rr3sE4l-_ literal 17 TcmZSPn$i6;&M+vG0Rk)mE35;p diff --git a/.gradle/6.7/javaCompile/javaCompile.lock b/.gradle/6.7/javaCompile/javaCompile.lock index 61c208d89f3f2b3fa6455954966b6479f3051fdc..aefdd34738bcbc39a055406796330bfa3b973e51 100644 GIT binary patch literal 17 UcmZQRCKeidDsTRJ1_)3A05SjsJOBUy literal 17 UcmZQRCKeidDsTRJ1_)3D05SapIRF3v diff --git a/.gradle/6.7/javaCompile/taskHistory.bin b/.gradle/6.7/javaCompile/taskHistory.bin index 0ee7808c44d81af4af4d28c875d6bf8af74dd117..0acfc2c899218377adc8318385048a2663e44808 100644 GIT binary patch delta 48 zcmdlwk#Xxp#tpt63dsi<^+StOi;DHLD|1qlGx9U_UGkGlb5rw5iuGMm%O=NoxHA?2 E0LE4k{{R30 delta 48 ucmdlwk#Xxp#tpt6{6QP_LyJ?3iuLmnOEMDkCg*y%3&k@4K?8_@f&u`QIt;)7 diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 80442d67bfd3cd8203267408b86dea012eb8dfb0..13ede573ffb65dee33a498d63d75c34ee3e5444d 100644 GIT binary patch literal 17 UcmZSHen$6n7vt>+1_*Ej05;bIegFUf literal 17 UcmZSHen$6n7vt>+1_-bL05;MDc>n+a diff --git a/build/tmp/compileJava/source-classes-mapping.txt b/build/tmp/compileJava/source-classes-mapping.txt index c7e52837..03fcb1a7 100644 --- a/build/tmp/compileJava/source-classes-mapping.txt +++ b/build/tmp/compileJava/source-classes-mapping.txt @@ -1,12 +1,12 @@ Main.java Main +domain/Rank.java + domain.Rank view/OutputView.java view.OutputView domain/LottoTicket.java domain.LottoTicket view/InputView.java view.InputView -domain/ProfitAmount.java - domain.ProfitAmount domain/TicketOffice.java domain.TicketOffice diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index 8fe5613a..c158ba57 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -32,7 +32,7 @@ private void setLottoNumber() { } } - private LottoTicket makeNewLottoTicket() { + private LottoTicket makeAutoTicket() { List ticketNumber = new ArrayList<>(); Collections.shuffle(lottoNumber); for (int i = 0; i < SELECTED_NUMBER; i++) { @@ -42,14 +42,28 @@ private LottoTicket makeNewLottoTicket() { return new LottoTicket(ticketNumber); } + private LottoTicket makeManualTicket() { + List ticketNumber = InputView.getManualNumber(); + return new LottoTicket(ticketNumber); + } + public List issueTickets() { int amount = InputView.getAmount(); int numberOfTickets = amount / PRICE; int change = amount % PRICE; TOTAL_PRICE = PRICE * numberOfTickets; List tickets = new ArrayList<>(); - for (int i = 0; i < numberOfTickets; i++) { - tickets.add(makeNewLottoTicket()); + + boolean isAuto = InputView.askisAuto(); + if (isAuto) { + for (int i = 0; i < numberOfTickets; i++) { + tickets.add(makeAutoTicket()); + } + } + else { + for (int i = 0; i < numberOfTickets; i++) { + tickets.add(makeManualTicket()); + } } OutputView.completePurchase(numberOfTickets, change, tickets); return tickets; diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index a9d8e181..9a2d40e4 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -1,5 +1,8 @@ package view; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; import java.util.Scanner; public class InputView { @@ -18,4 +21,22 @@ public static String[] getWinningNumber() { System.out.println("\n당첨 번호를 입력해 주세요."); return sc.nextLine().split(","); } + + public static boolean askisAuto() { + sc = new Scanner(System.in); + System.out.println("자동을 원하시면 'a', 수동을 원하시면 'm'을 입력해주세요."); + if (Objects.equals(sc.next(), 'a')) + return true; + return false; + } + + public static List getManualNumber() { + List manualNumber = new ArrayList<>(); + sc = new Scanner(System.in); + System.out.println("응모할 번호 6자리를 입력해 주세요."); + String[] userInput = sc.nextLine().split(","); + for (String number : userInput) + manualNumber.add(Integer.parseInt(number)); + return manualNumber; + } } From f438af0871f77f920794a85073cd7c4e222d19e5 Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Wed, 23 Feb 2022 12:31:39 +0900 Subject: [PATCH 04/19] =?UTF-8?q?[step2]=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=B3=BC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rank enum Class에 FIRST ~ FIFTH 까지 총 5단계로 구성 TicketOffice에서 보너스를 처리하는 메서드 : checkBonusNumber(), setBonusNumber() 추가 이에 따른 InputView, OutputView 개선 --- src/main/java/Main.java | 1 + src/main/java/domain/Rank.java | 19 +++++++------ src/main/java/domain/TicketOffice.java | 38 +++++++++++++++++++++----- src/main/java/view/InputView.java | 8 +++++- src/main/java/view/OutputView.java | 25 ++++++++++++----- 5 files changed, 68 insertions(+), 23 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index ac9606f6..77c25b4a 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -8,6 +8,7 @@ public static void main(String[] args) { TicketOffice to = new TicketOffice(); List tickets = to.issueTickets(); to.setWinningNumber(); + to.setBonusNumber(); to.getStatistic(tickets); } } diff --git a/src/main/java/domain/Rank.java b/src/main/java/domain/Rank.java index e22447b5..8409b6b5 100644 --- a/src/main/java/domain/Rank.java +++ b/src/main/java/domain/Rank.java @@ -1,10 +1,11 @@ package domain; public enum Rank { - FORTH(3, 5000), - THIRD(4, 50000), - SECOND(5, 1500000), - FIRST(6, 2000000000); + FIFTH(3, 5_000), + FORTH(4, 50_000), + THIRD(5, 1_500_000), + SECOND(7, 30_000_000), + FIRST(6, 2_000_000_000); private final int matchedNumber; private final int prize; @@ -18,17 +19,19 @@ public int getMatchedNumber() { return matchedNumber; } - public int getPrize(){ + public int getPrize() { return prize; } - public static Rank designateRank(int matchedNumber) { + public static Rank designateRank(int matchedNumber, boolean isBonus) { switch (matchedNumber) { case 3: - return FORTH; + return FIFTH; case 4: - return THIRD; + return FORTH; case 5: + return THIRD; + case 7: return SECOND; default: return FIRST; diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index c158ba57..6911dea0 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -11,6 +11,7 @@ public class TicketOffice { private final int SELECTED_NUMBER = 6; private final int PRICE = 1000; private int TOTAL_PRICE; + private int bonusNumber; private List winningNumbers = new ArrayList<>(); private Map statistics = new HashMap<>(); @@ -19,6 +20,7 @@ public class TicketOffice { statistics.put(4, 0); statistics.put(5, 0); statistics.put(6, 0); + statistics.put(7, 0); } @@ -59,8 +61,7 @@ public List issueTickets() { for (int i = 0; i < numberOfTickets; i++) { tickets.add(makeAutoTicket()); } - } - else { + } else { for (int i = 0; i < numberOfTickets; i++) { tickets.add(makeManualTicket()); } @@ -76,25 +77,41 @@ public void setWinningNumber() { } } + public void setBonusNumber() { // 추후 당첨 번호에 없는 번호만 받도록 예외처리 필요 + bonusNumber = InputView.getBonusNumber(); + } + public void getStatistic(List tickets) { int matchedNumber = 0; + boolean isBonus = false; for (LottoTicket ticket : tickets) { matchedNumber = checkWinningNumber(ticket.getTicketInfo()); + isBonus = checkBonusNumber(ticket.getTicketInfo()); + matchedNumber += temp(matchedNumber, isBonus); statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); } - OutputView.showWinningResult(this.statistics, calculateProfit()); + OutputView.showWinningResult(this.statistics, calculateProfit(isBonus)); } - public double calculateProfit() { + private int temp(int matchedNumber, boolean isBonus){ + if (matchedNumber == 5){ + if(isBonus){ + return 2; + } + } + return 0; + } + + public double calculateProfit(boolean isBonus) { int totalPrize = 0; for (Integer matchedNumber : statistics.keySet()) { - totalPrize += (switchPrize(matchedNumber) * statistics.get(matchedNumber)); + totalPrize += (switchPrize(matchedNumber, isBonus) * statistics.get(matchedNumber)); } return ((double) (totalPrize - TOTAL_PRICE) / TOTAL_PRICE) * 100; } - private int switchPrize(int matchedNumber) { - return Rank.designateRank(matchedNumber).getPrize(); + private int switchPrize(int matchedNumber, boolean isBonus) { + return Rank.designateRank(matchedNumber, isBonus).getPrize(); } private int checkWinningNumber(List ticketInfo) { @@ -105,6 +122,13 @@ private int checkWinningNumber(List ticketInfo) { return count; } + private boolean checkBonusNumber(List ticketInfo) { + if (ticketInfo.contains(bonusNumber)) { + return true; + } + return false; + } + private int isWinningNumber(int number) { if (winningNumbers.contains(number)) { return 1; diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index 9a2d40e4..394b0be8 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -18,7 +18,7 @@ public static int getAmount() { public static String[] getWinningNumber() { sc = new Scanner(System.in); - System.out.println("\n당첨 번호를 입력해 주세요."); + System.out.println("\n지난 주 당첨 번호를 입력해 주세요."); return sc.nextLine().split(","); } @@ -39,4 +39,10 @@ public static List getManualNumber() { manualNumber.add(Integer.parseInt(number)); return manualNumber; } + + public static int getBonusNumber(){ + sc = new Scanner(System.in); + System.out.println("보너스 볼을 입력해 주세요."); + return Integer.parseInt(sc.nextLine()); + } } diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index ed9c7fec..45586cb6 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -17,16 +17,27 @@ public static void completePurchase(int numberOfTickets, int change, List statistics, double profitRate) { - System.out.println("\n당첨 통계"); - System.out.println("__________"); + StringBuilder sb = new StringBuilder(); int matchedNumber; int prize; - for (Rank pa : Rank.values()) { - matchedNumber = pa.getMatchedNumber(); - prize = pa.getPrize(); - System.out.printf("%d개 일치 (%d원) - %d개", matchedNumber, prize, statistics.get(matchedNumber)); - System.out.println(); + sb.append("\n당첨 통계\n"); + sb.append("__________\n"); + for (Rank rank : Rank.values()) { + matchedNumber = rank.getMatchedNumber(); + prize = rank.getPrize(); + if (rank == Rank.SECOND){ + matchedNumber -= 2; + } + sb.append(matchedNumber).append("개 일치"); + + if (rank == Rank.SECOND){ + matchedNumber += 2; + sb.append(", 보너스 볼 일치"); + } + sb.append(" (").append(prize).append(")원 - "); + sb.append(statistics.get(matchedNumber)).append("개\n"); } + System.out.println(sb.toString()); System.out.printf("총 수익률은 %.2f%%입니다.", profitRate); } } From cedce92a66611482c5bfba33290ae464db477bde Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Wed, 23 Feb 2022 15:36:55 +0900 Subject: [PATCH 05/19] =?UTF-8?q?[step2]=20recactoring=20:=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=20=ED=8B=B0=EC=BC=93=EA=B3=BC=20=ED=98=84=EC=9E=AC=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=ED=8B=B0=EC=BC=93=EC=9D=84=20=EB=B9=84?= =?UTF-8?q?=EA=B5=90=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20Tic?= =?UTF-8?q?ketOffice=EC=97=90=EC=84=9C=20LottoTicket=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=98=AE=EA=B9=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TicketOffice -> LottoTicket으로 당첨 티켓 비교 기능 옮김 comparisonWinningTicket, checkNumber 메서드 생성 --- src/main/java/Main.java | 2 +- src/main/java/domain/LottoTicket.java | 26 +++++++++++++++++++++++-- src/main/java/domain/TicketOffice.java | 27 ++++---------------------- src/main/java/view/InputView.java | 12 ++++++------ 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 77c25b4a..178790f0 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -7,7 +7,7 @@ public class Main { public static void main(String[] args) { TicketOffice to = new TicketOffice(); List tickets = to.issueTickets(); - to.setWinningNumber(); + to.setWinningTicket(); to.setBonusNumber(); to.getStatistic(tickets); } diff --git a/src/main/java/domain/LottoTicket.java b/src/main/java/domain/LottoTicket.java index 7e4984d9..d6d3aef2 100644 --- a/src/main/java/domain/LottoTicket.java +++ b/src/main/java/domain/LottoTicket.java @@ -10,10 +10,32 @@ public LottoTicket(List lottoTicket) { this.lottoTicket = lottoTicket; } - - public List getTicketInfo() { return Collections.unmodifiableList(this.lottoTicket); } + public int get(int index){ + if (index < 0 || index >= lottoTicket.size()){ + throw new IndexOutOfBoundsException("인덱스를 초과하였습니다."); + } + return lottoTicket.get(index); + } + + public int comparisonWinningTicket(LottoTicket winningTicket){ + int count = 0; + for(int i=0; i winningNumbers = new ArrayList<>(); + private LottoTicket winningTicket; private Map statistics = new HashMap<>(); - { statistics.put(3, 0); statistics.put(4, 0); @@ -70,11 +69,8 @@ public List issueTickets() { return tickets; } - public void setWinningNumber() { - String[] winning = InputView.getWinningNumber(); - for (int i = 0; i < winning.length; i++) { - winningNumbers.add(Integer.parseInt(winning[i])); - } + public void setWinningTicket() { + winningTicket = new LottoTicket(InputView.getWinningNumber()); } public void setBonusNumber() { // 추후 당첨 번호에 없는 번호만 받도록 예외처리 필요 @@ -85,7 +81,7 @@ public void getStatistic(List tickets) { int matchedNumber = 0; boolean isBonus = false; for (LottoTicket ticket : tickets) { - matchedNumber = checkWinningNumber(ticket.getTicketInfo()); + matchedNumber = ticket.comparisonWinningTicket(winningTicket); isBonus = checkBonusNumber(ticket.getTicketInfo()); matchedNumber += temp(matchedNumber, isBonus); statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); @@ -114,25 +110,10 @@ private int switchPrize(int matchedNumber, boolean isBonus) { return Rank.designateRank(matchedNumber, isBonus).getPrize(); } - private int checkWinningNumber(List ticketInfo) { - int count = 0; - for (Integer number : ticketInfo) { - count += isWinningNumber(number); - } - return count; - } - private boolean checkBonusNumber(List ticketInfo) { if (ticketInfo.contains(bonusNumber)) { return true; } return false; } - - private int isWinningNumber(int number) { - if (winningNumbers.contains(number)) { - return 1; - } - return 0; - } } diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index 394b0be8..6f73d16b 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -1,9 +1,7 @@ package view; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Scanner; +import java.util.*; +import java.util.stream.Collectors; public class InputView { private static Scanner sc; @@ -16,10 +14,12 @@ public static int getAmount() { } - public static String[] getWinningNumber() { + public static List getWinningNumber() { sc = new Scanner(System.in); System.out.println("\n지난 주 당첨 번호를 입력해 주세요."); - return sc.nextLine().split(","); + String[] winningNumbers = sc.nextLine().split(","); + return Arrays.stream(winningNumbers) + .map(Integer::parseInt).collect(Collectors.toList()); } public static boolean askisAuto() { From 0a0f20d3c6b484a2eb9310f5f4f56be8a6a02eb6 Mon Sep 17 00:00:00 2001 From: Kyle Choi Date: Wed, 23 Feb 2022 16:15:04 +0900 Subject: [PATCH 06/19] =?UTF-8?q?[step2]=20=EB=A1=9C=EB=98=90=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99/=EC=88=98=EB=8F=99=20=EC=9E=85=EB=A0=A5=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit InputView.askIsAuto()에서 sc.next() -> sc.nextLine.charAt(0) 으로 바꾸어 char끼리 비교해 커맨드 수행하도록 수정. --- .../6.7/executionHistory/executionHistory.bin | Bin 28640 -> 28640 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/6.7/fileHashes/fileHashes.bin | Bin 19897 -> 19897 bytes .gradle/6.7/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .gradle/6.7/javaCompile/classAnalysis.bin | Bin 19274 -> 19668 bytes .gradle/6.7/javaCompile/javaCompile.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes src/main/java/domain/TicketOffice.java | 2 +- src/main/java/view/InputView.java | 11 +++++++---- 9 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.gradle/6.7/executionHistory/executionHistory.bin b/.gradle/6.7/executionHistory/executionHistory.bin index 61a8fac05bf488af2caec43b038f23366fb1d0e5..cc1827625364432b603734daa8787617bfae3fad 100644 GIT binary patch delta 418 zcmV;T0bTy!-vQv?0kCXdBy@Ccb8u;Gd2eE8VR&SBHFa=dGI4ZmH)Ava0000000Qg) zvy)Lu6_YPu2(ztTCi?01q{SSlkC*5Hn3FM67nA;DOAz=iDIwMSwqcgv zc-#@j>gSVLWMvW_L2L(5H0YDPz2+qpH(oJ~U z(M*#(WtMAapBr($hOOze4u`+LLizT zq7{bili_Q!5?AMUJD;Qd>Pl+8-UDiqxdGRcacM%6KUxKo>}*sJ=Jd_Ca+Gui5x3QY M9QE&Xvrui20t?*7mjD0& delta 418 zcmV;T0bTy!-vQv?0kCXdBz1UpV{JDzd2@DQGh}6RaB_BZb8c>VH)ml00000000+nb zvy)Lu6_YPu2(ztTC)nH0}(?WHHrR=bGh;Xn3FM67nA;DOAsy1UQ<|YDs2PX z+`uJ~E0dF1WMvX9%Hd-mf+vG!k_Z6qZ+aF1nUg_S6qDp+NDw#iI~r7>EX5Q4|B8Tg z8Re5aWt2Z!(h*Y8jLNXbO{XX$++lW=KVlRIip5)f9Nq5zg2knq)xkPyWa_W{h4acM%6-fHs@M@gq*&0-To0elAd zWyGFtli_Q!5*=bE`RFeR>EJWfLH3DJ76I3jacM%6KUxKo>}*sJ1*^7EvzLjV8( diff --git a/.gradle/6.7/executionHistory/executionHistory.lock b/.gradle/6.7/executionHistory/executionHistory.lock index e8cddedd3db67251992c0246d3fb43ba237e16a3..e786d4a8da0ce28ad70fac23172c3bbf332f1fa6 100644 GIT binary patch literal 17 UcmZQRm-OvpPqKR_0|ZzC06#PZ6951J literal 17 UcmZQRm-OvpPqKR_0|Y1n06!cA`v3p{ diff --git a/.gradle/6.7/fileHashes/fileHashes.bin b/.gradle/6.7/fileHashes/fileHashes.bin index b62c096365b2df8696ad668b748ca4e8928c4859..60f6c2f815db03296f65aeabf4112d2d07c80e2b 100644 GIT binary patch delta 587 zcmdlvn{nrC#tq`0^{es)UgfV}zD8ulCEto$7kwBQ80%I240kYq0b>l1(lZ7Unn0`w z!UDf${we(YW#7rTi_>m+?c040tV8F~Z=fU)upR^wXgZ3RCM?_-YFc#Abe59PJLeN% z9hn~OK$Z1C%=R2pi$wpLEel@#pV+eGsLYD~=`Wzp+67bz1kA621ezssjydcBCU2f= zt~xg1;NE9CU>#|@pgQ=PFm;4KFSo9rzxeMfudKcIn6oDBglIW>8e|0n15X){K(i#| zDa+Fbk;&Rt5uDc+iMG9k_{2XMtbu_y4O7R-uXiuKS(MzKclYgtkK0c-LhLxQ1)_r~ z^%DXzu3T8oPIn&O6J;ggeL7k-pR0#x(89)Nf65Ue|lNFlOo6{z7 zFucpJ5`$X857xlI8;q$#Hc9u-F%`XFb4+jdrow@@v6!8#b2K$fBDNWU6bdb7xJvCg{4S)mi3o`vYRI}xHo#jq%D%#tkMCnnFEWd0cNC*|dlO3_QjEL&2;wyO%`B9j$VP(fpu;%g6fJw7G>DjXv2ePnW}M1a71hq!a|RyXEA1-&Nkl~B+S3;fa1yV_p? zDmWcxg29rb*Uv}^XF$b&PrfSA&3JI5;t%nS1`%SL9X&XiCkuG7Xt@9t*nseavdq+S zJ^#{@g3^*OAQPmKsV5~rH!(9$FDNlDdvb!O6e~#7b8?_phKW9qr4GW#YCzH;z}SbR yF*+6^$Y3(L+SAl79mtCZ;VDoxA(_e9sU`ktX_?8XAeAiWPC>R|vW&MbV-5ff_H2d0cNC*|dlO3_Qgr$4XdCJ}TicSyfVEa;{`Eqv1xyAL1Jg MUWjdW^x$L$0936Lf&c&j diff --git a/.gradle/6.7/javaCompile/javaCompile.lock b/.gradle/6.7/javaCompile/javaCompile.lock index aefdd34738bcbc39a055406796330bfa3b973e51..1f14b757f66ef3deeb73bcb728eaf9c743eb77a7 100644 GIT binary patch literal 17 UcmZQRCKeidDsTRJ1_&?*05TH+1_%fT05+1_*Ej05;bIegFUf diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index 00fcb458..c854d625 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -55,7 +55,7 @@ public List issueTickets() { TOTAL_PRICE = PRICE * numberOfTickets; List tickets = new ArrayList<>(); - boolean isAuto = InputView.askisAuto(); + boolean isAuto = InputView.askIsAuto(); if (isAuto) { for (int i = 0; i < numberOfTickets; i++) { tickets.add(makeAutoTicket()); diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index 6f73d16b..241211b0 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -22,12 +22,15 @@ public static List getWinningNumber() { .map(Integer::parseInt).collect(Collectors.toList()); } - public static boolean askisAuto() { + public static boolean askIsAuto() { sc = new Scanner(System.in); System.out.println("자동을 원하시면 'a', 수동을 원하시면 'm'을 입력해주세요."); - if (Objects.equals(sc.next(), 'a')) - return true; - return false; + char input = sc.nextLine().charAt(0); + while (input != 'a' && input != 'm') { + System.out.println("올바르지 않은 명령입니다. 'a'와 'm'으로 입력하세요."); + input = sc.nextLine().charAt(0); + } + return Objects.equals(input, 'a'); } public static List getManualNumber() { From 2be4b31c35d287ddf39891bcb60a4ad51e0c5066 Mon Sep 17 00:00:00 2001 From: Kyle Choi Date: Wed, 23 Feb 2022 16:40:17 +0900 Subject: [PATCH 07/19] =?UTF-8?q?[step2]=20TicketOffice=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9E=90=EB=8F=99/=EC=88=98=EB=8F=99=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 자동, 수동으로 나뉘어 있던 메서드를 TicketOffice.makeLottoTicket()으로 합침. 해당 메서드의 매개변수로 boolean isAuto를 넘겨서 자동/수동에 따른 로직 분기하도록 구현. --- .../6.7/executionHistory/executionHistory.bin | Bin 28640 -> 28640 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/6.7/fileHashes/fileHashes.bin | Bin 19897 -> 19897 bytes .gradle/6.7/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .gradle/6.7/javaCompile/classAnalysis.bin | Bin 19668 -> 19937 bytes .gradle/6.7/javaCompile/javaCompile.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../compileJava/source-classes-mapping.txt | 8 +++---- src/main/java/domain/TicketOffice.java | 21 +++++------------- 9 files changed, 9 insertions(+), 20 deletions(-) diff --git a/.gradle/6.7/executionHistory/executionHistory.bin b/.gradle/6.7/executionHistory/executionHistory.bin index cc1827625364432b603734daa8787617bfae3fad..4f43168f049ff18f667bf4ece5e0e2a60eed2187 100644 GIT binary patch delta 162 zcmV;T0A2s!-vQv?0kCXdBxQASYH4C-d1-cNGHPOPHh5-dcxp5?Xku{y0000000JWb zvy)Lu6_YPu2(ztT5e5=F5nwC-A%nc`>-dt7B`rMxnUg_S6tm=H#{m%hz-`1enq@*G z(gQE5sw^s#%~cn((q{Yu5&pNaipr$$qd(lYa<)A0nE{hYDPz2+OV literal 17 UcmZQRm-OvpPqKR_0|ZzC06#PZ6951J diff --git a/.gradle/6.7/fileHashes/fileHashes.bin b/.gradle/6.7/fileHashes/fileHashes.bin index 60f6c2f815db03296f65aeabf4112d2d07c80e2b..d2cdc189d3cd7a1793c830553ce3444b754fb069 100644 GIT binary patch delta 92 zcmdlvn{nrC#trv96|4mlwErtM?|Jw7$E1E$U0VhQ#(LG}SwRe7z&myFf6s2_=JzF& nd%b)V{%zmbb!y3n#rAi$7j3h7KNF((gC<0=Na*IDUI&-}_PQlT delta 92 zcmdlvn{nrC#trv9733Uq*aJ-7Jl9-xY{J34&vY0V80%HjcI{#S1HPuo|2?~z(~fMJ o-0S6|@FUT;prO?HA$#22xRcmKIcyak8(Z zf`Dm+lJN}JE6*T;K368EN_H_Zac)%nA->T-Ky0(4$7GhtfnJ7_GkkI;r}z{A0PjK| A^Z)<= delta 43 zcmV+`0M!5Cn*r3B0kAX}0TPon7^su=7+1_($405<#tqW}N^ literal 17 UcmZSHen$6n7vt>+1_%fT05 ticketNumber = new ArrayList<>(); Collections.shuffle(lottoNumber); for (int i = 0; i < SELECTED_NUMBER; i++) { @@ -43,28 +45,15 @@ private LottoTicket makeAutoTicket() { return new LottoTicket(ticketNumber); } - private LottoTicket makeManualTicket() { - List ticketNumber = InputView.getManualNumber(); - return new LottoTicket(ticketNumber); - } - public List issueTickets() { int amount = InputView.getAmount(); int numberOfTickets = amount / PRICE; int change = amount % PRICE; TOTAL_PRICE = PRICE * numberOfTickets; List tickets = new ArrayList<>(); - boolean isAuto = InputView.askIsAuto(); - if (isAuto) { - for (int i = 0; i < numberOfTickets; i++) { - tickets.add(makeAutoTicket()); - } - } else { - for (int i = 0; i < numberOfTickets; i++) { - tickets.add(makeManualTicket()); - } - } + for (int i = 0; i < numberOfTickets; i++) + tickets.add(makeLottoTicket(isAuto)); OutputView.completePurchase(numberOfTickets, change, tickets); return tickets; } From 00a3220bbbbe961725cf45b2d6fc466af43c7a1a Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Wed, 23 Feb 2022 16:49:05 +0900 Subject: [PATCH 08/19] =?UTF-8?q?[step2]=20TicketOffice.checkBonusNumber()?= =?UTF-8?q?=20->=20LottoTicket.checkBonusNumber()=EB=A1=9C=20=EC=98=AE?= =?UTF-8?q?=EA=B9=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 티켓 내부 정보에 대한 검사(포함하는지 안하는지)에 대한 책임은 LottoTicket이 지도록 지정 --- src/main/java/domain/LottoTicket.java | 4 ++++ src/main/java/domain/TicketOffice.java | 9 +-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/java/domain/LottoTicket.java b/src/main/java/domain/LottoTicket.java index d6d3aef2..3aebcb49 100644 --- a/src/main/java/domain/LottoTicket.java +++ b/src/main/java/domain/LottoTicket.java @@ -36,6 +36,10 @@ private int checkNumber(LottoTicket winningTicket, int index){ return 0; } + public boolean checkBonusNumber(int bonusNumber){ + return lottoTicket.contains(bonusNumber); + } + } diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index 039d3805..dcff7337 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -71,7 +71,7 @@ public void getStatistic(List tickets) { boolean isBonus = false; for (LottoTicket ticket : tickets) { matchedNumber = ticket.comparisonWinningTicket(winningTicket); - isBonus = checkBonusNumber(ticket.getTicketInfo()); + isBonus = ticket.checkBonusNumber(bonusNumber); matchedNumber += temp(matchedNumber, isBonus); statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); } @@ -98,11 +98,4 @@ public double calculateProfit(boolean isBonus) { private int switchPrize(int matchedNumber, boolean isBonus) { return Rank.designateRank(matchedNumber, isBonus).getPrize(); } - - private boolean checkBonusNumber(List ticketInfo) { - if (ticketInfo.contains(bonusNumber)) { - return true; - } - return false; - } } From 7162394e9eab4c9ebaaf89fb15895349ca26ef0e Mon Sep 17 00:00:00 2001 From: Kyle Choi Date: Thu, 24 Feb 2022 14:34:19 +0900 Subject: [PATCH 09/19] =?UTF-8?q?[step2]=20TicketOffice=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EC=9D=98=20=EB=8B=B9=EC=B2=A8=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20LottoCompany=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 TicketOffice의 역할이 과도하게 크다고 판단하여 당첨 번호 설정 및 당첨금 확인(통계) 기능을 담당하는 LottoCompany 클래스를 만들어 분리. getStatistic()과 연결되는 calculateProfit에서 사용하는 TOTAL_PRICE 값은 TicketOffice에서 로또를 구매할 때 설정되기 때문에 구조 수정 필요. 클래스 분리로 인해 Main 로직도 수정 필요. --- src/main/java/domain/LottoCompany.java | 60 ++++++++++++++++++++++++++ src/main/java/domain/TicketOffice.java | 51 ---------------------- 2 files changed, 60 insertions(+), 51 deletions(-) create mode 100644 src/main/java/domain/LottoCompany.java diff --git a/src/main/java/domain/LottoCompany.java b/src/main/java/domain/LottoCompany.java new file mode 100644 index 00000000..1bc5efd1 --- /dev/null +++ b/src/main/java/domain/LottoCompany.java @@ -0,0 +1,60 @@ +package domain; + +import view.InputView; +import view.OutputView; + +import java.util.*; + +public class LottoCompany { + private LottoTicket winningTicket; + private int bonusNumber; + private Map statistics = new HashMap<>(); + { + statistics.put(3, 0); + statistics.put(4, 0); + statistics.put(5, 0); + statistics.put(6, 0); + statistics.put(7, 0); + } + + public void setWinningTicket() { + this.winningTicket = new LottoTicket(InputView.getWinningNumber()); + } + + public void setBonusNumber() { // 추후 당첨 번호에 없는 번호만 받도록 예외처리 필요 + this.bonusNumber = InputView.getBonusNumber(); + } + + public void getStatistic(List tickets) { + int matchedNumber = 0; + boolean isBonus = false; + for (LottoTicket ticket : tickets) { + matchedNumber = ticket.comparisonWinningTicket(this.winningTicket); + isBonus = ticket.checkBonusNumber(this.bonusNumber); + matchedNumber += addMatchedForBonus(matchedNumber, isBonus); + statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); + } + OutputView.showWinningResult(this.statistics, calculateProfit(isBonus)); + } + + private int addMatchedForBonus(int matchedNumber, boolean isBonus){ + if (matchedNumber == 5){ + if(isBonus){ + return 2; + } + } + return 0; + } + + public double calculateProfit(boolean isBonus) { + int totalPrize = 0; + for (Integer matchedNumber : this.statistics.keySet()) { + totalPrize += (switchPrize(matchedNumber, isBonus) * statistics.get(matchedNumber)); + } + return ((double) (totalPrize - TOTAL_PRICE) / TOTAL_PRICE) * 100; + } + + private int switchPrize(int matchedNumber, boolean isBonus) { + return Rank.designateRank(matchedNumber, isBonus).getPrize(); + } +} diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index dcff7337..a7232104 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -11,16 +11,6 @@ public class TicketOffice { private final int SELECTED_NUMBER = 6; private final int PRICE = 1000; private int TOTAL_PRICE; - private int bonusNumber; - private LottoTicket winningTicket; - private Map statistics = new HashMap<>(); - { - statistics.put(3, 0); - statistics.put(4, 0); - statistics.put(5, 0); - statistics.put(6, 0); - statistics.put(7, 0); - } public TicketOffice() { @@ -57,45 +47,4 @@ public List issueTickets() { OutputView.completePurchase(numberOfTickets, change, tickets); return tickets; } - - public void setWinningTicket() { - winningTicket = new LottoTicket(InputView.getWinningNumber()); - } - - public void setBonusNumber() { // 추후 당첨 번호에 없는 번호만 받도록 예외처리 필요 - bonusNumber = InputView.getBonusNumber(); - } - - public void getStatistic(List tickets) { - int matchedNumber = 0; - boolean isBonus = false; - for (LottoTicket ticket : tickets) { - matchedNumber = ticket.comparisonWinningTicket(winningTicket); - isBonus = ticket.checkBonusNumber(bonusNumber); - matchedNumber += temp(matchedNumber, isBonus); - statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); - } - OutputView.showWinningResult(this.statistics, calculateProfit(isBonus)); - } - - private int temp(int matchedNumber, boolean isBonus){ - if (matchedNumber == 5){ - if(isBonus){ - return 2; - } - } - return 0; - } - - public double calculateProfit(boolean isBonus) { - int totalPrize = 0; - for (Integer matchedNumber : statistics.keySet()) { - totalPrize += (switchPrize(matchedNumber, isBonus) * statistics.get(matchedNumber)); - } - return ((double) (totalPrize - TOTAL_PRICE) / TOTAL_PRICE) * 100; - } - - private int switchPrize(int matchedNumber, boolean isBonus) { - return Rank.designateRank(matchedNumber, isBonus).getPrize(); - } } From ff671c5f32d533cca09f69be0ba44c6a70d0f63d Mon Sep 17 00:00:00 2001 From: Kyle Choi Date: Thu, 24 Feb 2022 15:42:25 +0900 Subject: [PATCH 10/19] =?UTF-8?q?[step2]=20User=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User 클래스를 추가하여 purchaseTicketsFrom() 메서드를 통해 TicketOffice에서 티켓을 구매하도록 구현. 이후 LottoCompany와의 상호작용을 통해 결과(통계) 출력 기능 수정 필요. --- src/main/java/domain/TicketOffice.java | 12 +++++------- src/main/java/domain/User.java | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 src/main/java/domain/User.java diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index a7232104..58fc4498 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -10,7 +10,6 @@ public class TicketOffice { private final int SELECTABLE_NUMBER = 45; private final int SELECTED_NUMBER = 6; private final int PRICE = 1000; - private int TOTAL_PRICE; public TicketOffice() { @@ -35,16 +34,15 @@ private LottoTicket makeLottoTicket(boolean isAuto) { return new LottoTicket(ticketNumber); } - public List issueTickets() { - int amount = InputView.getAmount(); - int numberOfTickets = amount / PRICE; - int change = amount % PRICE; - TOTAL_PRICE = PRICE * numberOfTickets; + public List issueTickets(int numberOfTickets) { List tickets = new ArrayList<>(); boolean isAuto = InputView.askIsAuto(); for (int i = 0; i < numberOfTickets; i++) tickets.add(makeLottoTicket(isAuto)); - OutputView.completePurchase(numberOfTickets, change, tickets); return tickets; } + + public int getPrice() { + return this.PRICE; + } } diff --git a/src/main/java/domain/User.java b/src/main/java/domain/User.java new file mode 100644 index 00000000..1dcb1fd9 --- /dev/null +++ b/src/main/java/domain/User.java @@ -0,0 +1,24 @@ +package domain; + +import view.InputView; +import view.OutputView; + +import java.util.List; + +public class User { + int purchasedAmount; + int change; + List tickets; + + public void purchaseTicketsFrom(TicketOffice to) { + int amount = InputView.getAmount(); + int pricePerTicket = to.getPrice(); + int numberOfTickets = amount / pricePerTicket; + + this.tickets = to.issueTickets(numberOfTickets); + this.purchasedAmount = pricePerTicket * numberOfTickets; + this.change = amount - purchasedAmount; + + OutputView.completePurchase(numberOfTickets, change, tickets); + } +} From 2778b9a850db1a0429ee6ff2a29f1648f86f2f6f Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Thu, 24 Feb 2022 16:17:31 +0900 Subject: [PATCH 11/19] =?UTF-8?q?[step2]=20LottoCompany=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=EB=A5=BC=20=ED=86=B5=ED=95=B4=20User?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=8B=B9=EC=B2=A8=20=EC=A0=95=EB=B3=B4?= =?UTF-8?q?=EB=A5=BC=20=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User.checkMyTicketsFrom(lottoCompany) 추가 Enum Rank 필요없는 매개변수 isBonus 제거 LottoCompany.check(tickets)를 통해 User의 당첨 정보를 조회 --- src/main/java/Main.java | 12 +++++---- src/main/java/domain/LottoCompany.java | 35 +++++++++++++++----------- src/main/java/domain/Rank.java | 2 +- src/main/java/domain/User.java | 17 ++++++++----- 4 files changed, 40 insertions(+), 26 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 178790f0..10887b0d 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,14 +1,16 @@ +import domain.LottoCompany; import domain.LottoTicket; import domain.TicketOffice; +import domain.User; import java.util.List; public class Main { public static void main(String[] args) { - TicketOffice to = new TicketOffice(); - List tickets = to.issueTickets(); - to.setWinningTicket(); - to.setBonusNumber(); - to.getStatistic(tickets); + TicketOffice ticketOffice = new TicketOffice(); + LottoCompany lottoCompany = new LottoCompany(); + User user = new User(); + user.purchaseTicketsFrom(ticketOffice); + user.checkMyTicketsFrom(lottoCompany); } } diff --git a/src/main/java/domain/LottoCompany.java b/src/main/java/domain/LottoCompany.java index 1bc5efd1..fde12c0c 100644 --- a/src/main/java/domain/LottoCompany.java +++ b/src/main/java/domain/LottoCompany.java @@ -8,7 +8,9 @@ public class LottoCompany { private LottoTicket winningTicket; private int bonusNumber; - private Map statistics = new HashMap<>(); + private int totalPrice; + private final int PRICE = 1000; + private final Map statistics = new HashMap<>(); { statistics.put(3, 0); statistics.put(4, 0); @@ -17,6 +19,13 @@ public class LottoCompany { statistics.put(7, 0); } + public void check(List tickets){ + setWinningTicket(); + setBonusNumber(); + this.totalPrice = tickets.size() * PRICE; + getStatistic(tickets); + } + public void setWinningTicket() { this.winningTicket = new LottoTicket(InputView.getWinningNumber()); } @@ -26,35 +35,33 @@ public void setBonusNumber() { // 추후 당첨 번호에 없는 번호만 받 } public void getStatistic(List tickets) { - int matchedNumber = 0; - boolean isBonus = false; + int matchedNumber; + boolean isBonus; for (LottoTicket ticket : tickets) { matchedNumber = ticket.comparisonWinningTicket(this.winningTicket); isBonus = ticket.checkBonusNumber(this.bonusNumber); matchedNumber += addMatchedForBonus(matchedNumber, isBonus); statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); } - OutputView.showWinningResult(this.statistics, calculateProfit(isBonus)); + OutputView.showWinningResult(this.statistics, calculateProfit()); } private int addMatchedForBonus(int matchedNumber, boolean isBonus){ - if (matchedNumber == 5){ - if(isBonus){ - return 2; - } + if (matchedNumber == 5 && isBonus){ + return 2; } return 0; } - public double calculateProfit(boolean isBonus) { + public double calculateProfit() { int totalPrize = 0; - for (Integer matchedNumber : this.statistics.keySet()) { - totalPrize += (switchPrize(matchedNumber, isBonus) * statistics.get(matchedNumber)); + for (int matchedNumber : this.statistics.keySet()) { + totalPrize += (switchPrize(matchedNumber) * statistics.get(matchedNumber)); } - return ((double) (totalPrize - TOTAL_PRICE) / TOTAL_PRICE) * 100; + return ((double) (totalPrize - totalPrice) / totalPrice) * 100; } - private int switchPrize(int matchedNumber, boolean isBonus) { - return Rank.designateRank(matchedNumber, isBonus).getPrize(); + private int switchPrize(int matchedNumber) { + return Rank.designateRank(matchedNumber).getPrize(); } } diff --git a/src/main/java/domain/Rank.java b/src/main/java/domain/Rank.java index 8409b6b5..9922324e 100644 --- a/src/main/java/domain/Rank.java +++ b/src/main/java/domain/Rank.java @@ -23,7 +23,7 @@ public int getPrize() { return prize; } - public static Rank designateRank(int matchedNumber, boolean isBonus) { + public static Rank designateRank(int matchedNumber) { switch (matchedNumber) { case 3: return FIFTH; diff --git a/src/main/java/domain/User.java b/src/main/java/domain/User.java index 1dcb1fd9..0f585dfd 100644 --- a/src/main/java/domain/User.java +++ b/src/main/java/domain/User.java @@ -6,19 +6,24 @@ import java.util.List; public class User { - int purchasedAmount; - int change; - List tickets; + private int purchasedAmount; + private int change; + private int amount; + private List tickets; public void purchaseTicketsFrom(TicketOffice to) { - int amount = InputView.getAmount(); + this.amount = InputView.getAmount(); int pricePerTicket = to.getPrice(); - int numberOfTickets = amount / pricePerTicket; + int numberOfTickets = this.amount / pricePerTicket; this.tickets = to.issueTickets(numberOfTickets); this.purchasedAmount = pricePerTicket * numberOfTickets; - this.change = amount - purchasedAmount; + this.change = this.amount - purchasedAmount; OutputView.completePurchase(numberOfTickets, change, tickets); } + + public void checkMyTicketsFrom(LottoCompany lottoCompany){ + lottoCompany.check(this.tickets); + } } From a89c370ec0d8fbbaa9627e2023bc709eacd4bdd8 Mon Sep 17 00:00:00 2001 From: Kyle Choi Date: Thu, 24 Feb 2022 16:39:29 +0900 Subject: [PATCH 12/19] =?UTF-8?q?[step2]=20Rank=20=EC=88=98=EC=A0=95,=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=20=ED=86=B5=EA=B3=84=20Map=20key=20Integer?= =?UTF-8?q?=20->=20Rank=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enum 클래스인 Rank를 수정해 boolean 값인 isBonus를 가지고 있게 하고, LottoCompany의 멤버변수 statisctic의 key를 Rank로 변경. --- .../6.7/executionHistory/executionHistory.bin | Bin 28640 -> 38259 bytes .../executionHistory/executionHistory.lock | Bin 17 -> 17 bytes .gradle/6.7/fileHashes/fileHashes.bin | Bin 19897 -> 20097 bytes .gradle/6.7/fileHashes/fileHashes.lock | Bin 17 -> 17 bytes .gradle/6.7/javaCompile/classAnalysis.bin | Bin 19937 -> 20049 bytes .gradle/6.7/javaCompile/javaCompile.lock | Bin 17 -> 17 bytes .../buildOutputCleanup.lock | Bin 17 -> 17 bytes .../compileJava/source-classes-mapping.txt | 12 +++++--- src/main/java/domain/LottoCompany.java | 26 ++++++++---------- src/main/java/domain/Rank.java | 20 ++++++++------ src/main/java/view/OutputView.java | 2 +- 11 files changed, 32 insertions(+), 28 deletions(-) diff --git a/.gradle/6.7/executionHistory/executionHistory.bin b/.gradle/6.7/executionHistory/executionHistory.bin index 4f43168f049ff18f667bf4ece5e0e2a60eed2187..fd56b24eeb800282e781f89d6fab019e091cda4e 100644 GIT binary patch delta 1333 zcmaEGpYii5rU@dN%nV@Q$HKrM5Cvh!#W64lHbL0=4}k22K(^&Z!#m=WB_*_&8XGse zO3V&7G6u@b0OAQCJUgk#v?w>(C_URWEjcZ{Dk~?eG&{Y*C@I+lVi3<_hRu@$y+kML zCva?D8yCvL#Jzp;!dT78>ymjVTP1rkUYJ~%sRiUoSvu$E79{3X>SZOCB{B=#cy-Tc zS&q#UlQ?~H? zXG}H>7N7ht*<0Z8U#8Z3>-INCx*o9MDD-_hIWi?xXo}04#|sWdbJuu>7tA%S91`mjZfMa=vJsU zhW7jVs{;1?iPn)fEZ&=@ve_n8kda^UomJE^!SC|sLO+hny)&C!7b-rvIL$)CHgN89 zrT*Wu{**9Hsuo)x&pb6HwYVfRFR>&uKhGtzC^fkxzo?P}WRv4&k#ti=A&$%wtUE4l znzQGY(_+Re%-0xi0p&a=TLkk=-jES3(51woyP2c&AwRDu%Sqnt+b1jJ8%-9-lAQcM zgNyMDP^r`8x-1@{jMXWwm(Bcc@hy8&`zdDeZ-~_9ds$l?_9WU~TqMtdrm5ga}l<_Sm$pbLG#2!W(U!ETXn<4#@3hG6yCA!MVWHBK#7FAA<1g zijw5)tZZ|WY=V#d~}OXM*q)_ghuSCg&Uk&CX1xsm|T$QrHYb;l5-M^iHzc~ivnt=+;4|NQ?9vNUG$)(kHh zaE^jHEz2|8WM)_7_dmrp_PW=L&%qKfH$o9rlJVouGLuey&uUqIwrhjn^v#!n$+(Y+ HN%$QA1gjNi delta 45 wcmeyois`|9#t9;Vj0|Al$HKrM5Cvo^ZgjjMJ~2RMvZRC-Q(W9;SBcr-00-g=e*gdg diff --git a/.gradle/6.7/executionHistory/executionHistory.lock b/.gradle/6.7/executionHistory/executionHistory.lock index f4db99bcbf2531cbc0968490f0a7df15d2ac9a83..87e5b36ec78430bb5d21ece61277d1bbb5d06ebf 100644 GIT binary patch literal 17 UcmZQRm-OvpPqKR_0|fX006#|sCIA2c literal 17 UcmZQRm-OvpPqKR_0|dAN06#zl9{>OV diff --git a/.gradle/6.7/fileHashes/fileHashes.bin b/.gradle/6.7/fileHashes/fileHashes.bin index d2cdc189d3cd7a1793c830553ce3444b754fb069..5e74c2e6ae4518873b4f42a7be8d386d8d4b5032 100644 GIT binary patch delta 799 zcmdlvo3U{&;|3E6M}^i0aUJgF|E@BCfrsONDCn}h%i?*X^D{);cPC7|yS==t;~_d&LH48R*cP=Q_v%dr8%2tWI&gZ02{1Z`qUDPce&sLzQzvEMR(! zX#q#(3DzAKH_h2|%V{y=73OPD9Ty-v*g+JUlhnJPeosu^6fu2kxA4M0|ACPQ^u#K| zWk8i6Cvh-u{^^y)RR8!dQ|rBT`7WFi9tGZv?GDRJm-=IDIL z&nwDul6U)ds8b$7bg+ReKyym-6K&32QnUTTtzVhF?Oe_W(V=x7sInf2*%xDKndj^m zmlEhXbB)FhrKy74EnqFPl+}SMfq+>FNT69VKTFN$p_Olbj=8@H55K9a}761Vs kC{d&7$nwlKQJC2k`Tb9^jlJ&m;&V_ftzaDtEMR8=0N)zglmGw# delta 515 zcmZpi%eZqk;|3E6L7CPEaUJgF|E@BCfrsPfQV9pf$!8^ROx`Qi#Kg35qv8+ojRqN_ zlN~*-1+B^#c$L3?`5KWGmwYR3UG!mKV60d5Gu#2u%oqct^^AdpCJ-xvu)wdGe+oZ; z*>^JT;(F`h8z>0`tOqA&db-q0^sm{n;MM<$ElZBdtmvQq0&46oh$80K zKpM?hYrzEV|BB6f-o5@Ysb5vs7ObOrRuDu7?^H}3;m^yh=P&;I$}4N{J?5-QJHa~A zj-CdpWCdcLvdM;CYAmXm{>hW0y`<_-e!Y9?&7$P?yt{8FeB6Gz5n{pn5{Ly%&oC`; za8Y4irBI?>dg-#Y*?y<*5DSh;Lv*lpVCwj{ePh?DB_9^s-`QTY&F1|~h#en5fd_Ju zNa*IDURg|GKXf$}um0YaIPHGL9l>L-o`aR?Jo*JOm^lGRqlM1fvxPoq{%Z&L8J?Z9 UYl_zbs8jv|RRRH96_C&a0NzKR4*&oF diff --git a/.gradle/6.7/fileHashes/fileHashes.lock b/.gradle/6.7/fileHashes/fileHashes.lock index 1faa18c353ab750e57236cbd81049d31aa53c302..90510e184702a9fba8aa57c25677813907fb7238 100644 GIT binary patch literal 17 UcmZSPn$i6;&M+vG0RpB204xdw3jhEB literal 17 TcmZSPn$i6;&M+vG0RqYaE9wL5 diff --git a/.gradle/6.7/javaCompile/classAnalysis.bin b/.gradle/6.7/javaCompile/classAnalysis.bin index 7b29013e5d2e40edad99b200c30a135b51a8729b..ac05204db4c3213bca8d43d0cb300807399b3c2e 100644 GIT binary patch delta 56 zcmaDjoAKft#tkMCjAD~bB@zVoaNdn!wtTae0StT}Ztj&>&B&;@QSpcPMuQ)sn;ktC Kuuf+5EdT&2%@cP3 delta 35 rcmcaOhw+1_&qx05=N+vH$=8 literal 17 UcmZSHen$6n7vt>+1_($405<#tqW}N^ diff --git a/build/tmp/compileJava/source-classes-mapping.txt b/build/tmp/compileJava/source-classes-mapping.txt index d196bc3f..d799060b 100644 --- a/build/tmp/compileJava/source-classes-mapping.txt +++ b/build/tmp/compileJava/source-classes-mapping.txt @@ -1,12 +1,16 @@ -view/InputView.java - view.InputView +Main.java + Main domain/Rank.java domain.Rank view/OutputView.java view.OutputView domain/LottoTicket.java domain.LottoTicket -Main.java - Main +view/InputView.java + view.InputView +domain/User.java + domain.User domain/TicketOffice.java domain.TicketOffice +domain/LottoCompany.java + domain.LottoCompany diff --git a/src/main/java/domain/LottoCompany.java b/src/main/java/domain/LottoCompany.java index fde12c0c..010d6f66 100644 --- a/src/main/java/domain/LottoCompany.java +++ b/src/main/java/domain/LottoCompany.java @@ -10,13 +10,13 @@ public class LottoCompany { private int bonusNumber; private int totalPrice; private final int PRICE = 1000; - private final Map statistics = new HashMap<>(); - { - statistics.put(3, 0); - statistics.put(4, 0); - statistics.put(5, 0); - statistics.put(6, 0); - statistics.put(7, 0); + private final Map statistics = new HashMap<>(); + + + public void setInitialStatistic() { + for (Rank rank : Rank.values()) { + statistics.put(rank, 0); + } } public void check(List tickets){ @@ -35,13 +35,14 @@ public void setBonusNumber() { // 추후 당첨 번호에 없는 번호만 받 } public void getStatistic(List tickets) { + setInitialStatistic(); int matchedNumber; boolean isBonus; for (LottoTicket ticket : tickets) { matchedNumber = ticket.comparisonWinningTicket(this.winningTicket); isBonus = ticket.checkBonusNumber(this.bonusNumber); - matchedNumber += addMatchedForBonus(matchedNumber, isBonus); - statistics.computeIfPresent(matchedNumber, (k, v) -> v + 1); + Rank currentRank = Rank.designateRank(matchedNumber, isBonus); + statistics.computeIfPresent(currentRank, (k, v) -> v + 1); } OutputView.showWinningResult(this.statistics, calculateProfit()); } @@ -55,13 +56,10 @@ private int addMatchedForBonus(int matchedNumber, boolean isBonus){ public double calculateProfit() { int totalPrize = 0; - for (int matchedNumber : this.statistics.keySet()) { - totalPrize += (switchPrize(matchedNumber) * statistics.get(matchedNumber)); + for (Rank rank : this.statistics.keySet()) { + totalPrize += rank.getPrize() * statistics.get(rank); } return ((double) (totalPrize - totalPrice) / totalPrice) * 100; } - private int switchPrize(int matchedNumber) { - return Rank.designateRank(matchedNumber).getPrize(); - } } diff --git a/src/main/java/domain/Rank.java b/src/main/java/domain/Rank.java index 9922324e..66faa2c5 100644 --- a/src/main/java/domain/Rank.java +++ b/src/main/java/domain/Rank.java @@ -1,18 +1,20 @@ package domain; public enum Rank { - FIFTH(3, 5_000), - FORTH(4, 50_000), - THIRD(5, 1_500_000), - SECOND(7, 30_000_000), - FIRST(6, 2_000_000_000); + FIFTH(3, 5_000, false), + FORTH(4, 50_000, false), + THIRD(5, 1_500_000, false), + SECOND(5, 30_000_000, true), + FIRST(6, 2_000_000_000, false); private final int matchedNumber; private final int prize; + private final boolean isBonus; - private Rank(int matchedNumber, int prize) { + private Rank(int matchedNumber, int prize, boolean isBonus) { this.matchedNumber = matchedNumber; this.prize = prize; + this.isBonus = isBonus; } public int getMatchedNumber() { @@ -23,16 +25,16 @@ public int getPrize() { return prize; } - public static Rank designateRank(int matchedNumber) { + public static Rank designateRank(int matchedNumber, boolean isBonus) { switch (matchedNumber) { case 3: return FIFTH; case 4: return FORTH; case 5: + if (isBonus) + return SECOND; return THIRD; - case 7: - return SECOND; default: return FIRST; } diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index 45586cb6..a59775f7 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -16,7 +16,7 @@ public static void completePurchase(int numberOfTickets, int change, List statistics, double profitRate) { + public static void showWinningResult(Map statistics, double profitRate) { StringBuilder sb = new StringBuilder(); int matchedNumber; int prize; From 6cc42b8c4e1b77062fe2085de9baa2a1036913ea Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Thu, 24 Feb 2022 16:56:31 +0900 Subject: [PATCH 13/19] =?UTF-8?q?[step2]=20OutputView.showWinningResult=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LottoCompany의 statistics 자료형 구조 변경( -> )로 인한 showWinningReulst 메서드 변경 개선 --- src/main/java/domain/LottoCompany.java | 7 ------- src/main/java/domain/Rank.java | 4 ++++ src/main/java/view/OutputView.java | 29 +++++++++++--------------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/main/java/domain/LottoCompany.java b/src/main/java/domain/LottoCompany.java index 010d6f66..e18a542c 100644 --- a/src/main/java/domain/LottoCompany.java +++ b/src/main/java/domain/LottoCompany.java @@ -47,13 +47,6 @@ public void getStatistic(List tickets) { OutputView.showWinningResult(this.statistics, calculateProfit()); } - private int addMatchedForBonus(int matchedNumber, boolean isBonus){ - if (matchedNumber == 5 && isBonus){ - return 2; - } - return 0; - } - public double calculateProfit() { int totalPrize = 0; for (Rank rank : this.statistics.keySet()) { diff --git a/src/main/java/domain/Rank.java b/src/main/java/domain/Rank.java index 66faa2c5..567b6553 100644 --- a/src/main/java/domain/Rank.java +++ b/src/main/java/domain/Rank.java @@ -25,6 +25,10 @@ public int getPrize() { return prize; } + public boolean getIsBonus(){ + return isBonus; + } + public static Rank designateRank(int matchedNumber, boolean isBonus) { switch (matchedNumber) { case 3: diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index a59775f7..aeee9110 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -18,26 +18,21 @@ public static void completePurchase(int numberOfTickets, int change, List statistics, double profitRate) { StringBuilder sb = new StringBuilder(); - int matchedNumber; - int prize; - sb.append("\n당첨 통계\n"); - sb.append("__________\n"); + sb.append("\n당첨 통계\n").append("__________\n"); for (Rank rank : Rank.values()) { - matchedNumber = rank.getMatchedNumber(); - prize = rank.getPrize(); - if (rank == Rank.SECOND){ - matchedNumber -= 2; - } - sb.append(matchedNumber).append("개 일치"); - - if (rank == Rank.SECOND){ - matchedNumber += 2; - sb.append(", 보너스 볼 일치"); - } - sb.append(" (").append(prize).append(")원 - "); - sb.append(statistics.get(matchedNumber)).append("개\n"); + sb.append(rank.getMatchedNumber()).append("개 일치"); + sb.append(checkBonusBall(rank)); + sb.append(" (").append(rank.getPrize()).append(")원 - "); + sb.append(statistics.get(rank)).append("개\n"); } System.out.println(sb.toString()); System.out.printf("총 수익률은 %.2f%%입니다.", profitRate); } + + private static String checkBonusBall(Rank rank){ + if (rank == Rank.SECOND) { + return ", 보너스 볼 일치"; + } + return ""; + } } From 8cc12adc04250312b3302478d1e5181191965dd0 Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Thu, 24 Feb 2022 20:07:47 +0900 Subject: [PATCH 14/19] =?UTF-8?q?[step2]=20Rank=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20:=20checkBon?= =?UTF-8?q?us=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A5=BC=20=ED=86=B5=ED=95=B4?= =?UTF-8?q?=20indent=EB=A5=BC=20=EC=A4=84=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rank.checkBonus() 메서드 구현 --- README.md | 18 ++++++++++++++---- src/main/java/domain/Rank.java | 28 +++++++++++++--------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index fcd16a85..93a43f87 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,21 @@ - 기대 수익은 동작 예시를 참고하자. ### 프로그래밍 요구사항 -- [ ] indent(인덴트, 들여쓰기) depth를 1단계로 구현한다. -- [ ] depth의 경우 if문을 사용하는 경우 1단계의 depth가 증가한다. if문 안에 while문을 사용한다면 depth가 2단계가 된다. +- [x] indent(인덴트, 들여쓰기) depth를 1단계로 구현한다. +- [x] depth의 경우 if문을 사용하는 경우 1단계의 depth가 증가한다. if문 안에 while문을 사용한다면 depth가 2단계가 된다. - [x] else를 사용하지 마라. - [x] 메소드의 크기가 최대 10라인을 넘지 않도록 구현한다. -- [ ] method가 한 가지 일만 하도록 최대한 작게 만들어라. +- [x] method가 한 가지 일만 하도록 최대한 작게 만들어라. - [x] ArrayList를 사용해서 구현한다. ---- \ No newline at end of file +--- + +## 로또 2단계 - 보너스 번호 추가 +### 기능요구사항 +- [x] 2등을 위해 추가 번호를 하나 더 추첨한다. 당첨 통계에 2등도 추가해야 한다. + +### 프로그래밍 요구사항 +- [x] enum을 적용해 프로그래밍을 구현한다. + +### 힌트 +- [x] Lotto 클래스를 사용자가 구매한 Lotto와 기계에 의해 추첨한 Lotto로 구분해서 생성한다. \ No newline at end of file diff --git a/src/main/java/domain/Rank.java b/src/main/java/domain/Rank.java index 567b6553..4c1986a9 100644 --- a/src/main/java/domain/Rank.java +++ b/src/main/java/domain/Rank.java @@ -1,20 +1,18 @@ package domain; public enum Rank { - FIFTH(3, 5_000, false), - FORTH(4, 50_000, false), - THIRD(5, 1_500_000, false), - SECOND(5, 30_000_000, true), - FIRST(6, 2_000_000_000, false); + FIFTH(3, 5_000), + FORTH(4, 50_000), + THIRD(5, 1_500_000), + SECOND(5, 30_000_000), + FIRST(6, 2_000_000_000); private final int matchedNumber; private final int prize; - private final boolean isBonus; - private Rank(int matchedNumber, int prize, boolean isBonus) { + private Rank(int matchedNumber, int prize) { this.matchedNumber = matchedNumber; this.prize = prize; - this.isBonus = isBonus; } public int getMatchedNumber() { @@ -25,10 +23,6 @@ public int getPrize() { return prize; } - public boolean getIsBonus(){ - return isBonus; - } - public static Rank designateRank(int matchedNumber, boolean isBonus) { switch (matchedNumber) { case 3: @@ -36,11 +30,15 @@ public static Rank designateRank(int matchedNumber, boolean isBonus) { case 4: return FORTH; case 5: - if (isBonus) - return SECOND; - return THIRD; + return checkBonus(isBonus); default: return FIRST; } } + + private static Rank checkBonus(boolean isBonus){ + if(isBonus) + return SECOND; + return THIRD; + } } From 68655b3cd752d9059dab7d9104c518d5fd90c301 Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Thu, 24 Feb 2022 20:37:29 +0900 Subject: [PATCH 15/19] =?UTF-8?q?[step2]=20Rank=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=EC=97=90=20FAIL=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FAIL 추가를 통해 꽝인 경우를 제대로 분기하게 하였습니다. --- src/main/java/domain/LottoCompany.java | 3 ++- src/main/java/domain/Rank.java | 5 ++++- src/main/java/view/OutputView.java | 13 +++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/domain/LottoCompany.java b/src/main/java/domain/LottoCompany.java index e18a542c..b4e88e5a 100644 --- a/src/main/java/domain/LottoCompany.java +++ b/src/main/java/domain/LottoCompany.java @@ -38,10 +38,11 @@ public void getStatistic(List tickets) { setInitialStatistic(); int matchedNumber; boolean isBonus; + Rank currentRank; for (LottoTicket ticket : tickets) { matchedNumber = ticket.comparisonWinningTicket(this.winningTicket); isBonus = ticket.checkBonusNumber(this.bonusNumber); - Rank currentRank = Rank.designateRank(matchedNumber, isBonus); + currentRank = Rank.designateRank(matchedNumber, isBonus); statistics.computeIfPresent(currentRank, (k, v) -> v + 1); } OutputView.showWinningResult(this.statistics, calculateProfit()); diff --git a/src/main/java/domain/Rank.java b/src/main/java/domain/Rank.java index 4c1986a9..75c9fd1a 100644 --- a/src/main/java/domain/Rank.java +++ b/src/main/java/domain/Rank.java @@ -1,6 +1,7 @@ package domain; public enum Rank { + FAIL(0, 0), FIFTH(3, 5_000), FORTH(4, 50_000), THIRD(5, 1_500_000), @@ -31,8 +32,10 @@ public static Rank designateRank(int matchedNumber, boolean isBonus) { return FORTH; case 5: return checkBonus(isBonus); - default: + case 6: return FIRST; + default: + return FAIL; } } diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index aeee9110..dea3a007 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -18,17 +18,26 @@ public static void completePurchase(int numberOfTickets, int change, List statistics, double profitRate) { StringBuilder sb = new StringBuilder(); - sb.append("\n당첨 통계\n").append("__________\n"); + int matchedNumber; + System.out.println("\n당첨 통계\n__________"); for (Rank rank : Rank.values()) { - sb.append(rank.getMatchedNumber()).append("개 일치"); + matchedNumber = rank.getMatchedNumber(); + sb.append(matchedNumber).append("개 일치"); sb.append(checkBonusBall(rank)); sb.append(" (").append(rank.getPrize()).append(")원 - "); sb.append(statistics.get(rank)).append("개\n"); + initString(matchedNumber, sb); } System.out.println(sb.toString()); System.out.printf("총 수익률은 %.2f%%입니다.", profitRate); } + private static void initString(int matchedNumber, StringBuilder sb){ + if(matchedNumber==0){ + sb.setLength(0); + } + } + private static String checkBonusBall(Rank rank){ if (rank == Rank.SECOND) { return ", 보너스 볼 일치"; From c98801042f1acfe6a8e050df281e274dedbcecd9 Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Fri, 25 Feb 2022 11:30:18 +0900 Subject: [PATCH 16/19] =?UTF-8?q?[step3]=20=EC=88=98=EB=8F=99=20=ED=8B=B0?= =?UTF-8?q?=EC=BC=93=20=EA=B0=9C=EC=88=98=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=ED=9B=84=20=ED=95=9C=EA=BA=BC=EB=B2=88=EC=97=90=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit InputView.getNumberOfManualTicket() : 수동으로 구매할 로또수만 입력받도록 수정 TicketOffice.makeTicket() : makeManualTickets, makeAutoTicket으로 분리하여 따로따로 티켓을 생성하도록 수정 --- src/main/java/domain/TicketOffice.java | 24 +++++++++++++++++------- src/main/java/view/InputView.java | 12 +++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index 58fc4498..39ad0acc 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -1,7 +1,6 @@ package domain; import view.InputView; -import view.OutputView; import java.util.*; @@ -22,9 +21,16 @@ private void setLottoNumber() { } } - private LottoTicket makeLottoTicket(boolean isAuto) { - if (!isAuto) - return new LottoTicket(InputView.getManualNumber()); + private List makeManualTickets(int numberOfManualTicket) { + List manualLottoTickets = new ArrayList<>(); + System.out.println("수동으로 구매할 번호를 입력해 주세요. (응모할 번호 6자리)"); + for (int i = 0; i < numberOfManualTicket; i++) { + manualLottoTickets.add(new LottoTicket(InputView.getManualNumber())); + } + return manualLottoTickets; + } + + private LottoTicket makeAutoTicket() { List ticketNumber = new ArrayList<>(); Collections.shuffle(lottoNumber); for (int i = 0; i < SELECTED_NUMBER; i++) { @@ -36,9 +42,13 @@ private LottoTicket makeLottoTicket(boolean isAuto) { public List issueTickets(int numberOfTickets) { List tickets = new ArrayList<>(); - boolean isAuto = InputView.askIsAuto(); - for (int i = 0; i < numberOfTickets; i++) - tickets.add(makeLottoTicket(isAuto)); + int numberOfManualTicket = InputView.getNumberOfManualTicket(); + if (numberOfManualTicket>0) { + tickets.addAll(makeManualTickets(numberOfManualTicket)); + } + for (int j = 0; j < numberOfTickets - numberOfManualTicket; j++){ + tickets.add(makeAutoTicket()); + } return tickets; } diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java index 241211b0..474f956a 100644 --- a/src/main/java/view/InputView.java +++ b/src/main/java/view/InputView.java @@ -22,21 +22,15 @@ public static List getWinningNumber() { .map(Integer::parseInt).collect(Collectors.toList()); } - public static boolean askIsAuto() { + public static int getNumberOfManualTicket() { sc = new Scanner(System.in); - System.out.println("자동을 원하시면 'a', 수동을 원하시면 'm'을 입력해주세요."); - char input = sc.nextLine().charAt(0); - while (input != 'a' && input != 'm') { - System.out.println("올바르지 않은 명령입니다. 'a'와 'm'으로 입력하세요."); - input = sc.nextLine().charAt(0); - } - return Objects.equals(input, 'a'); + System.out.println("수동으로 구매할 로또 수를 입력해 주세요."); + return Integer.parseInt(sc.nextLine()); } public static List getManualNumber() { List manualNumber = new ArrayList<>(); sc = new Scanner(System.in); - System.out.println("응모할 번호 6자리를 입력해 주세요."); String[] userInput = sc.nextLine().split(","); for (String number : userInput) manualNumber.add(Integer.parseInt(number)); From 643fd1f7211735b5374396843f2311f2677773d8 Mon Sep 17 00:00:00 2001 From: Kyle Choi Date: Fri, 25 Feb 2022 14:22:44 +0900 Subject: [PATCH 17/19] =?UTF-8?q?[step3]=20AutoTicketOffice,=20ManualTicke?= =?UTF-8?q?tOffice=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 기존 TicketOffice 클래스를 상속하는 AutoTicketOffice, ManualTicketOffice 클래스 추가. 각 클래스가 issueTickets()를 오버라이딩하는 형태로 구현. --- src/main/java/domain/AutoTicketOffice.java | 38 ++++++++++++++++ src/main/java/domain/LottoTicket.java | 1 - src/main/java/domain/ManualTicketOffice.java | 27 ++++++++++++ src/main/java/domain/TicketOffice.java | 46 +------------------- 4 files changed, 67 insertions(+), 45 deletions(-) create mode 100644 src/main/java/domain/AutoTicketOffice.java create mode 100644 src/main/java/domain/ManualTicketOffice.java diff --git a/src/main/java/domain/AutoTicketOffice.java b/src/main/java/domain/AutoTicketOffice.java new file mode 100644 index 00000000..050041bb --- /dev/null +++ b/src/main/java/domain/AutoTicketOffice.java @@ -0,0 +1,38 @@ +package domain; + +import java.util.*; + +public class AutoTicketOffice extends TicketOffice { + private final List lottoNumber = new ArrayList<>(); + private final int SELECTABLE_NUMBER = 45; + private final int SELECTED_NUMBER = 6; + + public AutoTicketOffice() { + setLottoNumber(); + } + + @Override + public List issueTickets(int numberOfTickets) { + List tickets = new ArrayList<>(); + for (int j = 0; j < numberOfTickets; j++){ + tickets.add(makeAutoTicket()); + } + return tickets; + } + + private LottoTicket makeAutoTicket() { + List ticketNumber = new ArrayList<>(); + Collections.shuffle(lottoNumber); + for (int i = 0; i < SELECTED_NUMBER; i++) { + ticketNumber.add(lottoNumber.get(i)); + } + Collections.sort(ticketNumber); + return new LottoTicket(ticketNumber); + } + + private void setLottoNumber() { + for (int i = 1; i <= SELECTABLE_NUMBER; i++) { + this.lottoNumber.add(i); + } + } +} diff --git a/src/main/java/domain/LottoTicket.java b/src/main/java/domain/LottoTicket.java index 3aebcb49..8b0d66c5 100644 --- a/src/main/java/domain/LottoTicket.java +++ b/src/main/java/domain/LottoTicket.java @@ -41,5 +41,4 @@ public boolean checkBonusNumber(int bonusNumber){ } - } diff --git a/src/main/java/domain/ManualTicketOffice.java b/src/main/java/domain/ManualTicketOffice.java new file mode 100644 index 00000000..ef5c2e8c --- /dev/null +++ b/src/main/java/domain/ManualTicketOffice.java @@ -0,0 +1,27 @@ +package domain; + +import view.InputView; + +import java.util.*; + +public class ManualTicketOffice extends TicketOffice { + + @Override + public List issueTickets(int numberOfTickets) { + List tickets = new ArrayList<>(); + int numberOfManualTicket = InputView.getNumberOfManualTicket(); + if (numberOfManualTicket>0) { + tickets.addAll(makeManualTickets(numberOfManualTicket)); + } + return tickets; + } + + private List makeManualTickets(int numberOfManualTicket) { + List manualLottoTickets = new ArrayList<>(); + System.out.println("수동으로 구매할 번호를 입력해 주세요. (응모할 번호 6자리)"); + for (int i = 0; i < numberOfManualTicket; i++) { + manualLottoTickets.add(new LottoTicket(InputView.getManualNumber())); + } + return manualLottoTickets; + } +} diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index 39ad0acc..7761b3fb 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -4,53 +4,11 @@ import java.util.*; -public class TicketOffice { - private final List lottoNumber = new ArrayList<>(); - private final int SELECTABLE_NUMBER = 45; - private final int SELECTED_NUMBER = 6; +public abstract class TicketOffice { private final int PRICE = 1000; + public abstract List issueTickets(int numberOfTickets); - public TicketOffice() { - setLottoNumber(); - } - - private void setLottoNumber() { - for (int i = 1; i <= SELECTABLE_NUMBER; i++) { - this.lottoNumber.add(i); - } - } - - private List makeManualTickets(int numberOfManualTicket) { - List manualLottoTickets = new ArrayList<>(); - System.out.println("수동으로 구매할 번호를 입력해 주세요. (응모할 번호 6자리)"); - for (int i = 0; i < numberOfManualTicket; i++) { - manualLottoTickets.add(new LottoTicket(InputView.getManualNumber())); - } - return manualLottoTickets; - } - - private LottoTicket makeAutoTicket() { - List ticketNumber = new ArrayList<>(); - Collections.shuffle(lottoNumber); - for (int i = 0; i < SELECTED_NUMBER; i++) { - ticketNumber.add(lottoNumber.get(i)); - } - Collections.sort(ticketNumber); - return new LottoTicket(ticketNumber); - } - - public List issueTickets(int numberOfTickets) { - List tickets = new ArrayList<>(); - int numberOfManualTicket = InputView.getNumberOfManualTicket(); - if (numberOfManualTicket>0) { - tickets.addAll(makeManualTickets(numberOfManualTicket)); - } - for (int j = 0; j < numberOfTickets - numberOfManualTicket; j++){ - tickets.add(makeAutoTicket()); - } - return tickets; - } public int getPrice() { return this.PRICE; From 01591d8a40ecc0354b2280e573637021e4ee464b Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Fri, 25 Feb 2022 14:54:42 +0900 Subject: [PATCH 18/19] =?UTF-8?q?[step3]=20User.goTicketOffice=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User.goTicketOffice : 수동 자동 각각 티켓을 구입한 뒤 OutputView에 출력할 정보를 넘긴다. (메서드 상속으로 인한 리팩터링의 결과) --- src/main/java/Main.java | 8 ++---- src/main/java/domain/ManualTicketOffice.java | 5 ++-- src/main/java/domain/TicketOffice.java | 7 +++--- src/main/java/domain/User.java | 26 ++++++++++++++------ src/main/java/view/OutputView.java | 2 +- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 10887b0d..228f87b7 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,16 +1,12 @@ -import domain.LottoCompany; -import domain.LottoTicket; -import domain.TicketOffice; -import domain.User; +import domain.*; import java.util.List; public class Main { public static void main(String[] args) { - TicketOffice ticketOffice = new TicketOffice(); LottoCompany lottoCompany = new LottoCompany(); User user = new User(); - user.purchaseTicketsFrom(ticketOffice); + user.goTicketOffice(); user.checkMyTicketsFrom(lottoCompany); } } diff --git a/src/main/java/domain/ManualTicketOffice.java b/src/main/java/domain/ManualTicketOffice.java index ef5c2e8c..e24c0aec 100644 --- a/src/main/java/domain/ManualTicketOffice.java +++ b/src/main/java/domain/ManualTicketOffice.java @@ -7,10 +7,9 @@ public class ManualTicketOffice extends TicketOffice { @Override - public List issueTickets(int numberOfTickets) { + public List issueTickets(int numberOfManualTicket) { List tickets = new ArrayList<>(); - int numberOfManualTicket = InputView.getNumberOfManualTicket(); - if (numberOfManualTicket>0) { + if (numberOfManualTicket > 0) { tickets.addAll(makeManualTickets(numberOfManualTicket)); } return tickets; diff --git a/src/main/java/domain/TicketOffice.java b/src/main/java/domain/TicketOffice.java index 7761b3fb..fd5c79c8 100644 --- a/src/main/java/domain/TicketOffice.java +++ b/src/main/java/domain/TicketOffice.java @@ -5,12 +5,11 @@ import java.util.*; public abstract class TicketOffice { - private final int PRICE = 1000; + private final static int PRICE = 1000; public abstract List issueTickets(int numberOfTickets); - - public int getPrice() { - return this.PRICE; + public static int getPrice() { + return PRICE; } } diff --git a/src/main/java/domain/User.java b/src/main/java/domain/User.java index 0f585dfd..90bbc19f 100644 --- a/src/main/java/domain/User.java +++ b/src/main/java/domain/User.java @@ -3,24 +3,34 @@ import view.InputView; import view.OutputView; +import java.util.ArrayList; import java.util.List; public class User { private int purchasedAmount; private int change; private int amount; - private List tickets; + private int totalNumberOfTickets; + private List tickets = new ArrayList<>(); - public void purchaseTicketsFrom(TicketOffice to) { + public void goTicketOffice(){ this.amount = InputView.getAmount(); - int pricePerTicket = to.getPrice(); - int numberOfTickets = this.amount / pricePerTicket; + int pricePerTicket = TicketOffice.getPrice(); + int numberOfManualTicket = InputView.getNumberOfManualTicket(); + int numberOfAutoTicket = (this.amount / pricePerTicket) - numberOfManualTicket; + this.totalNumberOfTickets = numberOfAutoTicket + numberOfManualTicket; - this.tickets = to.issueTickets(numberOfTickets); - this.purchasedAmount = pricePerTicket * numberOfTickets; - this.change = this.amount - purchasedAmount; + purchaseTicketsFrom(new ManualTicketOffice(), numberOfManualTicket); + purchaseTicketsFrom(new AutoTicketOffice(), numberOfAutoTicket); - OutputView.completePurchase(numberOfTickets, change, tickets); + this.purchasedAmount = pricePerTicket * totalNumberOfTickets; + this.change += this.amount - purchasedAmount; + OutputView.printPurchase(totalNumberOfTickets, change, tickets); + + } + + private void purchaseTicketsFrom(TicketOffice to, int numberOfTickets) { + this.tickets.addAll(to.issueTickets(numberOfTickets)); } public void checkMyTicketsFrom(LottoCompany lottoCompany){ diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java index dea3a007..de53c076 100644 --- a/src/main/java/view/OutputView.java +++ b/src/main/java/view/OutputView.java @@ -7,7 +7,7 @@ import java.util.Map; public class OutputView { - public static void completePurchase(int numberOfTickets, int change, List tickets) { + public static void printPurchase(int numberOfTickets, int change, List tickets) { System.out.println(numberOfTickets + "개를 구매했습니다."); System.out.println("거스름돈은 " + change + "원 입니다."); From a2bed8076c8f5a87315db8904b3b77e2dfa1af34 Mon Sep 17 00:00:00 2001 From: nathan29849 Date: Fri, 25 Feb 2022 14:59:34 +0900 Subject: [PATCH 19/19] =?UTF-8?q?[step3]=20README=203=EB=8B=A8=EA=B3=84=20?= =?UTF-8?q?=EC=88=98=EB=8F=99=EA=B5=AC=EB=A7=A4=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EA=B4=80=EB=A0=A8=20=EC=A0=95=EB=B3=B4=20?= =?UTF-8?q?=EA=B8=B0=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 93a43f87..8766b296 100644 --- a/README.md +++ b/README.md @@ -28,4 +28,16 @@ - [x] enum을 적용해 프로그래밍을 구현한다. ### 힌트 -- [x] Lotto 클래스를 사용자가 구매한 Lotto와 기계에 의해 추첨한 Lotto로 구분해서 생성한다. \ No newline at end of file +- [x] Lotto 클래스를 사용자가 구매한 Lotto와 기계에 의해 추첨한 Lotto로 구분해서 생성한다. + +--- + +## 로또 3단계 - 수동구매 기능 추가 +### 기능요구사항 +- [x] 현재 로또 생성기는 자동 생성 기능만 제공한다. 사용자가 수동으로 추첨 번호를 입력할 수 있도록 해야 한다. +- [x] 입력한 금액, 자동 생성 숫자, 수동 생성 번호를 입력하도록 해야 한다. + +### 프로그래밍 요구사항 +- [ ] 예외가 발생하는 부분에 대해 자바 Exception을 적용해 예외처리한다. +- [ ] 사용자가 입력한 값에 대한 예외 처리를 철저히 한다. +- [x] 상속과 인터페이스를 통해 구현을 간결히 할 수 없는지 고민해 본다. \ No newline at end of file