-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathInventory.java
More file actions
50 lines (34 loc) · 942 Bytes
/
Inventory.java
File metadata and controls
50 lines (34 loc) · 942 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
42
43
44
45
46
47
48
/*
* @author Carlan Henry
*/
public class Inventory {
public static Item inv[] = new Item[10];
public static void addItem(Item item){
for (int i = 0; i < inv.length; i++) {
if(inv[i] == null) {
inv[i] = item;
System.out.println("You have added " + item.toString() + " to the inventory.");
return;
}
}
System.out.println("You have no space in your inventory, please remove an item.");
}
public static void removeItem(Item item) {
Item[] newItems = new Item[inv.length-1];
for (int i = 0; i < inv.length; i++){
if((inv[i].getName() == item.getName())){
inv[i] = newItems[i];
System.out.println("You have removed " + item.toString() + " from the inventory");
return;
}
}
System.out.println("No such item in inventory.");
}
public static void printInv() {
for (Item it : inv) {
if(it != null) {
System.out.print(it.toString() + " | ");
}
}
}
}