Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
19 changes: 12 additions & 7 deletions src/main/java/lotto/LottoGameApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package lotto;

import lotto.domain.game.LottoGame;
import java.util.List;
import lotto.domain.game.LottoMachine;
import lotto.domain.lotto.LottoTickets;
import lotto.domain.lotto.Money;
import lotto.domain.lotto.Purchase;
import lotto.domain.lotto.WinningTicket;
Expand All @@ -15,16 +16,20 @@ public static void main(String[] args) {
LottoMachine machine = new LottoMachine();

int purchaseAmount = InputView.inputPurchaseAmount();
Purchase purchase = machine.purchase(new Money(purchaseAmount));
int manualCount = InputView.inputManualLottoCount();
List<String> manualTickets = InputView.inputManualLottoTickets(manualCount);

Purchase purchase = machine.createPurchase(new Money(purchaseAmount), manualCount);
ResultView.printPurchase(purchase);

LottoTickets tickets = machine.generateTickets(manualTickets, purchase.getAutoCount());
ResultView.printTickets(tickets);

String winningLottoNumbers = InputView.inputWinningLottoNumbers();
int bonusNumber = InputView.inputBonusNumber();
WinningTicket winning = new WinningTicket(winningLottoNumbers, bonusNumber);

LottoGame game = new LottoGame(winning);
GameResult gameResult = game.check(purchase);

ResultView.printResult(gameResult, purchase.getPurchaseAmount());
GameResult result = tickets.match(winning);
ResultView.printResult(result, purchase.getSpentAmount());
}
}
}
54 changes: 31 additions & 23 deletions src/main/java/lotto/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# ๊ธฐ๋Šฅ ์š”๊ตฌ์‚ฌํ•ญ

> ์ž…๋ ฅํ•œ ๊ธˆ์•ก๋งŒํผ ๋กœ๋˜ ์ž๋™์œผ๋กœ ๋ฐœ๊ธ‰ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ
> ์ž…๋ ฅํ•œ ๊ธˆ์•ก๋งŒํผ ๋กœ๋˜๋ฅผ ์ˆ˜๋™/์ž๋™์œผ๋กœ ๋ฐœ๊ธ‰ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ

1. ๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ ๊ธฐ๋Šฅ
2. N๊ฐœ์˜ ๋กœ๋˜ ๊ตฌ๋งค ๊ธฐ๋Šฅ (์ž๋™)
3. ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅ ๊ธฐ๋Šฅ (๋‹น์ฒจ ๋ฒˆํ˜ธ 6๊ฐœ + ๋ณด๋„ˆ์Šค๋ณผ 1๊ฐœ)
4. ๋‹น์ฒจ ํ†ต๊ณ„ ์กฐํšŒ ๊ธฐ๋Šฅ
2. ์ˆ˜๋™ ๊ตฌ๋งค ๋กœ๋˜ ๊ฐœ์ˆ˜ ์ž…๋ ฅ ๊ธฐ๋Šฅ
3. ์ˆ˜๋™ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ ๊ธฐ๋Šฅ
4. N๊ฐœ์˜ ๋กœ๋˜ ๊ตฌ๋งค ๊ธฐ๋Šฅ (์ˆ˜๋™ + ์ž๋™)
5. ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅ ๊ธฐ๋Šฅ (๋‹น์ฒจ ๋ฒˆํ˜ธ 6๊ฐœ + ๋ณด๋„ˆ์Šค๋ณผ 1๊ฐœ)
6. ๋‹น์ฒจ ํ†ต๊ณ„ ์กฐํšŒ ๊ธฐ๋Šฅ
- ๋ช‡ ๊ฐœ์˜ ๋ฒˆํ˜ธ๊ฐ€ ์ผ์น˜ํ•˜๋Š”์ง€, ๋ช‡ ๊ฐœ์ธ์ง€
- ๋ณด๋„ˆ์Šค๋ณผ ์ผ์น˜ ์—ฌ๋ถ€ (5๊ฐœ ์ผ์น˜ ์‹œ)
- ์ˆ˜์ต๋ฅ 
Expand All @@ -17,25 +19,37 @@
- ๋ฌด์—‡์ธ๊ฐ€? : ๊ตฌ๋งค๊ธˆ์— ๋”ฐ๋ผ ๋กœ๋˜๋ฅผ ์ƒ์„ฑํ•ด์ฃผ๋Š” ๋จธ์‹ 
- ์—ญํ• 
- ๋กœ๋˜ ๋ฐœ๊ธ‰ ๊ฐœ์ˆ˜ ๊ณ„์‚ฐ
- ๋žœ๋ค ๋กœ๋˜ ํ‹ฐ์ผ“ ์ƒ์„ฑ
- ์ˆ˜๋™ ๋กœ๋˜ ํ‹ฐ์ผ“ ๋ณ€ํ™˜
- ์ž๋™ ๋กœ๋˜ ํ‹ฐ์ผ“ ์ƒ์„ฑ
- ๊ตฌ๋งค ์ •๋ณด(Purchase) ์ƒ์„ฑ

## ๋กœ๋˜ ํ‹ฐ์ผ“๋“ค (LottoTickets)

- ๋ฌด์—‡์ธ๊ฐ€? : ์—ฌ๋Ÿฌ ๋กœ๋˜ ํ‹ฐ์ผ“์„ ๊ด€๋ฆฌํ•˜๋Š” ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜
- ์—ญํ• 
- ๋กœ๋˜ ํ‹ฐ์ผ“ ๋ชฉ๋ก ๋ณด๊ด€
- ๋‹น์ฒจ ํ‹ฐ์ผ“๊ณผ ๋น„๊ตํ•˜์—ฌ ๊ฒŒ์ž„ ๊ฒฐ๊ณผ ์ƒ์„ฑ

## ๋กœ๋˜ (LottoTicket)

- ๋ฌด์—‡์ธ๊ฐ€? : 6๊ฐœ์˜ ๊ณ ์œ ํ•œ ์ˆซ์ž๋ฅผ ๋‹ด์€ ๋กœ๋˜ ํ‹ฐ์ผ“
- ์—ญํ• 
- 6๊ฐœ์˜ ์ˆซ์ž ๋ณด๊ด€
- ์ผ์น˜ ๊ฐฏ์ˆ˜ ๋น„๊ต
- ๋ฌธ์ž์—ด/์ˆซ์ž ๋ฐฐ์—ด๋กœ๋ถ€ํ„ฐ ํ‹ฐ์ผ“ ์ƒ์„ฑ
- ์ผ์น˜ ๊ฐœ์ˆ˜ ๋น„๊ต
- ํŠน์ • ๋ฒˆํ˜ธ ํฌํ•จ ์—ฌ๋ถ€ ํ™•์ธ

## ๋กœ๋˜ ์ˆซ์ž (LottoNumber)

- ๋ฌด์—‡์ธ๊ฐ€? : ๋กœ๋˜ ๋‚ด ์ˆซ์ž
- ์—ญํ• 
- ๋ฒˆํ˜ธ ์œ ํšจ์„ฑ ๋ณด์žฅ (1 ~ 45)
- ์บ์‹ฑ์„ ํ†ตํ•œ ๊ฐ์ฒด ์žฌ์‚ฌ์šฉ
- ์ˆซ์ž ๊ฐ์ฒด ๋น„๊ต

## ๊ธˆ์•ก (Money)

- ๋ฌด์—‡์ธ๊ฐ€? : ๊ธˆ์•ก์„ ํ‘œํ˜„ํ•˜๋Š” ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜
- ๋ฌด์—‡์ธ๊ฐ€? : ๊ธˆ์•ก์„ ํ‘œํ˜„ํ•˜๋Š” ๊ฐ’ ๊ฐ์ฒด
- ์—ญํ• 
- ๊ธˆ์•ก ์œ ํšจ์„ฑ ๋ณด์žฅ (0 ์ด์ƒ)
- ๊ธˆ์•ก ์—ฐ์‚ฐ (๋ง์…ˆ, ๊ณฑ์…ˆ, ๋‚˜๋ˆ—์…ˆ)
Expand All @@ -45,25 +59,17 @@

- ๋ฌด์—‡์ธ๊ฐ€? : ๋กœ๋˜ ๊ตฌ๋งค ์ •๋ณด๋ฅผ ๋‹ด์€ ๊ฐ์ฒด
- ์—ญํ• 
- ๊ตฌ๋งคํ•œ ๋กœ๋˜ ํ‹ฐ์ผ“ ๋ชฉ๋ก ๊ด€๋ฆฌ
- ํ‹ฐ์ผ“ ๊ฐœ์ˆ˜ ์กฐํšŒ
- ์ˆ˜๋™/์ž๋™ ๊ตฌ๋งค ๊ฐœ์ˆ˜ ๊ด€๋ฆฌ
- ์ด ๊ตฌ๋งค ๊ธˆ์•ก ๊ณ„์‚ฐ
- ์ˆ˜๋™ ๊ตฌ๋งค ์ˆ˜ ์œ ํšจ์„ฑ ๊ฒ€์ฆ

## ๋‹น์ฒจ ํ‹ฐ์ผ“ (WinningTicket)

- ๋ฌด์—‡์ธ๊ฐ€? : ๋‹น์ฒจ ๋ฒˆํ˜ธ 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค๋ณผ 1๊ฐœ๋ฅผ ๋‹ด์€ ํ‹ฐ์ผ“
- ์—ญํ• 
- ๋‹น์ฒจ ๋ฒˆํ˜ธ 6๊ฐœ ๋ณด๊ด€
- ๋ณด๋„ˆ์Šค๋ณผ ๋ณด๊ด€
- ๊ตฌ๋งค ํ‹ฐ์ผ“์˜ ๋ณด๋„ˆ์Šค๋ณผ ํฌํ•จ ์—ฌ๋ถ€ ํ™•์ธ

## ๋กœ๋˜ ๊ฒŒ์ž„ (LottoGame)

- ๋ฌด์—‡์ธ๊ฐ€? : ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๊ตฌ๋งคํ•œ ํ‹ฐ์ผ“๋“ค์„ ๋น„๊ตํ•˜์—ฌ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๊ฐ์ฒด
- ์—ญํ• 
- ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ณด๊ด€
- ๊ตฌ๋งคํ•œ ํ‹ฐ์ผ“๋“ค์˜ ๋‹น์ฒจ ๊ฒฐ๊ณผ ๊ณ„์‚ฐ
- ๊ฒŒ์ž„ ๊ฒฐ๊ณผ ์ƒ์„ฑ
- ๊ตฌ๋งค ํ‹ฐ์ผ“๊ณผ ๋น„๊ตํ•˜์—ฌ ๋“ฑ์ˆ˜(Rank) ๋ฐ˜ํ™˜

## ๋‹น์ฒจ ๋“ฑ์ˆ˜ (Rank)

Expand All @@ -75,12 +81,14 @@

## ๋กœ๋˜ ๊ฒŒ์ž„ ๊ฒฐ๊ณผ (GameResult)

- ๋ฌด์—‡์ธ๊ฐ€? : ์ „์ฒด ๋กœ๋˜ ๊ตฌ๋งค ๊ฒฐ๊ณผ (๋‹น์ฒจ ํ†ต๊ณ„, ์ˆ˜์ต๋ฅ )๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด
- ๋ฌด์—‡์ธ๊ฐ€? : ์ „์ฒด ๋กœ๋˜ ๊ตฌ๋งค ๊ฒฐ๊ณผ (๋‹น์ฒจ ํ†ต๊ณ„)๋ฅผ ๋‚˜ํƒ€๋‚ด๋Š” ๊ฐ์ฒด
- ์—ญํ• 
- ๋“ฑ์ˆ˜๋ณ„ ๋‹น์ฒจ ํ†ต๊ณ„ ๊ด€๋ฆฌ
- ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ (๋‹น์ฒจ ๊ธˆ์•ก / ๊ตฌ์ž… ๊ธˆ์•ก)
- ์†์ต ํŒ์ • (๊ธฐ์ค€: 1.0)


- ์ด ๋‹น์ฒจ ๊ธˆ์•ก ๊ณ„์‚ฐ

## ๋žœ๋ค ๋ฒˆํ˜ธ ์ƒ์„ฑ๊ธฐ (Random)

- ๋ฌด์—‡์ธ๊ฐ€? : ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ๋žœ๋ค์œผ๋กœ ์ƒ์„ฑํ•˜๋Š” ์œ ํ‹ธ๋ฆฌํ‹ฐ
- ์—ญํ• 
- 1~45 ๋ฒ”์œ„์—์„œ ์ค‘๋ณต ์—†์ด 6๊ฐœ ๋ฒˆํ˜ธ ์ƒ์„ฑ
- ์ •๋ ฌ๋œ LottoNumber ๋ฆฌ์ŠคํŠธ ๋ฐ˜ํ™˜
23 changes: 0 additions & 23 deletions src/main/java/lotto/domain/game/LottoGame.java

This file was deleted.

27 changes: 21 additions & 6 deletions src/main/java/lotto/domain/game/LottoMachine.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package lotto.domain.game;

import java.util.ArrayList;
import java.util.List;
import lotto.domain.lotto.LottoTicket;
import lotto.domain.lotto.LottoTickets;
import lotto.domain.lotto.Money;
import lotto.domain.lotto.Purchase;
Expand All @@ -18,16 +21,28 @@ public LottoMachine(Money lottoTicketPrice) {
this.lottoTicketPrice = lottoTicketPrice;
}

public Purchase purchase(Money money) {
return new Purchase(lottoTicketPrice, generateTickets(calculate(money)));
public Purchase createPurchase(Money budget, int manualCount) {
return new Purchase(budget, lottoTicketPrice, manualCount);
}

private int calculate(Money money) {
return money.divideForCount(lottoTicketPrice);
public LottoTickets generateTickets(List<String> manualTickets, int autoCount) {
List<LottoTicket> manual = convert(manualTickets);
List<LottoTicket> auto = generate(autoCount);

List<LottoTicket> allTickets = new ArrayList<>(manual);
allTickets.addAll(auto);
return new LottoTickets(allTickets);
}

LottoTickets generateTickets(int cnt) {
return new LottoTickets(cnt);
private List<LottoTicket> convert(List<String> tickets) {
return tickets.stream().map(LottoTicket::new).toList();
}

private List<LottoTicket> generate(int count) {
List<LottoTicket> tickets = new ArrayList<>();
for (int i = 0; i < count; i++) {
tickets.add(new LottoTicket(Random.generate()));
}
return tickets;
}
}
4 changes: 2 additions & 2 deletions src/main/java/lotto/domain/game/Rank.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public static Rank valueOf(int matched, boolean bonusMatched) {
.orElse(NONE);
}

public int getPrize() {
return prize;
public int calculatePrize(int count) {
return prize * count;
}

private static boolean isMatch(Rank rank, int matched,
Expand Down
29 changes: 5 additions & 24 deletions src/main/java/lotto/domain/lotto/LottoTickets.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,28 @@
package lotto.domain.lotto;

import java.util.ArrayList;
import java.util.List;
import lotto.domain.game.Random;
import lotto.domain.result.GameResult;

public class LottoTickets {
private final List<LottoTicket> tickets;

public LottoTickets(int cnt) {
this(generate(cnt));
}

public LottoTickets(List<LottoTicket> tickets){
this.tickets = tickets;
}

private static List<LottoTicket> generate(int cnt){
List<LottoTicket> tickets = new ArrayList<>();
for (int i = 0; i < cnt; i++) {
tickets.add(new LottoTicket(Random.generate()));
}
return tickets;
}

public Money calculate(Money pricePerTicket) {
return pricePerTicket.multiply(tickets.size());
}

public GameResult updateRank(WinningTicket winningTicket) {
public GameResult match(WinningTicket winning) {
GameResult gameResult = new GameResult();
for(LottoTicket ticket : tickets){
gameResult.updateRank(winningTicket.match(ticket));
gameResult.updateRank(winning.match(ticket));
}
return gameResult;
}

@Override
public String toString(){
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(tickets.size()+"๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.");
for (int i = 0; i < tickets.size(); i++) {
sb.append(tickets.get(i) + "\n");
for (LottoTicket ticket : tickets) {
sb.append(ticket).append("\n");
}
return sb.toString();
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/lotto/domain/lotto/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ public Money multiply(int multiplier) {
return new Money(this.amount.multiply(BigDecimal.valueOf(multiplier)));
}

public BigDecimal divideBy(Money divisor) {
public BigDecimal calculateRatio(Money divisor) {
validateDivisor(divisor);
return this.amount.divide(divisor.amount, 2, RoundingMode.HALF_UP);
}

public int divideForCount(Money divisor) {
validateDivisor(divisor);
return this.amount.divide(divisor.amount, 0, RoundingMode.DOWN).intValue();
public int countUnits(Money unit) {
validateDivisor(unit);
return this.amount.divide(unit.amount, 0, RoundingMode.DOWN).intValue();
}

public boolean isLessThan(Money other) {
return this.amount.compareTo(other.amount) < 0;
}

private void validateDivisor(Money divisor) {
Expand Down
40 changes: 30 additions & 10 deletions src/main/java/lotto/domain/lotto/Purchase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,44 @@

public class Purchase {
Copy link
Contributor

Choose a reason for hiding this comment

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

Money์™€ Purchase์˜ ์ฑ…์ž„๊ณผ ์—ญํ• ์ด ๋ช…ํ™•ํ•˜์ง€ ์•Š๊ณ  ๋‘˜์˜ ์—ญํ• ์ด ์• ๋งคํ•œ ์ธก๋ฉด์ด ์žˆ๋‹ค.
์ด ๋‘ ๊ฐœ์˜ ๊ฐ์ฒด์˜ ์—ญํ• ๊ณผ ์ฑ…์ž„์„ Money์™€ ๊ฐ™์€ ๊ฐ์ฒด ํ•˜๋‚˜๋กœ ํ†ตํ•ฉํ•  ์ˆ˜๋Š” ์—†์„๊นŒ?
์ด ๋‘ ๊ฐ์ฒด์˜ ์—ญํ• ๊ณผ ์ฑ…์ž„์— ๋Œ€ํ•ด ์ •์˜ํ•ด๋ณด๊ณ  AI ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์•„ ํ•˜๋‚˜๋กœ ํ†ตํ•ฉํ•˜๋Š” ๊ฒƒ๊ณผ ํ˜„์žฌ์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์— ๋Œ€ํ•ด ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์•„ ์„ค๊ณ„๋ฅผ ๊ฐœ์„ ํ•  ๋ถ€๋ถ„์„ ์ฐพ์•„๋ณธ๋‹ค.

Copy link
Author

Choose a reason for hiding this comment

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

Money ์™€ Purchase์˜ ์ฑ…์ž„๊ณผ ์—ญํ• 

ํ˜„์žฌ์™€ ๊ฐ™์€ ๊ตฌ์กฐ๋ฅผ ์œ ์ง€

  • ์ฑ…์ž„๊ณผ ์—ญํ• ์ด ๋ชจํ˜ธํ•œ ๋ถ€๋ถ„์ด ์žˆ๋‹ค

  • ์•„๋ž˜์™€ ๊ฐ™์ด ์—ญํ• ๊ณผ ์ฑ…์ž„์„ ์ •์˜ํ•œ๋‹ค๋ฉด?

    • Money: "์–ผ๋งˆ์ธ๊ฐ€?" (๊ธˆ์•ก, VO ์—ญํ• )
    • Purchase: "๋ฌด์—‡์„ ์–ผ๋งˆ๋‚˜ ์ƒ€๋Š”๊ฐ€?" (๊ตฌ๋งค ํ–‰์œ„, ๋„๋ฉ”์ธ ๊ฐ์ฒด)

Purchase

public class Purchase {

  private final Money budget;
  private final Money ticketPrice;
  private final int manualCount;
  private final int autoCount;
  }

๊ตฌ๋งค ๊ด€๋ จ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ํ™•์žฅ์ด ์žˆ๋Š” ๊ฒฝ์šฐ Purchase ๊ฐ์ฒด ๋‚ด์—์„œ ์ฒ˜๋ฆฌ๋  ์ˆ˜ ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด,

  1. ์ž”๋ˆ (๊ฑฐ์Šค๋ฆ„๋ˆ) ๊ธฐ๋Šฅ์ด ์ถ”๊ฐ€๋˜๋Š” ๊ฒฝ์šฐ ์•„๋ž˜์™€ ๊ฐ™์ด ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค.
  public Money getChange() {
      return budget.subtract(getSpentAmount());
  }
  1. ํ‹ฐ์ผ“์„ ์–ผ๋งˆ ์ฃผ๊ณ  ์ƒ€๋Š”์ง€ ๋ณต์‚ฌํ•ด์„œ ๊ฐ€์ง€๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ํ‹ฐ์ผ“ ๊ฐ€๊ฒฉ์ด ๋ณ€๋™๋˜๋Š” ๊ฒฝ์šฐ์— ์˜ํ–ฅ์ด ์—†์Šต๋‹ˆ๋‹ค.

๊ทธ๋ ‡๋‹ค๋ฉด, Money์— ์ถ”๊ฐ€๋  ์ˆ˜ ์žˆ๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง

AI์—๊ฒŒ ๋ฌผ์–ด๋ดค์Šต๋‹ˆ๋‹ค

๋กœ๋˜ ๋„๋ฉ”์ธ์—์„œ

 // 1000์› ๋‹จ์œ„ ๊ฒ€์ฆ (๋กœ๋˜๋Š” 1000์› ๋‹จ์œ„)
  public void validateUnit(int unit) {
      if (this.amount.remainder(BigDecimal.valueOf(unit)) != BigDecimal.ZERO) {
          throw new IllegalArgumentException("1000์› ๋‹จ์œ„๋กœ ์ž…๋ ฅํ•˜์„ธ์š”");
      }
  }

์ผ๋ฐ˜ ์ปค๋จธ์Šค ๋„๋ฉ”์ธ์—์„œ
ํ• ์ธ ์ ์šฉ,์„ธ๊ธˆ ๊ณ„์‚ฐ, ํ†ตํ™” ๋ณ€ํ™˜, ๊ฒฐ์ œ ๊ฐ€๋Šฅ ์—ฌ๋ถ€

์–ด๋ ค์› ๋˜ ์ 

Money ๊ฐ์ฒด์—์„œ

  1. BigDecimal wrapper ๋А๋‚Œ
  public Money add(Money m) { return new Money(amount.add(m.amount)); }
  public Money multiply(int n) { return new Money(amount.multiply(...)); }
  • Money๋งŒ์˜ ๋„๋ฉ”์ธ ๋กœ์ง ์—†์ด BigDecimal ์—ฐ์‚ฐ์„ ๊ฐ์‹ธ๊ธฐ๋งŒ ํ•จ
  1. ๋ฐ˜ํ™˜ ํƒ€์ž… ์ผ๊ด€์„ฑ
  add(Money) โ†’ Money      // โœ… ์ผ๊ด€
  multiply(int) โ†’ Money   // โœ… ์ผ๊ด€
  calculateRatio(Money) โ†’ BigDecimal  // โŒ Money ์•„๋‹˜
  countUnits(Money) โ†’ int             // โŒ Money ์•„๋‹˜
  • "๊ธˆ์•ก / ๊ธˆ์•ก"์˜ ๊ฒฐ๊ณผ๋Š” ๊ธˆ์•ก์ด ์•„๋‹ˆ๋ผ ๋น„์œจ/๊ฐœ์ˆ˜
  1. ๋„๋ฉ”์ธ ๋กœ์ง์˜ ์œ„์น˜
  // Money์— ์žˆ์–ด์•ผ ํ•˜๋‚˜?
  budget.canAfford(ticketPrice)

  // Purchase์— ์žˆ์–ด์•ผ ํ•˜๋‚˜?
  if (budget.isLessThan(ticketPrice)) { ... }
  • canAfford๋Š” "๊ตฌ๋งค ๊ฐ€๋Šฅ ์—ฌ๋ถ€"๋ผ๋Š” ๋„๋ฉ”์ธ ํŒ๋‹จ โ†’ Purchase ์ฑ…์ž„
  • isLessThan์€ "๊ธˆ์•ก ๋น„๊ต"๋ผ๋Š” ๋ฒ”์šฉ ์—ฐ์‚ฐ โ†’ Money ์ฑ…์ž„
  1. ๊ฒฐ๋ก 
Money Purchase
๊ธˆ์•ก ํ‘œํ˜„ (VO) ๊ตฌ๋งค ํ–‰์œ„ (๋„๋ฉ”์ธ ๊ฐ์ฒด)
๋ฒ”์šฉ ์—ฐ์‚ฐ/๋น„๊ต ๋„๋ฉ”์ธ ํŒ๋‹จ/๊ฒ€์ฆ
isLessThan, countUnits "์˜ˆ์‚ฐ์ด ์ถฉ๋ถ„ํ•œ๊ฐ€?"

Copy link
Contributor

Choose a reason for hiding this comment

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

AI์™€ ๋‹ค์Œ์— ๋Œ€ํ•ด์„œ๋„ ๋…ผ์˜ํ•ด ๋ณด๋ฉด ์ข‹๊ฒ ๋„ค์š”.
Money๋Š” ๋‹จ์ˆœํžˆ ๊ฐ’์„ ๊ฐ€์ง€๊ณ , Purchase๊ฐ€ Money ๊ฐ’์— ๋Œ€ํ•œ ํ–‰์œ„๋ฅผ ๋‹ค๋ฃฌ๋‹ค๋ฉด Money ๊ฐ’ ๊ฐ์ฒด๋ฅผ ๋„ˆ๋ฌด ์ˆ˜๋™์ ์ธ ์กด์žฌ๋กœ ๋ฐ”๋ผ๋ณด๋Š” ๋А๋‚Œ์ด ๋“œ๋Š”๋ฐ์š”.
Money ๊ฐ’ ๊ฐ์ฒด๋ฅผ ์ข€ ๋” ๋Šฅ๋™์ ์ธ ๊ฐ์ฒด๋กœ ๋ฐ”๋ผ๋ณธ๋‹ค๋ฉด Purchase์˜ ํ–‰์œ„๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋ถ€๋ถ„๊นŒ์ง€ Money๊ฐ€ ๋‹ด๋‹นํ•˜๋„๋ก ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์€ ์–ด๋–จ๊นŒ์— ๋Œ€ํ•ด์„œ AI ๋Œ€ํ™”๋ฅผ ํ†ตํ•ด ํ”ผ๋“œ๋ฐฑ์„ ๋ฐ›์•„๋ณผ ๊ฒƒ์„ ์ถ”์ฒœํ•ด ๋ด…๋‹ˆ๋‹ค.

Copy link
Author

Choose a reason for hiding this comment

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

2๊ฐ€์ง€ ์ด์œ  ๋•Œ๋ฌธ์— ์•„๋ฌด๋ž˜๋„ ์ด์ „ Money ๊ฐ์ฒด์—์„œ์˜ ์ˆ˜์ต๋ฅ  ๋ฉ”์„œ๋“œ๊ฐ€ ์–ด์ƒ‰ํ–ˆ๋˜ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • Money๋Š” "๊ธˆ์•ก"์ผ ๋ฟ์ธ๋ฐ, "๋กœ๋˜ ์ˆ˜์ต๋ฅ "์ด๋ผ๋Š” ๋„๋ฉ”์ธ ๊ฐœ๋…์„ ์•Œ์•„์•ผ ํ•จ
  • Purchase๊ฐ€ Money์—๊ฒŒ ๋ฌผ์–ด๋ณด๊ณ  ํŒ๋‹จํ•˜๋Š” ์ˆ˜๋™์  ๊ตฌ์กฐ

๋”ฐ๋ผ์„œ, ์•„๋ž˜์™€ ๊ฐ™์ด Purchase ํ•˜๋‚˜๋งŒ ๋‚จ๊ธฐ๋„๋ก ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
Purchase: "๋‚˜๋Š” ๋กœ๋˜ ๊ตฌ๋งค์•ผ. ์–ผ๋งˆ ์ผ๊ณ (์ง€์ถœ), ๋ช‡ ์žฅ ์ƒ€๋Š”์ง€(์ˆ˜๋Ÿ‰) ์•Œ์•„. ๋‹น์ฒจ๊ธˆ์„ ์•Œ๋ ค์ฃผ๋ฉด ์ˆ˜์ต๋ฅ ๋„ ๊ณ„์‚ฐํ•ด์ค„๊ฒŒ"


private final Money pricePerTicket;
private final LottoTickets tickets;
private final Money budget;
private final Money ticketPrice;
private final int manualCount;
private final int autoCount;

public Purchase(Money pricePerTicket, LottoTickets tickets) {
this.pricePerTicket = pricePerTicket;
this.tickets = tickets;
public Purchase(Money budget, Money ticketPrice, int manualCount) {
validateBudget(budget, ticketPrice);
int totalCount = budget.countUnits(ticketPrice);
validateManualCount(manualCount, totalCount);
this.budget = budget;
this.ticketPrice = ticketPrice;
this.manualCount = manualCount;
this.autoCount = totalCount - manualCount;
}

public LottoTickets getTickets(){
return this.tickets;
private static void validateBudget(Money budget, Money ticketPrice) {
if (budget.isLessThan(ticketPrice)) {
throw new IllegalArgumentException("์˜ˆ์‚ฐ์ด ํ‹ฐ์ผ“ ๊ฐ€๊ฒฉ๋ณด๋‹ค ์ ์Šต๋‹ˆ๋‹ค");
}
}

public Money getPurchaseAmount() {
return tickets.calculate(this.pricePerTicket);
private static void validateManualCount(int manualCount, int totalCount) {
if (manualCount > totalCount) {
throw new IllegalArgumentException("์ˆ˜๋™ ๊ตฌ๋งค ์ˆ˜๊ฐ€ ์ด ๊ตฌ๋งค ๊ฐ€๋Šฅ ์ˆ˜๋ฅผ ์ดˆ๊ณผํ•ฉ๋‹ˆ๋‹ค");
}
}

public Money getSpentAmount() {
return ticketPrice.multiply(manualCount + autoCount);
}


public int getAutoCount() {
return autoCount;
}

@Override
public String toString() {
return tickets.toString();
return "์ˆ˜๋™์œผ๋กœ " + manualCount + "์žฅ, ์ž๋™์œผ๋กœ " + autoCount + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.";
}
}
4 changes: 4 additions & 0 deletions src/main/java/lotto/domain/lotto/WinningTicket.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ public WinningTicket(String numbers, int bonus){
}

public WinningTicket(LottoTicket ticket, LottoNumber bonus) {
validate(ticket, bonus);
this.ticket = ticket;
this.bonus = bonus;
}
private static void validate(LottoTicket ticket, LottoNumber bonus){
if(ticket.contains(bonus))throw new IllegalArgumentException("๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ์ค‘๋ณต๋ฉ๋‹ˆ๋‹ค.");

}
public Rank match(LottoTicket ticket) {
return Rank.valueOf(this.ticket.matchCount(ticket), ticket.contains(this.bonus));
}
Expand Down
Loading