01: package myapp;
02:
03: import java.util.Vector;
04:
05: public class Category {
06: private int _id;
07:
08: private Vector _products = new Vector();
09:
10: private String _name;
11:
12: public int getId() {
13: return _id;
14: }
15:
16: public void setId(int id) {
17: _id = id;
18: }
19:
20: public String getName() {
21: return _name;
22: }
23:
24: public void setName(String name) {
25: _name = name;
26: }
27:
28: //public Enumeration getProducts()
29: public Vector getProducts() {
30: return _products;
31: // return _products.elements();
32: }
33:
34: public void addProduct(Product product) {
35: if (!_products.contains(product)) {
36: System.out.println("Adding product " + product
37: + " to category " + this );
38: _products.addElement(product);
39: product.addCategories(this );
40: }
41: }
42:
43: public String toString() {
44: return "<id: " + _id + " name: " + _name + ">";
45: }
46:
47: }
|