forked from gdsc-konkuk/24-25-study-java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨Refactor : Config를 통한 의존성 주입. Controller를 통한 게임 진행.
- Loading branch information
1 parent
45013be
commit ed887f3
Showing
18 changed files
with
346 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,18 @@ | ||
package lotto; | ||
|
||
import lotto.Producer.LottoProducer; | ||
import lotto.Product.Lotto; | ||
|
||
import java.util.Scanner; | ||
import lotto.config.LottoConfig; | ||
import lotto.controller.LottoController; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
IOSequence io=new IOSequence(new Scanner(System.in)); | ||
User user = new User(); | ||
// 초기 투자금 지정 | ||
user.setPurchaseMoney(io.inputPurchaseMoney()); | ||
Seller seller = new Seller(new LottoProducer()); | ||
// 셀러에게 로또 구매 | ||
user.orderToSeller(seller); | ||
// 구매한 로또 번호 출력 | ||
io.outputLottoList(user.getPurchaseLottoList()); | ||
// 당첨 번호, 보너스 번호 지정해서 객체 생성 | ||
Lotto lt= io.inputWinningLotto(); | ||
int bonusNum = io.inputBonusInt(lt); | ||
LottoGradeCheck lc=new LottoGradeCheck(lt, bonusNum); | ||
// 등수 확인 | ||
user.checkLottoGrade(lc); | ||
// 등수 출력 | ||
io.outputGrade(user.getGradeList()); | ||
// 상금 계산 | ||
user.calculatePrize(); | ||
// 수익률 계산 | ||
user.calculateRateofProfit(); | ||
// 수익률 반환, 출력 | ||
io.outputRateOfProfit(user.getRateofProfit()); | ||
|
||
LottoConfig lottoConfig=new LottoConfig(); | ||
|
||
// config를 통해 controller에 의존성 주입 | ||
LottoController lottoController = lottoConfig.initLottoController(); | ||
|
||
// startGame을 통해 게임 진행 | ||
lottoController.startGame(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package lotto.config; | ||
|
||
|
||
import lotto.controller.LottoController; | ||
import lotto.domain.Seller; | ||
import lotto.domain.producer.LottoProducer; | ||
import lotto.domain.producer.Producer; | ||
import lotto.service.CalculateService; | ||
import lotto.service.DistributeService; | ||
import lotto.service.ValidationService; | ||
import lotto.service.LottoGradeCheckService; | ||
import lotto.service.InputService; | ||
import lotto.view.Output; | ||
|
||
import java.util.Scanner; | ||
|
||
/** | ||
* <h4>로또 프로그램 실행을 위해 의존성 주입</h4> | ||
*/ | ||
public class LottoConfig { | ||
|
||
public LottoController initLottoController() { | ||
Producer producer = getLottoProducer(); | ||
Seller seller = getSeller(producer); | ||
DistributeService distributeService = getDistributeService(seller); | ||
LottoGradeCheckService lottoGradeCheckService = getLottoGradeCheckService(); | ||
InputService inputService = getIOSequence(); | ||
CalculateService calculateService = getCalculateService(); | ||
Output output = getOutput(); | ||
return new LottoController(lottoGradeCheckService, distributeService, inputService, calculateService, output); | ||
} | ||
|
||
private Output getOutput() { | ||
return new Output(); | ||
} | ||
|
||
private static CalculateService getCalculateService() { | ||
return new CalculateService(); | ||
} | ||
|
||
private static InputService getIOSequence() { | ||
return new InputService(getValidationService(), new Scanner(System.in)); | ||
} | ||
|
||
private static DistributeService getDistributeService(Seller seller) { | ||
return new DistributeService(seller); | ||
} | ||
|
||
private static LottoGradeCheckService getLottoGradeCheckService() { | ||
return new LottoGradeCheckService(); | ||
} | ||
|
||
private static ValidationService getValidationService() { | ||
return new ValidationService(); | ||
} | ||
|
||
private Producer getLottoProducer() { | ||
return new LottoProducer(); | ||
} | ||
|
||
private Seller getSeller(Producer producer) { | ||
return new Seller(producer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package lotto.controller; | ||
|
||
import lotto.domain.product.Lotto; | ||
import lotto.domain.product.Product; | ||
import lotto.service.CalculateService; | ||
import lotto.service.DistributeService; | ||
import lotto.service.LottoGradeCheckService; | ||
import lotto.service.InputService; | ||
import lotto.view.Output; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
/** | ||
* <h4>전체적인 프로그램 흐름 제어</h4> | ||
* <br> | ||
* {@link lotto.config.LottoConfig} 를 통해 Controller 객체가 생성된 후, {@link #startGame()} 을 통해 프로그램 진행 | ||
*/ | ||
public class LottoController { | ||
|
||
private final LottoGradeCheckService lottoGradeCheckService; | ||
private final DistributeService distributeService; | ||
private final InputService inputService; | ||
private final CalculateService calculateService; | ||
private final Output output; | ||
|
||
public LottoController(LottoGradeCheckService lottoGradeCheckService, DistributeService distributeService, InputService inputService, CalculateService calculateService, Output output) { | ||
this.lottoGradeCheckService = lottoGradeCheckService; | ||
this.distributeService = distributeService; | ||
this.inputService = inputService; | ||
this.calculateService = calculateService; | ||
this.output = output; | ||
} | ||
|
||
public void startGame(){ | ||
// 초기 투자금 지정 | ||
int purchaseMoney; | ||
try{ | ||
purchaseMoney = inputService.inputPurchaseMoney(); | ||
}catch (IllegalArgumentException e){ | ||
System.out.println("[ERROR]잘못된 입력입니다. 프로그램을 종료합니다."); | ||
return; | ||
} | ||
int purchaseLottoCount= purchaseMoney / 1000; | ||
// 구매 수량으로 Lotto 구매 | ||
List<Product> purchaseProduct = distributeService.orderToSeller(purchaseLottoCount); | ||
List<Lotto> purchaseLottos = new ArrayList<>(); | ||
for (Product product : purchaseProduct) { | ||
purchaseLottos.add((Lotto) product); | ||
} | ||
|
||
// 구매한 로또 번호 출력 | ||
output.outputLottoList(purchaseLottos); | ||
// 당첨 번호, 보너스 번호 지정해서 객체 생성 | ||
Lotto prizeLotto= inputService.inputWinningLotto(); | ||
int bonusNum = inputService.inputBonusInt(prizeLotto); | ||
endGame(purchaseLottos, prizeLotto, bonusNum, purchaseMoney); | ||
} | ||
|
||
private void endGame(List<Lotto> purchaseLottos, Lotto prizeLotto, int bonusNum, int purchaseMoney){ | ||
// 등수 확인 | ||
List<Integer> gradeList=lottoGradeCheckService.checkGrade(prizeLotto,bonusNum,purchaseLottos); | ||
// 등수 출력 | ||
output.outputGrade(gradeList); | ||
// 수익률 계산 | ||
double RateOfProfit = calculateService.calculateRateofProfit(gradeList, purchaseMoney); | ||
// 수익률 반환, 출력 | ||
output.outputRateOfProfit(RateOfProfit); | ||
|
||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/lotto/LottoPrize.java → src/main/java/lotto/domain/LottoPrize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lotto; | ||
package lotto.domain; | ||
|
||
public enum LottoPrize { | ||
FIRST(2_000_000_000.0), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...in/java/lotto/Producer/LottoProducer.java → .../lotto/domain/producer/LottoProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/main/java/lotto/Producer/Producer.java → .../java/lotto/domain/producer/Producer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/lotto/Product/Lotto.java → ...main/java/lotto/domain/product/Lotto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lotto.Product; | ||
package lotto.domain.product; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
2 changes: 1 addition & 1 deletion
2
src/main/java/lotto/Product/Product.java → ...in/java/lotto/domain/product/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package lotto.Product; | ||
package lotto.domain.product; | ||
|
||
public interface Product { | ||
} |
Oops, something went wrong.