|
| 1 | +package lotto.util; |
| 2 | + |
| 3 | +public enum GamePrize { |
| 4 | + PRIZE_5TH(3, 5000, false, 0), |
| 5 | + PRIZE_4TH(4, 50000, false, 1), |
| 6 | + PRIZE_3RD(5, 1500000, false, 2), |
| 7 | + PRIZE_2ND(5, 30000000, true, 3), |
| 8 | + PRIZE_1ST(6, 2000000000, false, 4); |
| 9 | + |
| 10 | + private final int matchingBall; |
| 11 | + private final String formattedPrizeMoney; |
| 12 | + private final int prizeMoney; |
| 13 | + private final boolean isBonus; |
| 14 | + private final int index; |
| 15 | + private final String message; |
| 16 | + |
| 17 | + GamePrize(int matchingBall, int prizeMoney, boolean isBonus, int index) { |
| 18 | + this.matchingBall = matchingBall; |
| 19 | + this.prizeMoney = prizeMoney; |
| 20 | + //아래는 1000을 1,000과 같이 스트링 형식으로 바꾸어줌 |
| 21 | + this.formattedPrizeMoney = String.format("%,d", prizeMoney); |
| 22 | + this.isBonus = isBonus; |
| 23 | + this.index = index; |
| 24 | + this.message = setMessage(); |
| 25 | + } |
| 26 | + |
| 27 | + public String getMessage() { |
| 28 | + return message; |
| 29 | + } |
| 30 | + |
| 31 | + public int getPrizeMoney() { |
| 32 | + return prizeMoney; |
| 33 | + } |
| 34 | + |
| 35 | + public int getIndex() { |
| 36 | + return index; |
| 37 | + } |
| 38 | + |
| 39 | + public String setMessage() { |
| 40 | + StringBuilder message = new StringBuilder(); |
| 41 | + message.append(matchingBall).append("개 일치"); |
| 42 | + if (isBonus) { |
| 43 | + message.append(", 보너스 볼 일치"); |
| 44 | + } |
| 45 | + |
| 46 | + message.append(" "); |
| 47 | + |
| 48 | + message.append("(").append(formattedPrizeMoney).append("원)"); |
| 49 | + message.append(" - "); |
| 50 | + return message.toString(); |
| 51 | + } |
| 52 | +} |
0 commit comments