-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathItem.java
More file actions
73 lines (46 loc) · 1.32 KB
/
Item.java
File metadata and controls
73 lines (46 loc) · 1.32 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package ironhack;
public class Item {
private String productId;
private String name;;
private int quantity;
private double price;
public Item(String productId, String name, int quantity, double price) {
if (productId == null) {
throw new IllegalArgumentException("Product ID cannot be null");
}
if (name == null) {
throw new IllegalArgumentException("Name cannot be null");
}
if (quantity < 0) {
throw new IllegalArgumentException("Quantity cannot be negative");
}
if (price < 0) {
throw new IllegalArgumentException("Price cannot be negative");
}
this.productId = productId;
this.name = name;
this.quantity = quantity;
this.price = price;
}
public String getName() {
return name;
}
public String getProductId() {
return productId;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
@Override
public String toString() {
return "Item{" +
"productId='" + productId + '\'' +
", name='" + name + '\'' +
", quantity=" + quantity +
", price=" + price +
'}';
}
}