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

import lotto.application.LottoMachine;
import lotto.domain.generator.ShuffleNumberGenerator;
import lotto.ui.InputView;
import lotto.ui.LottoController;
import lotto.ui.ResultView;

public class Application {
public static void main(String[] args) {
LottoMachine machine = new LottoMachine(new ShuffleNumberGenerator());
Expand Down
28 changes: 0 additions & 28 deletions src/main/java/lotto/InputView.java

This file was deleted.

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

This file was deleted.

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

This file was deleted.

28 changes: 0 additions & 28 deletions src/main/java/lotto/ResultView.java

This file was deleted.

16 changes: 0 additions & 16 deletions src/main/java/lotto/ShuffleNumberGenerator.java

This file was deleted.

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

import java.util.List;
import lotto.domain.generator.AutoLottosGenerator;
import lotto.domain.Lotto;
import lotto.domain.generator.CompositeLottosGenerator;
import lotto.domain.generator.LottoNumberGenerator;
import lotto.domain.Lottos;
import lotto.domain.generator.LottosGenerator;
import lotto.domain.generator.ManualLottosGenerator;
import lotto.domain.generator.MixedLottosGenerator;
import lotto.domain.Money;

public class LottoMachine {
private final LottoNumberGenerator numberGenerator;

public LottoMachine(LottoNumberGenerator numberGenerator) {
this.numberGenerator = numberGenerator;
}

public Lottos issue(Money money) {
LottosGenerator auto = new AutoLottosGenerator(money.ticketCount(), numberGenerator);
return auto.generate(); }


public Lottos issue(Money money, List<Lotto> manualLottos) {
int totalCount = money.ticketCount();
int manualCount = manualLottos.size();

if (manualCount > totalCount) {
throw new IllegalArgumentException("수동 로또 개수는 전체 구매 개수보다 클 수 없습니다.");
}

int autoCount = totalCount - manualCount;

LottosGenerator manual = new ManualLottosGenerator(manualLottos);
LottosGenerator auto = new AutoLottosGenerator(autoCount, numberGenerator);

return CompositeLottosGenerator.of(manual, auto).generate();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package lotto;
package lotto.domain;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/lotto/domain/LottoFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package lotto.domain;

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

public class LottoFactory {
public Lottos create(List<List<Integer>> numbers) {
return new Lottos(
numbers.stream()
.map(Lotto::new)
.collect(Collectors.toList())
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package lotto;
package lotto.domain;

import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public class LottoNumber {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package lotto;
package lotto.domain;

import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class Lottos {
private final List<Lotto> values;
Expand All @@ -18,4 +17,10 @@ public List<Lotto> values() {
public int size() {
return values.size();
}

public Lottos merge(Lottos other) {
List<Lotto> merged = new ArrayList<>(this.values);
merged.addAll(other.values);
return new Lottos(merged);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lotto;
package lotto.domain;

public class MatchResult {
private final int matchCount;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lotto;
package lotto.domain;

public class Money {
private static final int UNIT_PRICE = 1_000;
Expand All @@ -14,14 +14,14 @@ public static Money of(int amount) {
return new Money(amount);
}

public int ticketCount() {
return amount / UNIT_PRICE;
}

public int amount() {
return amount;
}

public int ticketCount() {
return amount / UNIT_PRICE;
}

private void validateAmount(int amount) {
if (amount <= 0) {
throw new IllegalArgumentException("구입 금액은 0보다 커야 한다.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package lotto;
package lotto.domain;


import lotto.MatchResult;

public enum Rank {
FIRST(6, false, 2_000_000_000, "6개 일치", 5),
SECOND(5, true, 30_000_000, "5개 일치, 보너스 볼 일치", 4),
Expand Down Expand Up @@ -50,5 +48,4 @@ public int displayOrder() {

public static Rank[] winningRanks() {
return new Rank[]{FIFTH, FOURTH, THIRD, SECOND, FIRST};
}
}
}}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package lotto;
package lotto.domain;


import lotto.MatchResult;

public class WinningNumbers {
private final Lotto winning;
private final LottoNumber bonus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lotto;
package lotto.domain;

import java.util.EnumMap;
import java.util.Map;
Expand All @@ -22,7 +22,10 @@ public long totalPrize() {
return sum;
}

public double profitRate(Money purchase) {
return (double) totalPrize() / purchase.amount();
public double profitRate(Money money) {
if (money.amount() == 0) {
return 0.0;
}
return (totalPrize() * 100.0) / money.amount();
}
}
28 changes: 28 additions & 0 deletions src/main/java/lotto/domain/generator/AutoLottosGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lotto.domain.generator;

import java.util.ArrayList;
import java.util.List;
import lotto.domain.Lotto;
import lotto.domain.Lottos;

public class AutoLottosGenerator implements LottosGenerator {
private final int count;
private final LottoNumberGenerator numberGenerator;

public AutoLottosGenerator(int count, LottoNumberGenerator numberGenerator) {
if (count < 0) {
throw new IllegalArgumentException("자동 로또 개수는 0 이상이어야 합니다.");
}
this.count = count;
this.numberGenerator = numberGenerator;
}

@Override
public Lottos generate() {
List<Lotto> lottos = new ArrayList<>();
for (int i = 0; i < count; i++) {
lottos.add(new Lotto(numberGenerator.generate()));
}
return new Lottos(lottos);
}
}
31 changes: 31 additions & 0 deletions src/main/java/lotto/domain/generator/CompositeLottosGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package lotto.domain.generator;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import lotto.domain.Lotto;
import lotto.domain.Lottos;

public class CompositeLottosGenerator implements LottosGenerator {
private final List<LottosGenerator> children;

public CompositeLottosGenerator(List<LottosGenerator> children) {
if (children == null || children.isEmpty()) {
throw new IllegalArgumentException("children must not be empty");
}
this.children = List.copyOf(children);
}

public static CompositeLottosGenerator of(LottosGenerator... children) {
return new CompositeLottosGenerator(Arrays.asList(children));
}

@Override
public Lottos generate() {
List<Lotto> merged = new ArrayList<>();
for (LottosGenerator child : children) {
merged.addAll(child.generate().values()); // Lottos.values() 필요
}
return new Lottos(merged);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lotto;
package lotto.domain.generator;

import java.util.List;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/lotto/domain/generator/LottosGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package lotto.domain.generator;

import lotto.domain.Lottos;

public interface LottosGenerator {
Lottos generate();
}
Loading