Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 75 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,75 @@
![1](description-img/3.로또_page-0001.jpg)
![2](description-img/3.로또_page-0002.jpg)
![3](description-img/3.로또_page-0003.jpg)
![4](description-img/3.로또_page-0004.jpg)
![5](description-img/3.로또_page-0005.jpg)
![6](description-img/3.로또_page-0006.jpg)
# 기능 구현 목록

## Model
### domain.Lotto
- [x] 주어진 필드와 메서드 구현
- [x] 당첨번호를 받아서 몇개 일치하는지 반환하는 메서드 구현
- [x] 당첨번호를 받아서 2등인지 반환하는 메서드 구현
### domain.LottoList
- [x] 로또 객체를 저장하는 리스트 저장
### domain.WinningNumber
- [x] 당첨 번호 리스트로 저장
- [x] 보너스 번호 저장
- [x] 값이 당첨번호중 하나와 같을 경우 예외 발생
### domain.LottoResult
- [x] 등수별 개수 저장
- [x] WinningConstant를 객체로 사용해 등수별 일치해야 하는 개수와 당첨 금액 데이터 사용
- [x] 수익률 계산하는 메서드 구현
### service.LottoService
- [x] 구입 금액에 대한 로또를 발행하는 메서드 구현
- [x] 구입 금액 입력값에 대한 검증
- [x] 검증 실패시(예외 발생시) 예외 메시지 출력 후 null 반환
- [x] 구입 금액에 맞는 개수의 로또 발행
- [x] 발행한 로또를 리스트로 저장
- [x] 로또 리스트 객체 반환
- [x] 당첨 번호를 저장하는 객체를 생성하고 반환하는 메서드 구현
- [x] 당첨 번호 파싱
- [x] 검증 실패시(예외 발생시) 예외 메시지 출력 후 null 반환
- [x] 당첨 번호 객체 생성 후 반환
- [x] 당첨 번호 객체에 보너스 번호 추가
- [x] 보너스 번호 입력값에 대한 검증
- [x] 검증 실패시(예외 발생시) 예외 메시지 출력 후 null 반환
- [x] 객체 내부에 추가한 후 해당 객체 반환(예외일 경우 null 반환)

## View
### view.InputView
- [x] 사용자로부터 구입 금액 입력받아서 반환하는 메서드 구현
- [x] 사용자로부터 당첨 번호 입력받아서 반환하는 메서드 구현
- [x] 사용자로부터 보너스 번호 입력받아서 반환하는 메서드 구현
### view.OutputView
- [x] 발행한 로또 오름차순으로 출력

## Controller
### controller.LottoController
- [x] 입력값에 따른 예외 발생 시 다시 입력받을 수 있도록 반복문 사용
- [x] 구입 금액 입력값을 받아서 Service로 넘김
- [x] 구입 금액에 맞게 발행된 로또 리스트 받음
- [x] 만약 null이 반환되었으면 사용자로부터 재입력 받음
- [x] 당첨 번호 입력값을 받아서 Service로 넘김
- [x] 당첨 번호 리스트가 저장된 객체 받음
- [x] 만약 null이 반환되었으면 사용자로부터 재입력 받음.
- [x] 보너스 번호 입력값을 받아서 Service로 넘김
- [x] 만약 null이 반환되었으면 사용자로부터 재입력 받음.

## Others
### util.Validator
검증 실패 시 메시지와 함께 예외 던짐
- [x] null 또는 공백만 입력한 경우 검증하는 메서드 구현
- [x] 0이하의 값 입력한 경우 검증하는 메서드 구현
- [x] 1000원 단위가 아닌 경우 검증하는 메서드 구현
- [x] 10만원 초과하는 경우 검증하는 메서드 구현
- [x] 당첨 번호 6개 아닌 경우 검증하는 메서드 구현
- [x] 당첨 번호가 1~45의 정수가 아닌 경우(리스트) 검증하는 메서드 구현
- [x] 당첨 번호가 1~45의 정수가 아닌 경우(값) 검증하는 메서드 구현
### util.parser
- [x] 당첨 번호 입력값 쉼표로 구분하는 메서드 구현
- [x] 쉼표로 구분해서 만든 리스트 검증
- [x] 당첨 번호 6개 아닌 경우
- [x] 당첨 번호가 1~45의 정수가 아닌 경우
- [x] 당첨 번호 리스트 반환
### random.RandomGenerator
- [x] 로또 번호 발행하는 메서드 구현
### constant.ErrorMessage
- [x] 에러메시지 상수 보관
### constant.Rank
- [x] 등수별 일치해야 하는 개수와 당첨 금액을 상수로 저장
Binary file added description-img/3.로또_page-0001.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added description-img/3.로또_page-0002.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added description-img/3.로또_page-0003.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added description-img/3.로또_page-0004.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added description-img/3.로또_page-0005.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added description-img/3.로또_page-0006.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/java/lotto/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package lotto;

import java.util.ArrayList;
import java.util.List;

public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
new ApplicationStarter().start();
}
}
18 changes: 18 additions & 0 deletions src/main/java/lotto/ApplicationStarter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package lotto;

import lotto.controller.LottoController;
import lotto.service.LottoService;
import lotto.view.InputView;
import lotto.view.OutputView;

public class ApplicationStarter {

public void start() {
LottoController controller = new LottoController(
new LottoService(),
new InputView(),
new OutputView()
);
controller.run();
}
}
20 changes: 0 additions & 20 deletions src/main/java/lotto/Lotto.java

This file was deleted.

22 changes: 22 additions & 0 deletions src/main/java/lotto/constant/ErrorMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lotto.constant;

public enum ErrorMessage {
LOTTO_NUMBER_COUNT_ERROR("[ERROR] 로또 번호는 6개여야 합니다."),
BONUS_NUMBER_NOT_UNIQUE_ERROR("[ERROR] 보너스 번호는 당첨 번호와 달라야 합니다."),
INVALID_INPUT_FORMAT_ERROR("[ERROR] 올바르지 않은 형식의 입력입니다."),
NOT_POSITIVE_ERROR("[ERROR] 양수를 입력해주세요."),
MAX_PURCHASE_AMOUNT_ERROR("[ERROR] 최대 10만원까지만 구매 가능합니다."),
PURCHASE_AMOUNT_UNIT_ERROR("[ERROR] 1000원 단위로 입력해주세요."),
LOTTO_NUMBER_RANGE_ERROR("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."),
LOTTO_NUMBER_NOT_UNIQUE_ERROR("[ERROR] 로또 번호는 중복이 없어야 합니다.");

private final String message;

ErrorMessage(String message) {
this.message = message;
}

public String getMessage() {
return message;
}
}
33 changes: 33 additions & 0 deletions src/main/java/lotto/constant/Rank.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package lotto.constant;

public enum Rank {
FIRST(1, 2000000000, 6),
SECOND(2, 30000000, 5),
THIRD(3, 1500000, 5),
FOURTH(4, 50000, 4),
FIFTH(5, 5000, 3);

Rank(Integer rank, int prize, int matchingCount) {
this.rank = rank;
this.prize = prize;
this.matchingCount = matchingCount;
}

private final Integer rank;
private final int prize;
private final int matchingCount;

public Integer getRank() {
return rank;
}

public int getPrize() {
return prize;
}

public int getMatchingCount() {
return matchingCount;
}


}
49 changes: 49 additions & 0 deletions src/main/java/lotto/controller/LottoController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package lotto.controller;

import lotto.domain.LottoList;
import lotto.domain.LottoResult;
import lotto.domain.WinningNumber;
import lotto.service.LottoService;
import lotto.view.InputView;
import lotto.view.OutputView;

public class LottoController {
private final LottoService service;
private final InputView inputView;
private final OutputView outputView;

public LottoController(LottoService service, InputView inputView, OutputView outputView) {
this.service = service;
this.inputView = inputView;
this.outputView = outputView;
}

public void run() {
String inputPurchaseAmount;
String inputWinningNumber;
String inputBonusNumber;
LottoList lottoList;
WinningNumber winningNumber;
boolean isNull;

do {
inputPurchaseAmount = inputView.readPurchaseAmount();
lottoList = service.getLottoList(inputPurchaseAmount);
} while (lottoList == null);

outputView.printLottoList(lottoList);

do {
inputWinningNumber = inputView.readWinningNumber();
winningNumber = service.getWinningNUmber(inputWinningNumber);
} while (winningNumber == null);

do {
inputBonusNumber = inputView.readBonusNumber();
isNull = service.getWinningNumberWithBonusNumber(winningNumber, inputBonusNumber);
} while (!isNull);

LottoResult lottoResult = service.getLottoResult(winningNumber, lottoList);
outputView.printLottoResult(lottoResult);
}
}
40 changes: 40 additions & 0 deletions src/main/java/lotto/domain/Lotto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package lotto.domain;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static lotto.constant.ErrorMessage.LOTTO_NUMBER_COUNT_ERROR;
import static lotto.util.Validator.validateLottoNumberUnique;

public class Lotto {
private final List<Integer> numbers;

public Lotto(List<Integer> numbers) {
validate(numbers);
this.numbers = numbers;
}

private void validate(List<Integer> numbers) {
if (numbers.size() != 6) {
throw new IllegalArgumentException(LOTTO_NUMBER_COUNT_ERROR.getMessage());
}
validateLottoNumberUnique(numbers);
}

// TODO: 추가 기능 구현
public List<Integer> getNumbers() {
return numbers.stream().sorted().toList();
}

public int getWinningNumberCount(List<Integer> winningNumber) {
Set<Integer> numbersSet = new HashSet<>(numbers);
Set<Integer> winningNumberSet = new HashSet<>(winningNumber);
numbersSet.retainAll(winningNumberSet);
return numbersSet.size();
}

public boolean checkBonusNumber(int bonusNumber) {
return numbers.contains(bonusNumber);
}
}
28 changes: 28 additions & 0 deletions src/main/java/lotto/domain/LottoList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lotto.domain;

import java.util.ArrayList;
import java.util.List;

public class LottoList {
private final List<Lotto> lottoList;

private LottoList(List<Lotto> lottoList) {
this.lottoList = lottoList;
}

public static LottoList of() {
return new LottoList(new ArrayList<>());
}

public void add(Lotto lotto) {
lottoList.add(lotto);
}

public int getLottoCount() {
return lottoList.size();
}

public List<Lotto> getLottoList() {
return lottoList;
}
}
44 changes: 44 additions & 0 deletions src/main/java/lotto/domain/LottoResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package lotto.domain;

import lotto.constant.Rank;

import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;

public class LottoResult {
private final Map<Rank, Integer> matchedCount = new TreeMap<>(Comparator.comparing(Rank::getRank).reversed());
private double profitRate;

public LottoResult() {
for (Rank rank : Rank.values()) {
matchedCount.put(rank, 0);
}
}

public Map<Rank, Integer> getMatchedCount() {
return matchedCount;
}

public double getProfitRate() {
return profitRate;
}

public void confirmRank(WinningNumber winningNumber, LottoList lottoList) {
for (Lotto lotto : lottoList.getLottoList()) {
Rank rank = winningNumber.getRank(lotto);
if (rank != null) {
matchedCount.put(rank, matchedCount.getOrDefault(rank, 0) + 1);
}
}
}

public void calculateProfitRate(LottoList lottoList) {
int purchaseAmount = lottoList.getLottoCount() * 1000;
int profit = 0;
for (Rank rank : matchedCount.keySet()) {
profit += rank.getPrize() * matchedCount.get(rank);
}
profitRate = (double) profit / purchaseAmount * 100;
}
}
Loading