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주차]객체지향 코드 연습(Jungsukwoo) #27

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
0f10b2e
feat: Appconfig 생성
Jungsukwoo Sep 29, 2024
0f3bff6
feat: Controller에 필요한 의존성 주입
Jungsukwoo Sep 29, 2024
aad9909
feat: 로또 구매 메소드 생성
Jungsukwoo Sep 29, 2024
0ab6887
feat: 로또 구매 갯수 파악, repository 저장 기능 구현
Jungsukwoo Sep 29, 2024
c1db8c3
feat: 로또 저장, 저장된 로또 목록 조회 메소드 생성
Jungsukwoo Sep 29, 2024
01e6b20
feat: 로또 저장, 반환 로직 구현
Jungsukwoo Sep 29, 2024
1732633
feat: 랜덤 로또번호 생성 구현
Jungsukwoo Sep 29, 2024
101765e
feat: 당첨 번호 + 보너스 번호 입력 받는 메소드 생성
Jungsukwoo Oct 5, 2024
66b3cc4
feat: 당첨 번호 + 보너스 번호 입력 받는 출력문 추가
Jungsukwoo Oct 5, 2024
0a41997
feat: 당첨 로또번호 입력 및 저장 메소드 기능 구현
Jungsukwoo Oct 5, 2024
b3f1208
feat: 당첨 로또번호 저장 메소드 생성
Jungsukwoo Oct 5, 2024
6acfb65
feat: 랜덤 로또 번호 저장소와 당첨 번호 저장소를 분리하여 저장
Jungsukwoo Oct 5, 2024
f9f43d7
feat: 로또 당첨번호 메소드 생성
Jungsukwoo Oct 5, 2024
3e916f3
feat: 당첨 번호 입력 받을 수 있도록 서비스와 연결, 각 출력되어야 하는 메시지 추가
Jungsukwoo Oct 5, 2024
37e1ece
feat: 예외처리 문구 추가
Jungsukwoo Oct 5, 2024
37285df
feat: 예외처리 문구 추가 outputvew
Jungsukwoo Oct 5, 2024
ed4118b
feat: 금액 잘못 넣었을 때 문구 추가
Jungsukwoo Oct 6, 2024
794e95a
feat: 로또 금액 잘못 넣었을 때 예외처리 로직 및 당첨 번호 잘못 넣었을 때 예외처리 로직 구현
Jungsukwoo Oct 6, 2024
93f171e
feat: 당첨 번호 입력 이후 구매한 로또 갯수+랜덤 번호 출력 메소드 추가
Jungsukwoo Oct 6, 2024
3e6801b
feat: 처음에는 단순히 저장할 메소드로 생각했으나 inputWinningNumbers에서 레파지토리에 저장메소드를 불러왔…
Jungsukwoo Oct 6, 2024
004a334
feat: 모든 구매 로또와 당첨 로또번호를 비교 후 출력 기능 구현
Jungsukwoo Oct 6, 2024
d31c6e2
feat: 최종 결과 값 클래스 생성
Jungsukwoo Oct 6, 2024
e28771d
feat: 6개중 첫번째 당첨 번호 저장 기능
Jungsukwoo Oct 6, 2024
1ed40b4
feat: 6개중 첫번째 당첨 번호 저장 기능
Jungsukwoo Oct 6, 2024
f27b5a4
feat: ErrorMessage 전용 enum 생성
Jungsukwoo Oct 8, 2024
67aacf4
feat: 기존 에러 관련된 output 전부 제거
Jungsukwoo Oct 8, 2024
a9cbd09
feat: 코드 재사용성 및 유지보수성을 위한 상수 선언
Jungsukwoo Oct 8, 2024
f782cba
feat: 가독성을 위해 public 메소드를 상단으로 재배치
Jungsukwoo Oct 8, 2024
fa0b41f
feat: 열거형 에러 메세지 호출
Jungsukwoo Oct 8, 2024
778f4ca
feat: 반복문의 조건을 변수로 선언하여 통제
Jungsukwoo Oct 9, 2024
31aa2d9
feat: 상수 불변성을 위해 final 사용
Jungsukwoo Oct 9, 2024
3449189
feat: 매직넘버를 상수로 선언, Enum으로 바꾼 에러 메시지 호출 메소드 수정
Jungsukwoo Oct 9, 2024
f7bdb02
feat: 중복된 문자열 정리
Jungsukwoo Oct 9, 2024
f789556
feat: 6개중 마지막 저장 번호 반환
Jungsukwoo Oct 9, 2024
81f8e75
feat: while문 변수선언 방식으로 변경
Jungsukwoo Oct 9, 2024
326660d
feat: 오타 수정
Jungsukwoo Oct 9, 2024
6254b9a
feat: 불필요한 static 수정
Jungsukwoo Oct 9, 2024
0e2bc0e
feat: 의존성 주입
Jungsukwoo Oct 9, 2024
632b5d7
feat: 의존성 주입으로 불필요한 객체 선언 수정
Jungsukwoo Oct 9, 2024
88c541c
feat: 로또 출력
Jungsukwoo Oct 9, 2024
22ad9ff
Update README.md and other modified files
Jungsukwoo Oct 9, 2024
4ef3fc3
feat: readme 파일 생성
Jungsukwoo Oct 10, 2024
516dd84
feat: readme 파일 수정
Jungsukwoo Oct 10, 2024
d9d8837
feat: 오타 수정
Jungsukwoo Oct 10, 2024
98a560c
feat: 내용 수정
Jungsukwoo Oct 10, 2024
ae0a4ff
feat: 파일수정
Jungsukwoo 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
36 changes: 36 additions & 0 deletions src/main/java/lotto/AppConfig.java
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppConfig를 통해 의존성을 관리하고 있는 것이 여러 의존 관계를 지닐 로또 미션에서 굉장히 좋은 선택이라는 생각이 듭니다.!
다만 아직까진 AppConfig은 그럼 어디서 생성해주고 관리해야할까요? 이것도 한번 고민해보시면 좋을것 같습니다!

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package lotto;

import lotto.controller.LottoController;
import lotto.repository.LottoRepository;
import lotto.repository.LottoRepositoryImpl;
import lotto.service.LottoService;
import lotto.service.LottoServiceImpl;
import lotto.view.InputView;
import lotto.view.OutputView;

import java.security.Provider;

public class AppConfig {

public InputView inputView() {
return new InputView();
}

public OutputView outputView() {
return new OutputView();
}

// LottoRepository 인스턴스를 생성하는 메서드
public LottoRepository lottoRepository() {
return new LottoRepositoryImpl();
}

public LottoService lottoService() {
return new LottoServiceImpl(lottoRepository());
}

public LottoController lottoController() {
return new LottoController(lottoService(), inputView(), outputView());
}

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

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

public class LottoController {

private final LottoService lottoService;
private final InputView inputView;
private final OutputView outputView;

public LottoController(LottoService lottoService, InputView inputView, OutputView outputView) {
this.lottoService = lottoService;
this.inputView = inputView;
this.outputView = outputView;
}
Comment on lines +13 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 생성자 주입을 사용하셨네요! 좋은 선택인 것 같습니다. 그래도 이유를 알면 좋으니 의존성 주입에는 다양한 방법이 있는데 생성자를 통해 의존성을 주입하신 이유에 대해 설명해주실 수 있을까요??



public void run() {

}
}

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

import lotto.model.Lotto;
import java.util.List;

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

import lotto.model.Lotto;
import java.util.ArrayList;
import java.util.List;

public class LottoRepositoryImpl implements LottoRepository {

private final List<Lotto> lottoStorage = new ArrayList<>();

@Override
public void saveLotto(Lotto lotto) {
lottoStorage.add(lotto);
}

@Override
public List<Lotto> findAllLotto() {
return new ArrayList<>(lottoStorage);
}
}
10 changes: 10 additions & 0 deletions src/main/java/lotto/service/LottoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package lotto.service;

import lotto.model.Lotto;

import java.util.List;

public interface LottoService {
List<Lotto> purchaseLotto(int amount);

}
29 changes: 29 additions & 0 deletions src/main/java/lotto/service/LottoServiceImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package lotto.service;
import camp.nextstep.edu.missionutils.Randoms;
import lotto.model.Lotto;
import lotto.repository.LottoRepository;
import java.util.ArrayList;
import java.util.List;

public class LottoServiceImpl implements LottoService {

private final LottoRepository lottoRepository;

public LottoServiceImpl(LottoRepository lottoRepository) {
this.lottoRepository = lottoRepository;
}

@Override
public List<Lotto> purchaseLotto(int amount) {
int numberOfLotto = amount / 1000;
List<Lotto> purchasedLotto = new ArrayList<>();

for (int i = 0; i < numberOfLotto; i++) {
List<Integer> lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6);
Lotto lotto = new Lotto(lottoNumbers);
purchasedLotto.add(lotto);
}
return purchasedLotto;
}

}