Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2주차] 방현우 객체지향 코드 연습(baaamk) #33

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
202edc7
refactor: 로또 저장 클래스 생성
baaamk Sep 30, 2024
f25afa1
refactor: 로또 저장 클래스 삭제, 배열 사용해 로또 번호 저장
baaamk Sep 30, 2024
aec94ea
refactor: 구현만 완료
baaamk Oct 1, 2024
620166d
refactor: LottoRank Enum으로 구현. LottoService 클래스 생성
baaamk Oct 1, 2024
9779e89
refactor: MVC 패턴 구사 위해 패키지화.
baaamk Oct 2, 2024
5194cd6
refactor: MVC 패턴 구사 위해 패키지화.
baaamk Oct 2, 2024
e6981f8
refactor: Application test파일 이동
baaamk Oct 2, 2024
906539e
refactor: 코드 컨벤션 수정, 매직넘버 수정
baaamk Oct 2, 2024
4627efd
refactor: 제공 라이브러리 사용
baaamk Oct 3, 2024
ba59f4f
refactor: 추상 클래스 생성으로 상수 관리. 수익률 반올림 가능하세 변경.
baaamk Oct 3, 2024
338173c
refactor: Enum으로 예외 변경, OutputMessage 클래스 view 패키지로 이동
baaamk Oct 3, 2024
8250e7d
refactor: LottoRepository 생성, LottoService 생성, 피드백 반영
baaamk Oct 7, 2024
6ca5717
refactor: 패키지명 수정
baaamk Oct 7, 2024
dbe2e6e
refactor: setQuantity 삭제
baaamk Oct 9, 2024
8e5364f
refactor: 로또 WinningImpl 클래스 싱글톤 변경,패키시 생성
baaamk Oct 9, 2024
1406a83
클래스 조직도
baaamk Oct 10, 2024
a503c0d
lotto 클래스 조직도.drawio 추가
baaamk Oct 10, 2024
3c53653
lotto 클래스 조직도.drawio 업데이트
baaamk Oct 10, 2024
7e7456e
Merge branch 'COW-edu:main' into main
baaamk Oct 10, 2024
82f770f
refactor: numbers 전역번수로 변경,
baaamk Oct 10, 2024
7aeb106
refactor: 제공 라이브러리 사용(scanner 변경)
baaamk Oct 10, 2024
1baf846
refactor: 패키지 명 변경
baaamk Oct 10, 2024
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 객체지향 코드 연습 - 로또([우아한테크코스 프리코스 - lotto](https://github.com/woowacourse-precourse/java-lotto))
# 객체지향 코드 연습 - 로또([우아한테크코스 프리코스 - lotto_view](https://github.com/woowacourse-precourse/java-lotto))

## 🔍 진행 방식

Expand Down Expand Up @@ -179,7 +179,7 @@ BUILD SUCCESSFUL in 0s
- Java Enum을 적용한다.
- 도메인 로직에 단위 테스트를 구현해야 한다. 단, UI(System.out, System.in, Scanner) 로직은 제외한다.
- 핵심 로직을 구현하는 코드와 UI를 담당하는 로직을 분리해 구현한다.
- 단위 테스트 작성이 익숙하지 않다면 `test/java/lotto/LottoTest`를 참고하여 학습한 후 테스트를 구현한다.
- 단위 테스트 작성이 익숙하지 않다면 `test/java/lotto_view/LottoTest`를 참고하여 학습한 후 테스트를 구현한다.

### 라이브러리

Expand Down Expand Up @@ -224,7 +224,7 @@ public class Lotto {

## ✏️ 과제 진행 요구 사항

- 미션은 [practice-oop-lotto](https://github.com/COW-edu/practice-oop-lotto) 저장소를 Fork & Clone해 시작한다.
- 미션은 [practice-oop-lotto_view](https://github.com/COW-edu/practice-oop-lotto) 저장소를 Fork & Clone해 시작한다.
- **기능을 구현하기 전 `docs/README.md`에 구현할 기능 목록을 정리**해 추가한다.
- **Git의 커밋 단위는 앞 단계에서 `docs/README.md`에 정리한 기능 목록 단위**로 추가한다.
- [커밋 메시지 컨벤션](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) 가이드를 참고해 커밋 메시지를 작성한다.
7 changes: 7 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Application : 메인 실행 클래스

LottoService : 로또 생성 및 계산

LottoRankENUM 사용) : 당첨 결과 관리

Lotto: 사용자 번호 저장
51 changes: 51 additions & 0 deletions src/main/java/AppConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import lotto_controller.LottoController;
import lotto_controller.LottoControllerImpl;
import lotto_model.comparator.LottoComparator;
import lotto_model.comparator.LottoComparatorImpl;
import lotto_model.data.LottoRepository;
import lotto_model.data.LottoRepositoryImpl;
import lotto_model.data.LottoWinning;
import lotto_model.data.LottoWinningImpl;
import lotto_model.generator.LottoGenerator;
import lotto_model.generator.LottoGeneratorImpl;
import lotto_model.service.LottoService;
import lotto_model.service.LottoServiceImpl;
import lotto_view.LottoInput;
import lotto_view.LottoInputImpl;
import lotto_view.LottoOutput;
import lotto_view.LottoOutputImpl;

public class AppConfig {
public LottoInput lottoInput() {
return new LottoInputImpl();
}

public LottoOutput lottoOutput() {
return new LottoOutputImpl(lottoWinning());
}

public LottoComparator lottoComparator() {
return new LottoComparatorImpl(lottoRepository(), lottoWinning());
}

public LottoGenerator lottoGenerator() {
return new LottoGeneratorImpl(lottoRepository());
}

public LottoRepository lottoRepository() {
return LottoRepositoryImpl.getInstance();
}

public LottoWinning lottoWinning() {
return LottoWinningImpl.getInstance();
}

public LottoService lottoService() {
return new LottoServiceImpl(lottoComparator(), lottoGenerator());
}

public LottoController lottoController() {
return new LottoControllerImpl(lottoInput(), lottoOutput(), lottoService());
}

}
10 changes: 10 additions & 0 deletions src/main/java/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import lotto_controller.LottoController;

public class Application {
public static void main(String[] args) {
AppConfig appConfig = new AppConfig();
LottoController lottoController = appConfig.lottoController();

lottoController.run();
}
}
7 changes: 0 additions & 7 deletions src/main/java/lotto/Application.java

This file was deleted.

20 changes: 0 additions & 20 deletions src/main/java/lotto/Lotto.java

This file was deleted.

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

public interface LottoController {
void run();
}
28 changes: 28 additions & 0 deletions src/main/java/lotto_controller/LottoControllerImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lotto_controller;

import lotto_model.lotto.Lotto;
import lotto_model.service.LottoService;
import lotto_view.LottoInput;
import lotto_view.LottoOutput;

public class LottoControllerImpl implements LottoController {
private final LottoInput lottoInput;
private final LottoOutput lottoOutput;
private final LottoService lottoService;

public LottoControllerImpl(LottoInput lottoInput, LottoOutput lottoOutput, LottoService lottoService) {
this.lottoInput = lottoInput;
this.lottoOutput = lottoOutput;
this.lottoService = lottoService;
}

@Override
public void run() {
int inputMoney = lottoInput.getInputMoney();
lottoService.printLotto(inputMoney);
Lotto targetLotto = lottoInput.inputNumber();
int bonusNumber = lottoInput.getBonusNumber();
lottoService.lottoCompare(targetLotto, bonusNumber);
lottoOutput.resultPrint(inputMoney);
}
}
19 changes: 19 additions & 0 deletions src/main/java/lotto_exception/ErrorMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package lotto_exception;

public enum ErrorMessage {
OUT_OF_RANGE("[ERROR] 1부터 45사이의 숫자를 입력해 주세요."),
DUPLICATE_NUMBER("ERROR] 중복된 숫자가 입력되었습니다."),
OUT_OF_UNIT("[ERROR] 1000원 단위로 입력해 주세요."),
INVALID_NUMBER_COUNT("[ERROR] 6개의 숫자만 입력해주세요."),
NOT_CORRECT_LEVEL("[ERROR] 잘못된 등수가 선정되었습니다");

private final String errorMessage;

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

public String getErrorMessage() {
return errorMessage;
}
}
7 changes: 7 additions & 0 deletions src/main/java/lotto_model/comparator/LottoComparator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lotto_model.comparator;

import lotto_model.lotto.Lotto;

public interface LottoComparator {
void compare(Lotto tragetLotto, int bonusNumber);
}
58 changes: 58 additions & 0 deletions src/main/java/lotto_model/comparator/LottoComparatorImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package lotto_model.comparator;

import lotto_model.data.LottoRepository;
import lotto_model.data.LottoWinning;
import lotto_model.lotto.Lotto;

import java.util.Iterator;

public class LottoComparatorImpl implements LottoComparator {

private final LottoRepository lottoRepository;
private final LottoWinning lottoWinning;

public LottoComparatorImpl(LottoRepository lottoRepository, LottoWinning lottoWinning) {
this.lottoRepository = lottoRepository;
this.lottoWinning = lottoWinning;
}

@Override
public void compare(Lotto tragetLotto, int bonusNumber) {

Iterator<Lotto> lottoNumbers = lottoRepository.getLottoSaved().iterator();

while (lottoNumbers.hasNext()) {
Lotto currentNumber = lottoNumbers.next();
int sameNumbers = 0;

for (Integer element : tragetLotto.getNumbers()) {
if (currentNumber.contains(element)) {
sameNumbers++;
}
}

if (sameNumbers == 6) {
lottoWinning.addFirst();
continue;
}
if (sameNumbers == 5 && currentNumber.contains(bonusNumber)) {
lottoWinning.addSecond();
continue;
}

if (sameNumbers == 5) {
lottoWinning.addThird();
continue;
}

if (sameNumbers == 4) {
lottoWinning.addFourth();
continue;
}

if (sameNumbers == 3) {
lottoWinning.addFifth();
}
}
}
}
10 changes: 10 additions & 0 deletions src/main/java/lotto_model/data/LottoRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lotto_model.data;

import lotto_model.lotto.Lotto;

import java.util.List;

public interface LottoRepository {
List<Lotto> getLottoSaved();
void save(Lotto lotto);
}
30 changes: 30 additions & 0 deletions src/main/java/lotto_model/data/LottoRepositoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lotto_model.data;

import lotto_model.lotto.Lotto;

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

public class LottoRepositoryImpl implements LottoRepository {

private static final LottoRepositoryImpl instance = new LottoRepositoryImpl();
private final List<Lotto> lottoSaved;

private LottoRepositoryImpl() {
lottoSaved = new ArrayList<>();
}

public static LottoRepositoryImpl getInstance() {
return instance;
}

@Override
public List<Lotto> getLottoSaved() {
return lottoSaved;
}

@Override
public void save(Lotto lotto) {
lottoSaved.add(lotto);
}
}
13 changes: 13 additions & 0 deletions src/main/java/lotto_model/data/LottoWinning.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package lotto_model.data;

import lotto_model.lotto.LottoRank;

public interface LottoWinning {
void addFirst();
void addSecond();
void addThird();
void addFourth();
void addFifth();

int getQuantity(LottoRank lottoRank);
}
64 changes: 64 additions & 0 deletions src/main/java/lotto_model/data/LottoWinningImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package lotto_model.data;

import lotto_exception.ErrorMessage;
import lotto_model.lotto.LottoRank;

public class LottoWinningImpl implements LottoWinning {
private final static LottoWinningImpl instance = new LottoWinningImpl();

public static LottoWinningImpl getInstance() {
return instance;
}


private int first = 0;
private int second = 0;
private int third = 0;
private int fourth = 0;
private int fifth = 0;

@Override
public void addFirst() {
first++;
}

@Override
public void addSecond() {
second++;
}

@Override
public void addThird() {
third++;
}

@Override
public void addFourth() {
fourth++;
}

@Override
public void addFifth() {
fifth++;
}

@Override
public int getQuantity(LottoRank lottoRank){
if (lottoRank == LottoRank.FIRST) {
return first;
}
if (lottoRank ==LottoRank.SECOND) {
return second;
}
if (lottoRank == LottoRank.THIRD) {
return third;
}
if (lottoRank == LottoRank.FOURTH) {
return fourth;
}
if (lottoRank == LottoRank.FIFTH) {
return fifth;
}
throw new IllegalArgumentException(ErrorMessage.NOT_CORRECT_LEVEL.getErrorMessage());
}
}
5 changes: 5 additions & 0 deletions src/main/java/lotto_model/generator/LottoGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package lotto_model.generator;

public interface LottoGenerator {
void printLottoSaved(int inputMoney);
}
Loading