forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Product.java
45 lines (36 loc) · 974 Bytes
/
Product.java
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
package onlineshopping;
public class Product {
private final String id;
private final String name;
private final String description;
private final double price;
private int quantity;
public Product(String id, String name, String description, double price, int quantity) {
this.id = id;
this.name = name;
this.description = description;
this.price = price;
this.quantity = quantity;
}
public synchronized void updateQuantity(int quantity) {
this.quantity += quantity;
}
public synchronized boolean isAvailable(int quantity) {
return this.quantity >= quantity;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public double getPrice() {
return price;
}
public int getQuantity() {
return quantity;
}
}