Skip to content

Commit 5bd2314

Browse files
committed
feat(model): Game&Lotto&Player 구현 #3
1 parent a7daea0 commit 5bd2314

4 files changed

Lines changed: 113 additions & 20 deletions

File tree

src/main/java/lotto/Lotto.java

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package lotto.model;
2+
3+
import java.util.Set;
4+
5+
public class Game {
6+
private Set<Integer> jackpotNumbers;
7+
private Integer bonus;
8+
9+
Game(Set<Integer> jackpotNumbers) {
10+
this.jackpotNumbers = jackpotNumbers;
11+
}
12+
13+
//static factory pattern
14+
public static Game setJackpot(Set<Integer> jackpotNumbers) {
15+
return new Game(jackpotNumbers);
16+
}
17+
18+
public void setBonus(int bonus) {
19+
this.bonus = bonus;
20+
}
21+
22+
public Set<Integer> getJackpotNumbers() {
23+
return jackpotNumbers;
24+
}
25+
26+
public Integer getBonus() {
27+
return bonus;
28+
}
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package lotto.model;
2+
3+
import camp.nextstep.edu.missionutils.Randoms;
4+
import java.util.List;
5+
import lotto.util.Validator;
6+
7+
public class Lotto {
8+
private final List<Integer> numbers;
9+
static final int LOTTO_RANGE_START = 1;
10+
static final int LOTTO_RANGE_END = 45;
11+
static final int LOTTO_BALL_COUNT = 6;
12+
13+
public Lotto(List<Integer> numbers) {
14+
Validator.isLength(numbers.size());
15+
Validator.isListItemDuplicated(numbers);
16+
this.numbers = numbers;
17+
}
18+
19+
public static Lotto buyNew() {
20+
return new Lotto(Randoms.pickUniqueNumbersInRange(LOTTO_RANGE_START, LOTTO_RANGE_END, LOTTO_BALL_COUNT));
21+
}
22+
23+
public List<Integer> getNumbers() {
24+
return numbers;
25+
}
26+
27+
public static int getLottoRangeStart() {
28+
return LOTTO_RANGE_START;
29+
}
30+
31+
public static int getLottoRangeEnd() {
32+
return LOTTO_RANGE_END;
33+
}
34+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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

Comments
 (0)