-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 4단계 로또 수동(#2810) * squash commit Co-authored-by: annelguplus <annelguplus@gmail.com>
- Loading branch information
1 parent
cb97e23
commit 298ad08
Showing
19 changed files
with
444 additions
and
77 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,8 +1,8 @@ | ||
import ui.AutoResultView; | ||
import ui.ManualResultView; | ||
import ui.common.ResultView; | ||
|
||
public class JavaLottoApplication { | ||
public static void main(String... args) { | ||
ResultView.lottoResult(new AutoResultView()); | ||
ResultView.lottoResult(new ManualResultView()); | ||
} | ||
} |
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
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,38 @@ | ||
package domain.lottery; | ||
|
||
import java.util.Objects; | ||
|
||
public class LotteryNumber { | ||
private static final int MIN_NUMBER = 1; | ||
private static final int MAX_NUMBER = 45; | ||
private final int number; | ||
|
||
private LotteryNumber(int number) { | ||
this.number = number; | ||
|
||
if (number < MIN_NUMBER || number > MAX_NUMBER) { | ||
throw new IllegalArgumentException("유효하지 않은 번호입니다."); | ||
} | ||
} | ||
|
||
public static LotteryNumber of(int number) { | ||
return new LotteryNumber(number); | ||
} | ||
|
||
public int number() { | ||
return number; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
LotteryNumber that = (LotteryNumber) o; | ||
return number == that.number; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(number); | ||
} | ||
} |
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,15 +1,33 @@ | ||
package domain.lottery; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class LotteryTicket { | ||
private final List<Integer> ticketNumbers; | ||
private final List<LotteryNumber> ticketNumbers; | ||
|
||
public LotteryTicket(List<Integer> ticketNumbers) { | ||
private static final int COUNT_OF_LOTTERY_NUMBERS = 6; | ||
|
||
private LotteryTicket(List<LotteryNumber> ticketNumbers) { | ||
this.ticketNumbers = ticketNumbers; | ||
|
||
ticketNumbers = ticketNumbers.stream().distinct().collect(Collectors.toList()); | ||
|
||
if (ticketNumbers.size() < COUNT_OF_LOTTERY_NUMBERS) { | ||
throw new IllegalArgumentException("복권번호가 중복됩니다."); | ||
} | ||
} | ||
|
||
public List<Integer> getTicketNumbers() { | ||
public static LotteryTicket of(List<LotteryNumber> ticketNumbers) { | ||
return new LotteryTicket(Optional.ofNullable(ticketNumbers).get()); | ||
} | ||
|
||
public List<LotteryNumber> getTicketNumbers() { | ||
return ticketNumbers; | ||
} | ||
|
||
public void add(LotteryNumber lotteryNumber) { | ||
ticketNumbers.add(lotteryNumber); | ||
} | ||
} |
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
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
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
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
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,74 @@ | ||
package ui; | ||
|
||
import domain.lottery.*; | ||
import service.LotteryService; | ||
import ui.common.InputView; | ||
import ui.common.Result; | ||
import util.Calculator; | ||
import util.Converter; | ||
|
||
import static constant.LotteryRules.DEFAULT_LOTTERY_TICKET_PRICE; | ||
|
||
public class ManualResultView implements Result { | ||
private final String DELIMITER = ", "; | ||
private LotteryTickets lotteryTickets; | ||
private WinnerLotteryTicket winnerLotteryTicket; | ||
private RewardLotteryTickets rewardLotteryTickets; | ||
|
||
@Override | ||
public void printAll() { | ||
LotteryService lotteryService = new LotteryService(); | ||
|
||
printTicketNumbers(); | ||
printLotteryResult(lotteryService); | ||
} | ||
|
||
@Override | ||
public void printTicketNumbers() { | ||
System.out.println("구입금액을 입력해 주세요."); | ||
|
||
long amount = InputView.inputInteger(); | ||
int totalNumberOfLotteryTickets = (int) Calculator.divide(amount, DEFAULT_LOTTERY_TICKET_PRICE); | ||
|
||
System.out.println(); | ||
System.out.println("수동으로 구매할 로또 수를 입력해 주세요."); | ||
int numberOfManualLotteryTickets = InputView.inputInteger(); | ||
|
||
lotteryTickets = new LotteryTickets(totalNumberOfLotteryTickets - numberOfManualLotteryTickets); | ||
|
||
System.out.println(); | ||
System.out.println("수동으로 구매할 번호를 입력해 주세요."); | ||
for (int count = 1; count <= numberOfManualLotteryTickets; count++) { | ||
lotteryTickets.add(Converter.convertStringToLotteryTicket(InputView.inputString().split(DELIMITER))); | ||
} | ||
|
||
System.out.println(); | ||
System.out.println("수동으로 " + numberOfManualLotteryTickets + "장, 자동으로 " + (totalNumberOfLotteryTickets - numberOfManualLotteryTickets) + "개를 구매했습니다."); | ||
for (LotteryTicket lotteryTicket : lotteryTickets.getLotteryTickets()) { | ||
System.out.println(lotteryTicket.getTicketNumbers()); | ||
} | ||
|
||
System.out.println(); | ||
System.out.println("지난 주 당첨 번호를 입력해 주세요."); | ||
LotteryTicket winnerTicket = Converter.convertStringToLotteryTicket(InputView.inputString().split(DELIMITER)); | ||
|
||
System.out.println("보너스 볼을 입력해 주세요."); | ||
int bonusTicketNumber = InputView.inputInteger(); | ||
winnerLotteryTicket = new WinnerLotteryTicket(winnerTicket, LotteryNumber.of(bonusTicketNumber)); | ||
rewardLotteryTickets = new RewardLotteryTickets(lotteryTickets, winnerLotteryTicket); | ||
} | ||
|
||
@Override | ||
public void printLotteryResult(LotteryService lotteryService) { | ||
System.out.println(); | ||
System.out.println("당첨 통계"); | ||
System.out.println("---------"); | ||
|
||
System.out.println("3개 일치 (5000원)- " + lotteryService.countOfLotteryWinners(3, rewardLotteryTickets) + "개"); | ||
System.out.println("4개 일치 (50000원)- " + lotteryService.countOfLotteryWinners(4, rewardLotteryTickets) + "개"); | ||
System.out.println("5개 일치 (1500000원)- " + lotteryService.countOfLotteryWinners(5, rewardLotteryTickets) + "개"); | ||
System.out.println("5개 일치, 보너스 볼 일치(30000000원)- " + lotteryService.countOfLotteryWinners(7, rewardLotteryTickets) + "개"); | ||
System.out.println("6개 일치 (2000000000원)- " + lotteryService.countOfLotteryWinners(6, rewardLotteryTickets) + "개"); | ||
System.out.println("총 수익률은 " + Calculator.rateOfProfit((long) lotteryTickets.getLotteryTickets().size() * DEFAULT_LOTTERY_TICKET_PRICE, lotteryService.findTotalRewards(new RewardLotteryTickets(lotteryTickets, winnerLotteryTicket))) + "입니다.(기준이 1이기 때문에 결과적으로 손해라는 의미임)"); | ||
} | ||
} |
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,17 +1,18 @@ | ||
package util; | ||
|
||
import domain.lottery.LotteryNumber; | ||
import domain.lottery.LotteryTicket; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Converter { | ||
public static LotteryTicket convertStringToLotteryTicket(String[] numbers) { | ||
List<Integer> lotteryTicketNumbers = new ArrayList<>(); | ||
|
||
LotteryTicket lotteryTicket = LotteryTicket.of(new ArrayList<>()); | ||
for (String number : numbers) { | ||
lotteryTicketNumbers.add(Integer.parseInt(number)); | ||
lotteryTicket.add(LotteryNumber.of(Integer.parseInt(number))); | ||
} | ||
|
||
return new LotteryTicket(lotteryTicketNumbers); | ||
return lotteryTicket; | ||
} | ||
} |
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
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
Oops, something went wrong.