From fdd09cb6437be1540e6259076ff8dbe3dce8dcd5 Mon Sep 17 00:00:00 2001 From: banxzxx Date: Tue, 7 May 2024 00:02:39 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 93 +++++++++++++++++++ src/main/java/lotto/Application.java | 16 ++++ .../lotto/controller/LottoController.java | 71 ++++++++++++++ .../java/lotto/domain/CalculateProfit.java | 21 +++++ src/main/java/lotto/domain/CreateLotto.java | 24 +++++ .../java/lotto/domain/CreateLottoList.java | 24 +++++ src/main/java/lotto/domain/FindBingo.java | 62 +++++++++++++ src/main/java/lotto/dto/Bingo.java | 25 +++++ src/main/java/lotto/dto/Lotto.java | 53 +++++++++++ src/main/java/lotto/dto/Lottos.java | 16 ++++ src/main/java/lotto/dto/Money.java | 32 +++++++ .../lotto/inputView/InputBonusNumber.java | 32 +++++++ .../java/lotto/inputView/InputNumber.java | 32 +++++++ .../java/lotto/inputView/InputUserMoney.java | 22 +++++ .../java/lotto/outputView/OutputLottos.java | 13 +++ .../java/lotto/outputView/OutputPercent.java | 7 ++ .../java/lotto/outputView/OutputResult.java | 40 ++++++++ .../lotto/outputView/OutputTicketNum.java | 8 ++ 18 files changed, 591 insertions(+) create mode 100644 docs/README.md create mode 100644 src/main/java/lotto/Application.java create mode 100644 src/main/java/lotto/controller/LottoController.java create mode 100644 src/main/java/lotto/domain/CalculateProfit.java create mode 100644 src/main/java/lotto/domain/CreateLotto.java create mode 100644 src/main/java/lotto/domain/CreateLottoList.java create mode 100644 src/main/java/lotto/domain/FindBingo.java create mode 100644 src/main/java/lotto/dto/Bingo.java create mode 100644 src/main/java/lotto/dto/Lotto.java create mode 100644 src/main/java/lotto/dto/Lottos.java create mode 100644 src/main/java/lotto/dto/Money.java create mode 100644 src/main/java/lotto/inputView/InputBonusNumber.java create mode 100644 src/main/java/lotto/inputView/InputNumber.java create mode 100644 src/main/java/lotto/inputView/InputUserMoney.java create mode 100644 src/main/java/lotto/outputView/OutputLottos.java create mode 100644 src/main/java/lotto/outputView/OutputPercent.java create mode 100644 src/main/java/lotto/outputView/OutputResult.java create mode 100644 src/main/java/lotto/outputView/OutputTicketNum.java diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 00000000..1cb22071 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,93 @@ +## 게임 설명 +1. 범위가 1~45인 6개의 숫자를 가진 로또를 뽑는다. 한 장 당 1000원 +2. 로또를 사기 위한 입력값은 1000에 맞게 떨어져야한다 (아닐시 예외 발생) +3. 로또를 구매한 개수에 맞게 오름차순으로 나열되게 출력한다 + ``` + 8개를 구매했습니다. + [8, 21, 23, 41, 42, 43] + [3, 5, 11, 16, 32, 38] + [7, 11, 16, 35, 36, 44] + [1, 8, 11, 31, 41, 42] + [13, 14, 16, 38, 42, 45] + [7, 11, 30, 40, 42, 43] + [2, 13, 22, 32, 38, 45] + [1, 3, 5, 14, 22, 45] + ``` +4. 당첨 번호 6개를 입력 받는다 이때 번호는 쉼표로 구분되어 았어야한다 +5. 보너스 번호를 입력 받는다 +6. 당첨 내역을 출력한다 + ``` + 3개 일치 (5,000원) - 개 + 4개 일치 (50,000원) - 개 + 5개 일치 (1,500,000원) - 개 + 5개 일치, 보너스 볼 일치 (30,000,000원) - 개 + 6개 일치 (2,000,000,000원) - 개 + ``` +7. 소수점 둘째 자리에서 반올림한 수익률을 출력한다 + ``` + 총 수익률은 62.5%입니다. + ``` + +### 입력값 +``` +- 로또 구입 금액 +- 당첨 번호 6개 ( ,를 기준으로 구분) +- 보너스 번호 +``` + +--- +## 주요 요구사항 +- 클래스(객체)를 분리 +- 도메인 로직에 대한 단위 테스트를 작성 +- 함수(또는 메서드)의 길이가 15라인을 넘어가지 않도록 구현한다. +- else 예약어를 쓰지 않는다. (switch/case 도 당연히 안됨) +- depth는 2까지만 허용 +- 도메인 로직에 단위 테스트를 구현해야 한다. 단, UI(System.out, System.in, Scanner) 로직은 제외한다. +- Lotto 클래스를 활용해야한다 -> 사용자가 지정한 로또 혹은 구매한 로또의 객체 + - 기본 메서드 + - 생성자 + - 입력 받은 리스트의 길이가 6이 아닌 경우 예외를 발생시키는 메서드 +- enum 사용 + +--- +## 기능 구현 목록 +### 사용 DTO +- `Money`, `Lotto`, `Lottos`, `Bingo` +``` +Money : 사용자가 입력한 구매 금액 +Lotto : 사용자의 로또 및 사용자가 구매한 개수(ticket)만큼의 로또 객체. 총 6개의 숫자가 중복 없이 존재해야한다. +Lottos : 사용자가 구매한 개수만큼의 로또를 List<>로 묶은 객체 +Bingo : 사용자의 당첨번호와 3~6개의 숫자가 일치하는 로또 개수 객체. 당첨 기준이 동일하기 때문에 싱글톤으로 생성 (3,4,5,5+보너스,6) +``` +### 1. 사용자 입력 (inputView.Input*) +- 로또 구매 금액 입력 `InputUserMoney` + - 입력 처리 되자마자 정수형이 아닌 다른 자료형으로 입력되었는지 확인 + - 입력 처리 후 올바른 정수값인지 확인 + - 오류 확인은 Money 객체에서 실행한다 +- Lotto 클래스를 활용하여 로또 번호 6개 입력 `InputNumber` +- 보너스 번호 입력 `InputBonusNumber` +### 2. 로또 게임 구현 (domain) +- ticket(로또 구매 금액 / 1000)에 맞는 개수의 로또 객체를 가진 로또 리스트 객체 만들기 `CreateLotto`, `CreateLottoList` + - 랜덤으로 숫자들이 지정되어야한다 ( 중복x ) + - 오름차순으로 출력되도록 재배치 필요 +- Bingo 클래스를 통해 당첨 통계 만들기 `FindBingo` + - 여기서 빙고 클래스 객체가 어떤것인지 정해져있으므로는 싱클톤패턴으로 고유 클래스를 가지도록 구현 ( bingo3, bingo4, bingo5, bingo5wB, bingo6 ) +- 결과에 따른 수익률 계산하기 `CalculateProfit` + - 소수점 두번째 자리에서 반올림 하도록 구현 +### 3. 출력 (outputView.Output*) +- 구매 개수 출력 `OutputTicketNum.printTicketNum()` +- 뽑은 로또 리스트 출력 `OutputLottos.printLottos()` +- 당첨 통계 출력 `OutputResult.printResult()` +- 수익률 출력 `OutputPercent.printPercent()` +### 4. 테스트 코드 (LottoTest, InputTest) +- LottoTest + - 랜덤으로 부여된 로또에 1~45 사이가 아닌 숫자가 있으면 예외가 발생한다. `checkOutOfRangeNum()` + - 로또번호가 오름차순으로 정렬되는지 확인한다. `checkLottoNumArray()` +- InputTest + - 입력한 보너스 번호가 정수가 아닌 경우 예외가 발생한다. `checkBonusNumberValidate()` + - 입력한 보너스 번호가 범위를 벗어나면 예외가 발생한다. `checkBonusNumberRange()` + - 입력한 로또 번호가 올바른 구분자로 구분이 안되어 있으면 예외가 발생한다. `checkInputNumberValidate()` + - 입력한 구매 금액이 정수가 아닌 경우 예외가 발생한다. `checkInputUserMoneyValidate()` + - 구매 금액이 1000 단위가 아닌 경우 예외가 발생한다. `checkInputUserMoneyDigit()` + - 구매 금액이 양수가 아닌 경우 예외가 발생한다. `checkInputUserMoneyPositive()` + \ No newline at end of file diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java new file mode 100644 index 00000000..a5e215a2 --- /dev/null +++ b/src/main/java/lotto/Application.java @@ -0,0 +1,16 @@ +package lotto; + +import lotto.controller.LottoController; + +public class Application { + + public static void main(String[] args) { + try { + LottoController lottoController = new LottoController(); + lottoController.start(); + } catch (Exception e) { + System.out.println(e.getMessage()); + } + } +} + diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java new file mode 100644 index 00000000..da6bc244 --- /dev/null +++ b/src/main/java/lotto/controller/LottoController.java @@ -0,0 +1,71 @@ +package lotto.controller; + +import lotto.domain.CalculateProfit; +import lotto.domain.CreateLottoList; +import lotto.domain.FindBingo; +import lotto.dto.Lotto; +import lotto.dto.Lottos; +import lotto.dto.Money; +import lotto.inputView.InputBonusNumber; +import lotto.inputView.InputNumber; +import lotto.inputView.InputUserMoney; + +import java.util.List; + +import static lotto.outputView.OutputLottos.printLottos; +import static lotto.outputView.OutputPercent.printPercent; +import static lotto.outputView.OutputResult.printResult; +import static lotto.outputView.OutputTicketNum.printTicketNum; + +public class LottoController { + + public void start(){ + Money money = getUserMoney(); + int ticket = money.ticket(); + + Lottos lottos = makeLottoList(ticket); + printTicketNum(ticket); + printLottos(lottos); + + Lotto userLotto = getUserNumber(); + int bonusNum = getBonusNumber(); + + makeBingo(lottos, userLotto, bonusNum); + printResult(); + printPercent(calculate(ticket)); + } + + public Money getUserMoney(){ + InputUserMoney inputUserMoney = new InputUserMoney(); + Integer money = inputUserMoney.getInput(); + return new Money(money); + } + + public Lotto getUserNumber(){ + InputNumber inputUserNumber = new InputNumber(); + List userNumber = inputUserNumber.getInput(); + return new Lotto(userNumber); + } + + public int getBonusNumber(){ + InputBonusNumber inputBonusNumber = new InputBonusNumber(); + return inputBonusNumber.getInput(); + } + + public Lottos makeLottoList(int ticket) { + CreateLottoList lottoList = new CreateLottoList(); + return new Lottos(lottoList.createLottoList(ticket)); + } + + public void makeBingo(Lottos lottos, Lotto userLotto, int bonusNum){ + FindBingo findBingo = new FindBingo(); + findBingo.findBingos(lottos,userLotto,bonusNum); + } + + private double calculate(int ticket) { + CalculateProfit calculateProfit = new CalculateProfit(); + calculateProfit.calcProfit(); + return calculateProfit.calcProfitPercent(ticket*1000); + } + +} \ No newline at end of file diff --git a/src/main/java/lotto/domain/CalculateProfit.java b/src/main/java/lotto/domain/CalculateProfit.java new file mode 100644 index 00000000..d33471de --- /dev/null +++ b/src/main/java/lotto/domain/CalculateProfit.java @@ -0,0 +1,21 @@ +package lotto.domain; + +import lotto.dto.Bingo; + +public class CalculateProfit { + double profit = 0; + + public void calcProfit(){ + profit += 5000* Bingo.getBingo3().correctLotto; + profit += 50000*Bingo.getBingo4().correctLotto; + profit += 1500000*Bingo.getBingo5().correctLotto; + profit += 30000000*Bingo.getBingo5wB().correctLotto; + profit += 2000000000*Bingo.getBingo6().correctLotto; + } + + public double calcProfitPercent(int money){ + double percent = (profit/(double)money)*100; + return Math.round(percent*100)/100.0; + } + +} diff --git a/src/main/java/lotto/domain/CreateLotto.java b/src/main/java/lotto/domain/CreateLotto.java new file mode 100644 index 00000000..57731f6b --- /dev/null +++ b/src/main/java/lotto/domain/CreateLotto.java @@ -0,0 +1,24 @@ +package lotto.domain; + +import lotto.dto.Lotto; + +import java.util.*; + +public class CreateLotto { + public Lotto createLotto() { + Random rand = new Random(); + List randomNumbers = new ArrayList<>(); + + // 한 로또 내에 난수가 중복되지 않도록 HashSet을 사용한다 + Set uniqueNumbers = new HashSet<>(); + + while (uniqueNumbers.size() < 6) { + int randomNumber = rand.nextInt(45) + 1; + uniqueNumbers.add(randomNumber); + } + + randomNumbers.addAll(uniqueNumbers); + + return new Lotto(randomNumbers); + } +} diff --git a/src/main/java/lotto/domain/CreateLottoList.java b/src/main/java/lotto/domain/CreateLottoList.java new file mode 100644 index 00000000..cdbcb3da --- /dev/null +++ b/src/main/java/lotto/domain/CreateLottoList.java @@ -0,0 +1,24 @@ +package lotto.domain; + +import lotto.dto.Lotto; + +import java.util.ArrayList; +import java.util.List; + +public class CreateLottoList { + + public List createLottoList(int ticket){ + List lottoList = new ArrayList<>(); + for ( int i = 0 ; i < ticket ; i++ ){ + lottoList.add(createLotto()); + } + + return lottoList; + } + + public Lotto createLotto(){ + CreateLotto lotto = new CreateLotto(); + return lotto.createLotto(); + } + +} diff --git a/src/main/java/lotto/domain/FindBingo.java b/src/main/java/lotto/domain/FindBingo.java new file mode 100644 index 00000000..cbb23005 --- /dev/null +++ b/src/main/java/lotto/domain/FindBingo.java @@ -0,0 +1,62 @@ +package lotto.domain; + +import lotto.dto.Bingo; +import lotto.dto.Lotto; +import lotto.dto.Lottos; + +public class FindBingo { + int correctNum = 0; + int bonusFlag = 0; + + public void findBingos(Lottos lottos, Lotto userLotto, int bonusNum){ + + for ( Lotto lotto : lottos.getLottos() ){ + correctNum = 0; + bonusFlag = 0; + compareUserLotto(lotto, userLotto, bonusNum); + + checkBingoList(correctNum, bonusFlag); + } + } + + public void compareUserLotto(Lotto lotto, Lotto userLotto, int bonusNum){ + for ( int i : userLotto.getNumbers() ){ + for ( int j : lotto.getNumbers()){ + compareNumber(i,j,bonusNum); + } + } + } + + public void compareNumber(int i, int j, int bonusNum ){ + if ( i == j ) correctNum++; + if ( bonusNum == j ) bonusFlag = 1; + } + + public void checkBingoList(int correctNum, int bonusFlag){ + findBingo3(correctNum); + findBingo4(correctNum); + findBingo5(correctNum, bonusFlag); + findBingo5wB(correctNum, bonusFlag); + findBingo6(correctNum); + } + + public void findBingo3( int correctNum ){ + if ( correctNum == 3 ) Bingo.getBingo3().correctLotto++; + } + + public void findBingo4( int correctNum ){ + if ( correctNum == 4 ) Bingo.getBingo4().correctLotto++; + } + + public void findBingo5( int correctNum, int bonusFlag ){ + if ( correctNum == 5 && bonusFlag == 0 ) Bingo.getBingo5().correctLotto++; + } + + public void findBingo5wB( int correctNum, int bonusFlag ){ + if ( correctNum == 5 && bonusFlag == 1 ) Bingo.getBingo5wB().correctLotto++; + } + + public void findBingo6( int correctNum ){ + if ( correctNum == 6 ) Bingo.getBingo6().correctLotto++; + } +} diff --git a/src/main/java/lotto/dto/Bingo.java b/src/main/java/lotto/dto/Bingo.java new file mode 100644 index 00000000..c023e556 --- /dev/null +++ b/src/main/java/lotto/dto/Bingo.java @@ -0,0 +1,25 @@ +package lotto.dto; + +public class Bingo { + int bingoNum; + boolean checkBonus; + public int correctLotto = 0; + + private Bingo(int bingoNum, boolean checkBonus){ + this.bingoNum = bingoNum; + this.checkBonus = checkBonus; + } + + private static Bingo bingo3 = new Bingo(3,false); + private static Bingo bingo4 = new Bingo(4,false); + private static Bingo bingo5 = new Bingo(5,false); + private static Bingo bingo5wB = new Bingo(5,true); + private static Bingo bingo6 = new Bingo(6,false); + + public static Bingo getBingo3() { return bingo3; } + public static Bingo getBingo4() { return bingo4; } + public static Bingo getBingo5() { return bingo5; } + public static Bingo getBingo5wB() { return bingo5wB; } + public static Bingo getBingo6() { return bingo6; } + +} diff --git a/src/main/java/lotto/dto/Lotto.java b/src/main/java/lotto/dto/Lotto.java new file mode 100644 index 00000000..c8fc1933 --- /dev/null +++ b/src/main/java/lotto/dto/Lotto.java @@ -0,0 +1,53 @@ +package lotto.dto; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class Lotto { + private final List numbers; + + public Lotto(List numbers) { + checkValidateCnt(numbers); + checkValidateRange(numbers); + checkDuplicatedNum(numbers); + numbers = sorted(numbers); + this.numbers = numbers; + } + + private void checkDuplicatedNum(List numbers) { + Set nonDuplicateNumbers = new HashSet<>(numbers); + if (nonDuplicateNumbers.size() != 6) { + throw new IllegalArgumentException("[ERROR] 중복된 숫자가 존재하는 로또입니다. "); + } + } + + private void checkValidateRange(List numbers) { + for ( int num : numbers){ + if ( num < 1 || num > 45 ){ + throw new IllegalArgumentException("[ERROR] 지정된 범위에 벗어나는 숫자입니다."); + } + } + } + + private void checkValidateCnt(List numbers) { + if (numbers.size() != 6) { + throw new IllegalArgumentException("[ERROR] 로또 번호 개수는 6개여야 합니다."); + } + } + + public List getNumbers() { + return numbers; + } + + public List sorted(List numbers) { + return numbers.stream().sorted().collect(Collectors.toList()); + } + + @Override + public String toString() { + return numbers + ""; + } + +} diff --git a/src/main/java/lotto/dto/Lottos.java b/src/main/java/lotto/dto/Lottos.java new file mode 100644 index 00000000..c2b91852 --- /dev/null +++ b/src/main/java/lotto/dto/Lottos.java @@ -0,0 +1,16 @@ +package lotto.dto; + +import java.util.List; + +public class Lottos { + + private final List lottos; + + public Lottos(List lottos) { + this.lottos = lottos; + } + + public List getLottos() { + return lottos; + } +} diff --git a/src/main/java/lotto/dto/Money.java b/src/main/java/lotto/dto/Money.java new file mode 100644 index 00000000..7f2662d6 --- /dev/null +++ b/src/main/java/lotto/dto/Money.java @@ -0,0 +1,32 @@ +package lotto.dto; + +public class Money { + private final int money; + + public Money(int input) { + checkValidateInput(input); + this.money = input; + } + + private void checkValidateInput(int input) { + inputZero(input); + inputDivisible(input); + } + + private void inputZero(int input) { + if ( input <= 0 ) throw new IllegalArgumentException("[ERROR] 구매 금액이 0보다 커야합니다. "); + } + + private void inputDivisible(int input) { + if ( input % 1000 != 0 ) throw new IllegalArgumentException("[ERROR] 1000단위의 금액을 입력해야합니다."); + } + + public int ticket() { + return money / 1000; + } + + public int getMoney() { + return money; + } +} + diff --git a/src/main/java/lotto/inputView/InputBonusNumber.java b/src/main/java/lotto/inputView/InputBonusNumber.java new file mode 100644 index 00000000..79d57b3f --- /dev/null +++ b/src/main/java/lotto/inputView/InputBonusNumber.java @@ -0,0 +1,32 @@ +package lotto.inputView; + +import java.util.Scanner; +import java.util.regex.Pattern; + +public class InputBonusNumber { + + private static final Pattern PATTERN = Pattern.compile("\\d+"); + + public Integer getInput(){ + System.out.println("\n보너스 번호를 입력해 주세요."); + Scanner scan = new Scanner(System.in); + String bonusNumber = scan.next(); + checkValidate(bonusNumber); + checkValidateRange(bonusNumber); + return Integer.parseInt(bonusNumber); + } + + private void checkValidate(String bonusNumber) { + if (!PATTERN.matcher(bonusNumber).matches()) { + throw new IllegalArgumentException("[ERROR] 올바르지 않은 입력값 입니다."); + } + + + } + + public void checkValidateRange(String bonusNumber) { + if ( Integer.parseInt(bonusNumber) < 1 || Integer.parseInt(bonusNumber) > 45 ) { + throw new IllegalArgumentException("[ERROR] 지정된 범위에 벗어나는 숫자입니다."); + } + } +} diff --git a/src/main/java/lotto/inputView/InputNumber.java b/src/main/java/lotto/inputView/InputNumber.java new file mode 100644 index 00000000..22112a5a --- /dev/null +++ b/src/main/java/lotto/inputView/InputNumber.java @@ -0,0 +1,32 @@ +package lotto.inputView; + +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; +import java.util.regex.Pattern; + +public class InputNumber { + + private static final Pattern PATTERN = Pattern.compile("(\\d{1,2},){5}\\d{1,2}"); + + public List getInput(){ + + System.out.println("\n당첨 번호를 입력해 주세요."); + Scanner scan = new Scanner(System.in); + String userNumList = scan.next(); + checkValidate(userNumList); + + List userNumbers = new ArrayList<>(); + for ( String num : userNumList.split(",") ) { + userNumbers.add(Integer.parseInt(num)); + } + + return userNumbers; + } + + public void checkValidate(String userNumList) { + if (!PATTERN.matcher(userNumList).matches()) { + throw new IllegalArgumentException("[ERROR] 올바른 구분자로 입력되어있지 않는 입력값입니다."); + } + } +} diff --git a/src/main/java/lotto/inputView/InputUserMoney.java b/src/main/java/lotto/inputView/InputUserMoney.java new file mode 100644 index 00000000..c419e3a3 --- /dev/null +++ b/src/main/java/lotto/inputView/InputUserMoney.java @@ -0,0 +1,22 @@ +package lotto.inputView; + +import java.util.Scanner; +import java.util.regex.Pattern; + +public class InputUserMoney { + private static final Pattern PATTERN = Pattern.compile("\\d+"); + + public Integer getInput(){ + System.out.println("구매금액을 입력해 주세요."); + Scanner scan = new Scanner(System.in); + String userMoney = scan.nextLine(); + checkValidate(userMoney); + return Integer.parseInt(userMoney); + } + + public void checkValidate(String userMoney) { + if (!PATTERN.matcher(userMoney).matches()) { + throw new IllegalArgumentException("[ERROR] 올바르지 않은 입력값입니다. "); + } + } +} diff --git a/src/main/java/lotto/outputView/OutputLottos.java b/src/main/java/lotto/outputView/OutputLottos.java new file mode 100644 index 00000000..15a6df3f --- /dev/null +++ b/src/main/java/lotto/outputView/OutputLottos.java @@ -0,0 +1,13 @@ +package lotto.outputView; + +import lotto.dto.Lotto; +import lotto.dto.Lottos; + +public class OutputLottos { + public static void printLottos(Lottos lottos){ + for (Lotto l : lottos.getLottos()) { + System.out.println(l); + } + } + +} diff --git a/src/main/java/lotto/outputView/OutputPercent.java b/src/main/java/lotto/outputView/OutputPercent.java new file mode 100644 index 00000000..610044e1 --- /dev/null +++ b/src/main/java/lotto/outputView/OutputPercent.java @@ -0,0 +1,7 @@ +package lotto.outputView; + +public class OutputPercent { + public static void printPercent(double profitPercent){ + System.out.println("총 수익률은 " + profitPercent + "%입니다."); + } +} diff --git a/src/main/java/lotto/outputView/OutputResult.java b/src/main/java/lotto/outputView/OutputResult.java new file mode 100644 index 00000000..24fa2a4f --- /dev/null +++ b/src/main/java/lotto/outputView/OutputResult.java @@ -0,0 +1,40 @@ +package lotto.outputView; + +import lotto.dto.Bingo; + +public class OutputResult { + + enum Result { + BINGO3(Bingo.getBingo3().correctLotto,"3개 일치 (5,000원) - "), + BINGO4(Bingo.getBingo4().correctLotto,"4개 일치 (50,000원) - "), + BINGO5(Bingo.getBingo5().correctLotto,"5개 일치 (1,500,000원) - "), + BINGO5WB(Bingo.getBingo5wB().correctLotto,"5개 일치, 보너스 볼 일치 (30,000,000원) - "), + BINGO6(Bingo.getBingo6().correctLotto,"6개 일치 (2,000,000,000원) - "); + + final private int matchNum; + + final private String message; + + Result(int matchNum, final String message){ + this.matchNum = matchNum; + this.message = message; + } + + public String getMessage(){ + return message; + } + + public int getMatchNum(){ + return matchNum; + } + } + + public static void printResult(){ + System.out.println("\n당첨통계\n---"); + for ( Result result : Result.values() ) { + System.out.println(result.getMessage() + result.getMatchNum() + "개"); + } + } + +} + diff --git a/src/main/java/lotto/outputView/OutputTicketNum.java b/src/main/java/lotto/outputView/OutputTicketNum.java new file mode 100644 index 00000000..5d536761 --- /dev/null +++ b/src/main/java/lotto/outputView/OutputTicketNum.java @@ -0,0 +1,8 @@ +package lotto.outputView; + +public class OutputTicketNum { + public static void printTicketNum(int ticket){ + System.out.println("\n" + ticket + "개를 구매했습니다."); + } + +}