|
| 1 | +package lotto.model; |
| 2 | + |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | +import java.util.stream.IntStream; |
| 6 | +import lotto.util.DetailErrorMessage; |
| 7 | + |
| 8 | +public class Player { |
| 9 | + final int purchaseMoney; |
| 10 | + int profitMoney; |
| 11 | + List<Lotto> purchasedLottoList; |
| 12 | + |
| 13 | + public static Player setLottoMoney(int purchaseMoney) { |
| 14 | + if (purchaseMoney <= 0) { |
| 15 | + throw new IllegalArgumentException(DetailErrorMessage.ZERO_NEGATIVE.getMessage()); |
| 16 | + } |
| 17 | + if (purchaseMoney % 1000 > 0) { |
| 18 | + throw new IllegalArgumentException(DetailErrorMessage.NOT_MULTIPLE.getMessage()); |
| 19 | + } |
| 20 | + return new Player(purchaseMoney); |
| 21 | + } |
| 22 | + |
| 23 | + Player(int purchaseMoney) { |
| 24 | + this.purchaseMoney = purchaseMoney; |
| 25 | + purchasedLottoList = new ArrayList<>(); |
| 26 | + } |
| 27 | + |
| 28 | + public void buyLotto() { |
| 29 | + int howMuch = purchaseMoney / 1000; |
| 30 | + IntStream.range(0, howMuch).forEach((i) -> { |
| 31 | + purchasedLottoList.add(Lotto.buyNew()); |
| 32 | + }); |
| 33 | + } |
| 34 | + |
| 35 | + public List<Lotto> getPurchasedLottoList() { |
| 36 | + return purchasedLottoList; |
| 37 | + } |
| 38 | + |
| 39 | + public int getPurchasedLottoNum() { |
| 40 | + return purchasedLottoList.size(); |
| 41 | + } |
| 42 | + |
| 43 | + public void setProfitMoney(int profitMoney) { |
| 44 | + this.profitMoney = profitMoney; |
| 45 | + } |
| 46 | + |
| 47 | + public float getProfitPercent() { |
| 48 | + return (float) (profitMoney * 100) / purchaseMoney; |
| 49 | + } |
| 50 | +} |
0 commit comments