I am creating a POS program as a requirement in one of my major class and I am having a hard time finding out if I missed something. So, I will be very thankful for any help you can give. I am trying to add object that has constructor in a LinkedList for every button press.
This is my handler class (that I expected to add objects in the LinkedList but ended up not working):
import java.util.Iterator;
import java.util.LinkedList;
import javax.swing.JLabel;
public class Handler {
LinkedList<ProductInfo> productList= new LinkedList<ProductInfo>();
Iterator iterator = productList.iterator();
public void tick(){
for(int i = 0; i<productList.size();i++){
ProductInfo tempProduct = productList.get(i);
tempProduct.tick();
}
}
public void addProduct(ProductInfo product){
this.productList.add(product);
}
public void removeProdcut(ProductInfo product){
this.productList.remove(product);
}
}
And this is the object class:
import javax.swing.*;
public abstract class ProductInfo {
protected String productName;
protected int productID;
protected String variant;
protected char size;
protected double unitPrice;
protected int quantity;
public ProductInfo(String productName, int productID, String variant, char size, double unitPrice){
this.productName = productName;
this.productID = productID;
this.variant = variant;
this.size = size;
this.unitPrice = unitPrice;
this.quantity = quantity;
}
public abstract void tick();
public void setProductName(String productName){
this.productName = productName;
}
public String getProductName(){
return productName;
}
public void setProductID(int productID){
this.productID = productID;
}
public int getProductID(){
return productID;
}
public void setVariant(String variant){
this.variant = variant;
}
public String getVariant(){
return variant;
}
public void setSize(char size){
this.size = size;
}
public char getSize(){
return size;
}
}
Oh, and I created another class that extends my ProductInfo class.
And this is the button listener:
public void actionPerformed(ActionEvent e){
if(e.getSource()==coconutPie){
handler.addProduct(new Product("Pastry", 101, "Coconut Cream Pie",'M',129.99));
}
}