-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathProduct.java
More file actions
53 lines (42 loc) · 1.37 KB
/
Copy pathProduct.java
File metadata and controls
53 lines (42 loc) · 1.37 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
51
52
53
package vendingmachine.domain;
import vendingmachine.constants.Constants;
public class Product {
private static final int MIN_PRICE = 100;
private static final int PRICE_UNIT = 10;
private String name;
private int price;
private int quantity;
public Product(String name, int price, int quantity) {
this.name = name;
validatePrice(price);
this.price = price;
this.quantity = quantity;
}
private void validatePrice(int price) {
if (price < MIN_PRICE) {
throw new IllegalArgumentException(
String.format("%s 상품 가격은 %d원 이상이어야 합니다.",
Constants.ERROR_PREFIX.getValue(), MIN_PRICE));
}
if (price % PRICE_UNIT != 0) {
throw new IllegalArgumentException(
String.format("%s 상품 가격은 %d원 단위만 가능합니다.",
Constants.ERROR_PREFIX.getValue(), PRICE_UNIT));
}
}
public void decreaseQuantity() {
this.quantity--;
}
public boolean isPriceGreaterThan(int amount) {
return price > amount;
}
public boolean isSoldOut() {
return quantity == 0;
}
public boolean isName(String name) {
return this.name.equals(name);
}
public int getPrice() {
return price;
}
}