Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ceb411e
refactor : 티켓 장 수 계산 메소드 수정, static 키워드 수정
pageprologue Jul 13, 2021
250b0a0
refactor : 로또 당첨 순위 클래스명 변경 (LottoPrize -> LottoRank), 코드 이동 및 테스트 코드 수정
pageprologue Jul 13, 2021
5079c3d
docs : 구현 목록 추가
pageprologue Jul 14, 2021
76114b5
style : 패키지 정리
pageprologue Jul 14, 2021
7889a2c
feat : 티켓 장 수 테스트 및 기능 구현, 관련 소스 수정
pageprologue Jul 14, 2021
3ce0976
feat : InputView 수동 티켓 입력, 티켓 장 수 예외 처리 추가
pageprologue Jul 14, 2021
0f9d2a0
feat : 로또 수동 생성 테스트 및 기능 추가
pageprologue Jul 14, 2021
7f7ae6c
feat : 전체 로또 티켓 생성 테스트 및 기능 추가, 관련 소스 수정
pageprologue Jul 14, 2021
4f4b103
refactor : OutputView 정리
pageprologue Jul 14, 2021
1fe76e0
feat : 로또 번호가 중복될 경우 예외 발생 테스트 및 기능 구현
pageprologue Jul 15, 2021
6983ea5
feat : 당첨 결과 테스트 및 기능 구현, 관련 소스 수정, 코드 정리
pageprologue Jul 15, 2021
2094b29
fix : 보너스 번호가 일치하는 경우 당첨 순위 버그 수정 및 테스트 코드 작성
pageprologue Jul 15, 2021
4089514
refactor : 요소가 없는 경우 Collections.emptyList() 로 변경
pageprologue Jul 15, 2021
ab32b7c
feat : 로또 티켓 유효성 검사 테스트 및 기능 구현
pageprologue Jul 15, 2021
b2792af
refactor : static 키워드 제거, 생성자 주입으로 변경
pageprologue Aug 1, 2021
2a6e9d8
refactor : 사용자 입력 에러를 Controller 가 담당하도록 수정, 클래스 변수를 생성자 주입으로 수정
pageprologue Aug 2, 2021
af61ec9
refactor : 당첨 번호 일치 개수 기능 WinningLottoRank -> WinningNumbers 로 이동
pageprologue Aug 3, 2021
75f5df1
refactor : LottoNumber 캐시 적용
pageprologue Aug 17, 2021
491f190
refactor : LottoService, LottoController, StringUtil 정리
pageprologue Aug 17, 2021
a01d40a
style : rank 패키지 생성 및 Rank 관련 클래스 이동
pageprologue Aug 17, 2021
db7c747
refactor : 테스트 클래스 패키지 이동, Rank 2등인 경우 수정
pageprologue Aug 20, 2021
7bb61e0
chore: root project name 수정
pageprologue Nov 3, 2021
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
43 changes: 32 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,63 @@

- [x] 입력
- [x] 구입 금액을 입력한다.
- [x] 수동으로 구매할 로또 수를 입력한다.
- [x] 수동으로 구매할 번호를 입력한다.
- [x] 지난 주 당첨 번호를 입력한다.
- [x] 보너스 볼을 입력한다.

- [] 출력
- [x] 구매 금액에 따른 로또 티켓 장수를 출력한다.
- [x] 출력
- [x] 구입 금액에 따라 수동 구매 장수와 자동 구매 장수를 출력한다.
- [x] 구매 금액에 따른 각 로또 티켓의 번호를 출력한다.
- [x] 당첨 번호와 일치하는 로또 티켓 개수를 출력한다.
- [x] 총 수익률을 출력한다.

***

- [x] 구입 금액
- [x] 구입 금액은 1000원 단위의 정수값이다.
- [x] ERROR : 음수일 경우 예외가 발생한다.
- [x] ERROR : 1000원 단위가 아닐 경우 예외가 발생한다.
- [x] 로또 티켓 금액으로 나눈 티켓 장수로 반환한다.

- [x] 티켓 장수
- [x] 구입 금액과 수동 로또 티켓 개수를 인자로 받아 로또 티켓 장수를 반환한다.
- [x] ERROR : 전체 티켓 장수 보다 수동 구매 장수가 많은 경우 예외가 발생한다.


- [x] 로또 티켓 머신
- [x] 구입 금액을 1000원 단위로 나누어 로또 티켓 장수를 반환한다.
- [x] 로또 티켓 장수만큼 로또 티켓을 생성한다.
- [x] 수동으로 로또 티켓을 생성한다.
- [x] 자동으로 로또 티켓을 생성한다.
- [x] 전체 로또 티켓을 생성한다.

- [x] 로또 티켓
- [x] 6개의 로또 번호를 가진다.
***

- [x] 로또 번호 생성기
- [x] 1 ~ 45 사이의 난수로 로또 번호를 생성한다.
- [x] 6개의 로또 번호를 반환한다.

- [x] 로또 번호
- [x] 로또 번호는 1 ~ 45 사이의 값으로 로또 번호를 생성한다.
- [x] ERROR : 1 ~ 45가 아닐 경우 예외가 발생한다.

- [x] 로또 티켓
- [x] 6개의 로또 번호를 가진다.
- [x] ERROR : 로또 번호가 6개 보다 작거나 많은 경우 예외가 발생한다.
- [x] ERROR : 로또 번호가 중복될 경우 예외가 발생한다.

- [x] 로또 순위
- [x] 로또 티켓의 당첨 수에 따른 순위를 반환한다.

***

- [x] 당첨 번호
- [x] ERROR: 중복되는 로또 번호가 있을 경우 예외가 발생한다.
- [x] 당첨 번호와 중복되지 않는 1 ~ 45 중 하나는 보너스 볼이다.
- [x] 당첨 번호와 일치하는 로또 번호 개수를 반환한다.

- [x] 로또 상금
- [x] 로또 티켓의 당첨 순위에 따른 당첨 금액을 반환한다.

- [x] 로또 통계
- [x] 당첨 결과
- [x] 당첨 번호와 일치하는 로또 번호 개수를 반환한다.
- [x] 보너스 번호 일치하는 로또 번호 개수를 반환한다.
- [x] 당첨 번호 개수가 같은 로또 티켓 개수를 반환한다.

- [x] 당첨 통계
- [x] 당첨 순위의 수익률을 계산한다.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
rootProject.name = 'java-racingcar'
rootProject.name = 'java-lotto'

28 changes: 26 additions & 2 deletions src/main/java/lotto/LottoApplication.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
package lotto;

import lotto.controller.LottoController;
import lotto.domain.lotto.LottoTickets;
import lotto.domain.vending.BuyingPrice;
import lotto.domain.vending.TicketAmount;
import lotto.domain.winning.WinningNumbers;
import lotto.view.InputView;
import lotto.view.OutputView;

public class LottoApplication {
public static void main(String[] args) {
LottoController lottoController = new LottoController();
lottoController.run();
try {
LottoController lottoController = new LottoController();

BuyingPrice buyingPrice = lottoController.getBuyingPrice(InputView.getBuyingPrice());
TicketAmount ticketAmount = lottoController.getTicketAmount(buyingPrice.totalTicketAmount(), InputView.getManualCount());

LottoTickets lottoTickets = lottoController.issueTickets(ticketAmount);
OutputView.printTicketAmount(ticketAmount);
OutputView.printLottoTickets(lottoTickets);

String winningNumber = InputView.getWinningNumber();
String bonusNumber = InputView.getBonusNumber();
WinningNumbers winningNumbers = lottoController.validateWinningLottoNumbers(winningNumber, bonusNumber);
float profitRate = lottoController.calculateProfitRate(ticketAmount.total(), lottoTickets, winningNumbers);
OutputView.printProfitRate(profitRate);

} catch (RuntimeException e) {
System.out.println("=====> Error Message : " + e.getMessage());
}
}
}

67 changes: 41 additions & 26 deletions src/main/java/lotto/controller/LottoController.java
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
package lotto.controller;

import lotto.domain.*;
import lotto.domain.lotto.LottoTickets;
import lotto.domain.rank.WinningLottoRank;
import lotto.domain.vending.BuyingPrice;
import lotto.domain.vending.TicketAmount;
import lotto.domain.winning.WinningNumbers;
import lotto.service.LottoService;
import lotto.util.StringUtil;
import lotto.view.InputView;
import lotto.view.OutputView;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static lotto.domain.LottoTicketVendingMachine.TICKET_PRICE;

public class LottoController {
public void run() {
String inputPrice = InputView.getBuyingPrice();
BuyingPrice buyingPrice = new BuyingPrice(inputPrice);
int ticketAmount = buyingPrice.divide(TICKET_PRICE);
OutputView.printTicketAmount(ticketAmount);

LottoTicketVendingMachine lottoTicketVendingMachine = new LottoTicketVendingMachine();
List<LottoTicket> lottoTickets = lottoTicketVendingMachine.issueTickets(buyingPrice);
OutputView.printLottoTickets(lottoTickets);

String inputWinningNumbers = InputView.getWinningNumber();
List<Integer> splitWinningNumbers = InputView.split(inputWinningNumbers)
.stream()
.map(Integer::parseInt)
private final LottoService lottoService = new LottoService();

public BuyingPrice getBuyingPrice(String price) throws NumberFormatException {
try {
return new BuyingPrice(Integer.parseInt(price));

} catch (NumberFormatException e) {
throw new IllegalArgumentException("구매 금액은 숫자로 입력해 주세요.");
}
}

public TicketAmount getTicketAmount(int totalTicketAmount, String manualTicketAmount) {
try {
return new TicketAmount(totalTicketAmount, Integer.parseInt(manualTicketAmount));

} catch (NumberFormatException e) {
throw new IllegalArgumentException("수동으로 구매할 티켓 개수를 확인해 주세요.");
}
}

public LottoTickets issueTickets(TicketAmount ticketAmount) {
List<String> inputManualNumbers = InputView.getManualNumbers(ticketAmount.manual());
List<List<Integer>> manualNumbers = inputManualNumbers.stream()
.map(StringUtil::splitParseInt)
.collect(Collectors.toList());
return lottoService.issueTickets(ticketAmount.auto(), manualNumbers);
}

int bonusNumber = Integer.parseInt(InputView.getBonusNumber());
WinningNumbers winningNumbers = new WinningNumbers(splitWinningNumbers, bonusNumber);
WinningStatistics winningStatistics = new WinningStatistics(winningNumbers);
public WinningNumbers validateWinningLottoNumbers(String inputWinningNumbers, String inputBonusNumber) {
List<Integer> splitWinningNumbers = StringUtil.splitParseInt(inputWinningNumbers);
int bonusNumber = StringUtil.parseInt(inputBonusNumber);
return new WinningNumbers(splitWinningNumbers, bonusNumber);
}

Map<LottoPrize, Integer> ranks = winningStatistics.groupByWinningNumber(lottoTickets);
OutputView.printWinningStatistics(ranks);

float profitRate = winningStatistics.profitRate(ticketAmount, ranks);
OutputView.printProfitRate(profitRate);
public float calculateProfitRate(int totalTicketAmount, LottoTickets lottoTickets, WinningNumbers winningNumbers) {
WinningLottoRank winningLottoRank = lottoService.getWinningLottoRank(lottoTickets, winningNumbers);
return lottoService.getProfitRate(totalTicketAmount, winningLottoRank);
}
}
28 changes: 0 additions & 28 deletions src/main/java/lotto/domain/LottoGenerator.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/main/java/lotto/domain/LottoNumber.java

This file was deleted.

55 changes: 0 additions & 55 deletions src/main/java/lotto/domain/LottoPrize.java

This file was deleted.

29 changes: 0 additions & 29 deletions src/main/java/lotto/domain/LottoTicket.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/main/java/lotto/domain/LottoTicketVendingMachine.java

This file was deleted.

Loading