-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProduct.java
More file actions
41 lines (33 loc) · 825 Bytes
/
Product.java
File metadata and controls
41 lines (33 loc) · 825 Bytes
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
package myproject;
public class Product {
private String name;
private int stock;
private int sold;
public Product(String name, int stock) {
this.name = name;
this.stock = stock;
this.sold = 0;
}
public String getName() {
return name;
}
public int getStock() {
return stock;
}
public int getSold() {
return sold;
}
public int getRemaining() {
return stock - sold;
}
public void sell(int quantity) {
if (quantity <= getRemaining()) {
sold += quantity;
} else {
System.out.println("Not enough stock to sell " + quantity + " " + name);
}
}
public void restock(int quantity) {
stock += quantity;
}
}