-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCartTableModel.java
More file actions
68 lines (56 loc) · 2.04 KB
/
Copy pathCartTableModel.java
File metadata and controls
68 lines (56 loc) · 2.04 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
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;
public class CartTableModel extends AbstractTableModel {
private String columnNames[] = {"Product Name", "Number Of Items", "Price"};
ShoppingCart myCart;
int countOfItem;
ArrayList<CartProducts> myTableProductList;
public CartTableModel( ShoppingCart myCart ) {
this.myCart = myCart;
myTableProductList = myCart.getCart();
}
@Override
public int getRowCount() {
return myTableProductList.size();
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public Object getValueAt(int row, int col) {
CartProducts product = myTableProductList.get(row);
if (col == 0) {
if (product.getProduct() instanceof Electronics) {
return product.getProduct().getProductID() + "\n" + ((Electronics) product.getProduct()).getBrandName() + "\n" + ((Electronics) product.getProduct()).getWarrantyPeriod() + " months warranty";
} else if (product.getProduct() instanceof Clothing) {
return product.getProduct().getProductID() + "\n" + ((Clothing) product.getProduct()).getColour() + "\n" + ((Clothing) product.getProduct()).getSize();
}
} else if (col == 1) {
if (myCart != null) {
countOfItem =product.getCount();
//System.out.println("here my count"+countOfItem);
return countOfItem;
}
} else if (col == 2) {
return product.getProduct().getPrice() * countOfItem; // Price
}
return null;
}
@Override
public String getColumnName(int col) {
return columnNames[col];
}
@Override
public Class getColumnClass(int col) {
if (col == 0) {
return String.class;
} else if (col == 1) {
return Integer.class;
} else {
return Double.class;
}
}
}