-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathItem.java
More file actions
102 lines (93 loc) · 2.73 KB
/
Item.java
File metadata and controls
102 lines (93 loc) · 2.73 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package master1;
/**
* This class is used to represent an item in a shopping center
* @author Jon Spratt
* @version v1_11.20.2016
*/
public class Item extends KeyedItem<String>{
/**
* The name of this item
*/
private String name;
/**
* The re-stocking threshold for this item
*/
private int restockThreshold;
/**
* The current stock quantity for this item
*/
private int currentStock;
/**
* Full argument constructor for an item
* @param name the name to set for this item
* @param restockThreshold the re-stocking threshold to set for this item
* @param currentStock the current stock to set for this item
*/
public Item(String name, int restockThreshold, int currentStock) {
super(name);
this.name = name;
this.restockThreshold = restockThreshold;
this.currentStock = currentStock;
}
/**
* Constructor for item by name and re-stocking threshold.
* Current stock equals zero upon construction
* @param name the name of an item
* @param restockThreshold the re-stocking threshold for an item
*/
public Item(String name, int restockThreshold) {
super(name);
this.name = name;
this.restockThreshold = restockThreshold;
currentStock = 0;
}
/**
* Standard Accessor - for the name of this item
* @return returns the name of this item
*/
public String getName() {
return name;
}
/**
* Standard Accessor - for the re-stocking threshold of this item
* @return returns the re-stocking threshold amount for an item
*/
public int getRestockThreshold() {
return restockThreshold;
}
/**
* Standard Mutator - for the re-stocking threshold of this item
* @param restockThreshold the re-stocking threshold to set for an item
*/
public void setRestockThreshold(int restockThreshold) {
this.restockThreshold = restockThreshold;
}
/**
* Standard Accessor - for the current stock quantity of this item
* @return returns the current stock quantity of this item
*/
public int getCurrentStock() {
return currentStock;
}
/**
* Adjust the current stock quantity
* Can adjust by negative or positive value
* If adjusted by negative value, floor equals 0. You cannot have a negative amount of items
* @param amount the amount to adjust the current stock by
*/
public void adjustCurrentStock(int amount) {
if (currentStock + amount < 0) {
throw new ItemException("No "+name+"s in stock.");
} else {
currentStock += amount;
}
}
/**
* Standard toString method for the items in the collection
*/
public String toString() {
return "\tItem name: " + name +
"\n\tRestocking threshold: " + restockThreshold +
"\n\tCurrent stock: " + currentStock + "\n";
}
}