Yurttas/PL/OOL/Java/F/08/02/01/00/InventoryServant00.java
Jump to navigation
Jump to search
1import Inventory00.*;
2
3import java.util.*;
4
5class InventoryServant00 extends InventoryPOA {
6
7 private Vector catalogItems = new Vector();
8
9 public InventoryServant00() {
10 super();
11 CD cdUnderTable = new CD("Under the Table and Dreaming","Dave Matthews Band");
12 addCatalogItem(new CatalogItem(cdUnderTable,19,2));
13
14 CD cdCrash = new CD("Crash","Dave Matthews Band");
15 addCatalogItem( new CatalogItem(cdCrash,15,3));
16
17 CD cdMMBT = new CD("Don't Know How To Party","Dave Matthews Band");
18 addCatalogItem(new CatalogItem(cdMMBT,14.5,1));
19 }
20
21 public void addCatalogItem(Inventory00.CatalogItem inItem) {
22 if(!catalogItems.contains(inItem)) {
23 catalogItems.addElement(inItem);
24 System.out.println("Added item : " + inItem.aCD.title);
25 }
26 else
27 System.out.println("Store already contains :" + inItem);
28 }
29
30 public boolean inInventory(Inventory00.CatalogItem inItem) {
31 return catalogItems.contains(inItem);
32 }
33
34 public Inventory00.CatalogItem[] getCatalogItems() {
35 Inventory00.CatalogItem[] catalogItemsArray = new Inventory00.CatalogItem[catalogItems.size()];
36 catalogItems.copyInto(catalogItemsArray);
37 return catalogItemsArray;
38 }
39
40 public int getQuantityInInventory(Inventory00.CatalogItem inItem) {
41 CatalogItem item = null;
42 if(catalogItems.contains(inItem)) {
43 int index = catalogItems.indexOf(inItem);
44 item = (CatalogItem) catalogItems.elementAt(index);
45 System.out.println("Quantity : " + item.quantity);
46 return item.quantity;
47 }
48 else {
49 System.out.println("Item not found\n");
50 return 0;
51 }
52 }
53
54 public Inventory00.CatalogItem[] catalogItemsArray() {
55 return getCatalogItems();
56 }
57
58}