Skip to content

๐Ÿš€ 4๋‹จ๊ณ„ - ๋กœ๋˜(์ˆ˜๋™) #4161

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

Open
wants to merge 2 commits into
base: aj172019
Choose a base branch
from
Open
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
Copy link
Member

Choose a reason for hiding this comment

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

์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•˜๊ณ  ์žˆ์ง€ ์•Š๋„ค์š” ๐Ÿ˜ข
image

Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.nextstep.camp.lotto.domain.entity;

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

import com.nextstep.camp.lotto.domain.exception.LottoTicketsCannotBeEmptyException;
import com.nextstep.camp.lotto.domain.type.Rank;
import com.nextstep.camp.lotto.domain.vo.WinningNumbers;

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

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

Expand All @@ -25,6 +26,13 @@ public static LottoTickets of(List<LottoTicket> tickets) {
return new LottoTickets(tickets);
}

public static LottoTickets of(LottoTickets manualTickets, LottoTickets autoTickets) {
List<LottoTicket> allTickets = new ArrayList<>();
allTickets.addAll(manualTickets.getTickets());
allTickets.addAll(autoTickets.getTickets());
return new LottoTickets(allTickets);
}

public int size() {
return tickets.size();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.nextstep.camp.lotto.domain.entity;

import com.nextstep.camp.lotto.domain.type.ProfitType;
import java.util.Map;

import com.nextstep.camp.lotto.domain.type.Rank;
import com.nextstep.camp.lotto.domain.vo.LottoAmount;
import com.nextstep.camp.lotto.domain.vo.RateOfReturn;

import java.util.Map;
import java.util.stream.Collectors;

public class WinningStatistics {
private final Map<Rank, Integer> resultCounts;
private final LottoAmount spent;
Expand Down Expand Up @@ -38,18 +36,4 @@ public Map<Rank, Integer> getResultCounts() {
public LottoAmount getSpent() {
return spent;
}

@Override
public String toString() {
String resultString = resultCounts.entrySet().stream()
.map(entry -> entry.getKey() + " - " + entry.getValue() + "๊ฐœ")
.collect(Collectors.joining("\n"));

RateOfReturn rateOfReturn = calculateRateOfReturn(spent);
ProfitType profitType = rateOfReturn.getProfitType();
return resultString + "\n" +
"์ด ์ˆ˜์ต๋ฅ ์€ " +
rateOfReturn.toString() +
"์ž…๋‹ˆ๋‹ค.(๊ธฐ์ค€์ด 1์ด๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฐ๊ณผ์ ์œผ๋กœ " + profitType.getDescription() + "๋ผ๋Š” ์˜๋ฏธ์ž„)";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.nextstep.camp.lotto.domain.exception;

public class LottoCountCannotBeNegativeException extends RuntimeException {

private static final String MESSAGE = "๋กœ๋˜ ํ‹ฐ์ผ“ ์ˆ˜๋Š” 0๋ณด๋‹ค ์ž‘์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.";

public LottoCountCannotBeNegativeException() {
super(MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.nextstep.camp.lotto.domain.exception;

public class LottoNumberInputRegexException extends IllegalArgumentException {

private static final String MESSAGE = "๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ";

public LottoNumberInputRegexException() {
super(MESSAGE);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.nextstep.camp.lotto.domain.strategy;

import com.nextstep.camp.lotto.domain.entity.LottoTicket;
import com.nextstep.camp.lotto.domain.vo.LottoAmount;

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

import com.nextstep.camp.lotto.domain.entity.LottoTicket;
import com.nextstep.camp.lotto.domain.vo.LottoCount;

public class LottoAutoPicker implements LottoPicker {

private final LottoAmount amount;
private final LottoCount count;

private static final int LOTTO_MIN = 1;
private static final int LOTTO_MAX = 45;
Expand All @@ -19,19 +19,19 @@ public class LottoAutoPicker implements LottoPicker {
.boxed()
.collect(Collectors.toList());

private LottoAutoPicker(LottoAmount amount) {
this.amount = amount;
private LottoAutoPicker(LottoCount count) {
this.count = count;
}

public static LottoAutoPicker of(LottoAmount amount) {
public static LottoAutoPicker of(LottoCount amount) {
return new LottoAutoPicker(amount);
}

@Override
public List<LottoTicket> pick() {
return IntStream.range(0, this.amount.lottoCount())
.mapToObj(i -> LottoTicket.of(generateOne()))
.collect(Collectors.toList());
return this.count.intStream()
.mapToObj(count -> LottoTicket.of(generateOne()))
.collect(Collectors.toList());
}

private List<Integer> generateOne() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public static LottoAmount of(int value) {
return new LottoAmount(value);
}

public int lottoCount() {
return value / LOTTO_PRICE;
}

public int getValue() {
return value;
}

public LottoCount getLottoCount() {
return LottoCount.of(value / LOTTO_PRICE);
}
}
50 changes: 50 additions & 0 deletions src/main/java/com/nextstep/camp/lotto/domain/vo/LottoCount.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.nextstep.camp.lotto.domain.vo;

import java.util.stream.IntStream;

import com.nextstep.camp.lotto.domain.exception.LottoCountCannotBeNegativeException;

public class LottoCount {
private final int value;

private LottoCount(int value) {
validate(value);
this.value = value;
}

private static void validate(int value) {
if (value < 0) {
throw new LottoCountCannotBeNegativeException();
}
}

public static LottoCount of(int intValue) {
return new LottoCount(intValue);
}

public int getCount() {
return value;
}

public IntStream intStream() {
return IntStream.range(0, value);
}
Comment on lines +29 to +31
Copy link
Member

Choose a reason for hiding this comment

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

ํ‰์†Œ์—๋„ ์ŠคํŠธ๋ฆผ์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋กœ์ง์„ ์ž์ฃผ ์‚ฌ์šฉํ•˜์‹œ๋‚˜์š”?
์–ด๋–ค ์žฅ์ ์ด ์žˆ๋‹ค๊ณ  ํŒ๋‹จํ•˜์…จ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.


public LottoCount minus(LottoCount other) {
validateMinus(other);
return LottoCount.of(this.value - other.value);
}
Comment on lines +33 to +36
Copy link
Member

Choose a reason for hiding this comment

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

๋ถˆ๋ณ€ ๊ฐ์ฒด ํ™œ์šฉ ๐Ÿ‘


private void validateMinus(LottoCount other) {
if (this.value < other.value) {
throw new LottoCountCannotBeNegativeException();
}
}

@Override
public String toString() {
return "LottoCount{" +
"count=" + value +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.nextstep.camp.lotto.domain.vo;

import com.nextstep.camp.lotto.domain.exception.LottoNumberOutOfRangeException;

import java.util.Objects;

import com.nextstep.camp.lotto.domain.exception.LottoNumberOutOfRangeException;

public class LottoNumber {
private final int value;

private static final int MIN_VALUE = 1;
private static final int MAX_VALUE = 45;
public static final int MIN_VALUE = 1;
public static final int MAX_VALUE = 45;

private LottoNumber(int value) {
validate(value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.nextstep.camp.lotto.domain.vo;

import java.util.*;
import java.util.stream.Collectors;

import com.nextstep.camp.lotto.domain.exception.LottoNumberDuplicatedException;
import com.nextstep.camp.lotto.domain.exception.LottoNumbersSizeException;

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

public class LottoNumbers {
private final List<LottoNumber> numbers;

private static final int LOTTO_NUMBERS_SIZE = 6;
public static final int LOTTO_NUMBERS_SIZE = 6;

private LottoNumbers(List<Integer> rawNumbers) {
validate(rawNumbers);
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/nextstep/camp/lotto/view/LottoInputView.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.nextstep.camp.lotto.view;

import com.nextstep.camp.lotto.domain.vo.LottoAmount;
import com.nextstep.camp.lotto.view.component.LottoAmountInput;
import com.nextstep.camp.lotto.view.component.LottoTicketsInput;
import com.nextstep.camp.lotto.view.component.WinningNumbersInput;
import com.nextstep.camp.lotto.domain.vo.LottoCount;
import com.nextstep.camp.lotto.view.component.*;
import com.nextstep.camp.lotto.view.dto.LottoInputData;
import com.nextstep.camp.lotto.view.strategy.LottoAmountInputStrategy;
import com.nextstep.camp.lotto.view.strategy.LottoTicketsAutoInputStrategy;
import com.nextstep.camp.lotto.view.strategy.WinningNumbersInputStrategy;
import com.nextstep.camp.lotto.view.strategy.*;

public class LottoInputView {
private final LottoAmountInput lottoAmountInput;
private final LottoManuelCountInput lottoManuelCountInput;
private final WinningNumbersInput winningNumbersInput;

private LottoTicketsInput lottoTicketsInput;
Expand All @@ -19,7 +17,9 @@ public class LottoInputView {
private LottoInputView() {
LottoAmountInput lottoAmountInput = LottoAmountInput.create(LottoAmountInputStrategy.ofSystemIn());
WinningNumbersInput winningNumbersInput = WinningNumbersInput.create(WinningNumbersInputStrategy.of());
LottoManuelCountInput lottoManuelCountInput = LottoManuelCountInput.create(LottoManuelCountInputStrategy.ofSystemIn());
this.lottoAmountInput = lottoAmountInput;
this.lottoManuelCountInput = lottoManuelCountInput;
this.winningNumbersInput = winningNumbersInput;
}

Expand All @@ -29,8 +29,9 @@ public static LottoInputView publish() {

public void render() {
LottoAmount lottoAmount = this.lottoAmountInput.action();
LottoCount lottoManuelCount = this.lottoManuelCountInput.action();

LottoTicketsAutoInputStrategy inputStrategy = LottoTicketsAutoInputStrategy.of(lottoAmount);
LottoTicketsInputStrategy inputStrategy = LottoTicketsInputStrategy.of(lottoAmount, lottoManuelCount);
this.lottoTicketsInput = LottoTicketsInput.create(inputStrategy);
this.lottoTicketsInput.action();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.nextstep.camp.lotto.view.component;

import com.nextstep.camp.common.strategy.InputStrategy;
import com.nextstep.camp.common.view.component.AbstractInput;
import com.nextstep.camp.lotto.domain.vo.LottoCount;

public class LottoManuelCountInput extends AbstractInput<LottoCount> {

private LottoManuelCountInput(InputStrategy<LottoCount> inputStrategy) {
super(inputStrategy);
}

public static LottoManuelCountInput create(InputStrategy<LottoCount> inputStrategy) {
return new LottoManuelCountInput(inputStrategy);
}

@Override
public String getLabel() {
return "\n์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋กœ๋˜ ์ˆ˜๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.nextstep.camp.lotto.view.component;

import com.nextstep.camp.common.strategy.InputStrategy;
import com.nextstep.camp.common.view.component.AbstractInput;
import com.nextstep.camp.lotto.domain.entity.LottoTickets;
import com.nextstep.camp.lotto.domain.vo.LottoCount;

public class LottoTicketsAutoInput extends AbstractInput<LottoTickets> {

private final LottoCount autoCount;
private final LottoCount manualCount;

private LottoTicketsAutoInput(InputStrategy<LottoTickets> inputStrategy, LottoCount autoCount, LottoCount manualCount) {
super(inputStrategy);
this.autoCount = autoCount;
this.manualCount = manualCount;
}

public static LottoTicketsAutoInput create(InputStrategy<LottoTickets> inputStrategy, LottoCount autoCount, LottoCount manualCount) {
return new LottoTicketsAutoInput(inputStrategy, autoCount, manualCount);
}

@Override
public String getLabel() {
return String.format("์ˆ˜๋™์œผ๋กœ %d์žฅ, ์ž๋™์œผ๋กœ %d๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.", manualCount.getCount(), autoCount.getCount());
}

@Override
public LottoTickets action() {
LottoTickets lottoTickets = super.action();
System.out.println(lottoTickets);
return lottoTickets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ public static LottoTicketsInput create(InputStrategy<LottoTickets> inputStrategy

@Override
public String getLabel() {
return "14๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.";
}

@Override
public LottoTickets action() {
LottoTickets lottoTickets = super.action();
System.out.println(lottoTickets);
return lottoTickets;
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.nextstep.camp.lotto.view.component;

import com.nextstep.camp.common.strategy.InputStrategy;
import com.nextstep.camp.common.view.component.AbstractInput;
import com.nextstep.camp.lotto.domain.entity.LottoTickets;

public class LottoTicketsManualInput extends AbstractInput<LottoTickets> {

private LottoTicketsManualInput(InputStrategy<LottoTickets> inputStrategy) {
super(inputStrategy);
}

public static LottoTicketsManualInput create(InputStrategy<LottoTickets> inputStrategy) {
return new LottoTicketsManualInput(inputStrategy);
}

@Override
public String getLabel() {
return "\n์ˆ˜๋™์œผ๋กœ ๊ตฌ๋งคํ•  ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.";
}
}
Loading