-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPlayer.java
More file actions
50 lines (41 loc) · 1.33 KB
/
Player.java
File metadata and controls
50 lines (41 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package lotto.model;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.IntStream;
import lotto.util.DetailErrorMessage;
public class Player {
final int purchaseMoney;
int profitMoney;
List<Lotto> purchasedLottoList;
public static Player setLottoMoney(int purchaseMoney) {
if (purchaseMoney <= 0) {
throw new IllegalArgumentException(DetailErrorMessage.ZERO_NEGATIVE.getMessage());
}
if (purchaseMoney % 1000 > 0) {
throw new IllegalArgumentException(DetailErrorMessage.NOT_MULTIPLE.getMessage());
}
return new Player(purchaseMoney);
}
Player(int purchaseMoney) {
this.purchaseMoney = purchaseMoney;
purchasedLottoList = new ArrayList<>();
}
public void buyLotto() {
int howMuch = purchaseMoney / 1000;
IntStream.range(0, howMuch).forEach((i) -> {
purchasedLottoList.add(Lotto.buyNew());
});
}
public List<Lotto> getPurchasedLottoList() {
return purchasedLottoList;
}
public int getPurchasedLottoNum() {
return purchasedLottoList.size();
}
public void setProfitMoney(int profitMoney) {
this.profitMoney = profitMoney;
}
public float getProfitPercent() {
return (float) (profitMoney * 100) / purchaseMoney;
}
}