-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathInventory.java
More file actions
59 lines (51 loc) · 1.34 KB
/
Inventory.java
File metadata and controls
59 lines (51 loc) · 1.34 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
package com.dtcc.exams.collections;
import java.util.ArrayList;
import java.util.List;
/**
* Use a map to keep track of inventory in a store
*/
public class Inventory {
/**
* @param strings list of strings to add / remove / fetch from
*/
List<String> strings;
Integer itemQuantity;
public Inventory(List<String> strings) {
this.strings=strings;
this.itemQuantity=strings.size();
}
/**
* nullary constructor initializes a new list
*/
public Inventory() {
this(new ArrayList<String>());
}
/**
* @param item - increment the number of this item in stock by 1
*/
public void addItemToInventory(String item) {
this.strings.add(item);
this.itemQuantity=strings.size();
}
/**
* @param item - decrement the number of this item in stock by 1
*/
public void removeItemFromInventory(String item) {
if(strings!=null) {
strings.remove(item);
this.itemQuantity=strings.size();
}
}
public List<String> getStrings() {
return this.strings;
}
/**
* @param item - Search for this item in stock
* @return - return the number of items
*/
public Integer getItemQuantity(String item) {
if(strings.contains(item)){
}
return this.itemQuantity;
}
}