I need some help cause I got stuck. I have an ArrayList called orderList with type ItemOrdered(int quantity,Item item). I want to set a new value for item's quantity where the given item exists into ArrayList. I tried everything but didn't work.
//place new order from buyer class
public void placeOrder(int quantity, Item item) {
//ItemOrdered newitemordered = new ItemOrdered(quantity,item );
ShoppingCart shoppingCart = new ShoppingCart();
shoppingCart.addItemOrdered(quantity,item);
}
//call placeOrder method
buyer.placeOrder(quantity,eshop.ItemListPen.get(x));
import java.util.ArrayList;
public class ShoppingCart {
public ArrayList<ItemOrdered> orderList = new ArrayList<ItemOrdered>();
public void addItemOrdered(int quantity,Item item) {
if(item.getStock() >= quantity && (!item.equals(orderList))){
ItemOrdered newitemordered = new ItemOrdered(quantity,item);
orderList.add(new ItemOrdered(quantity,item));
}else if(item.getStock() < quantity){
System.out.println("Sorry,this quantity is not available in stock.");
}else{
orderList.get(item).setQuantity(quantity);
System.out.println("nothing");
}
}
}
public class ItemOrdered {
static Item item;
private int quantity;
public ItemOrdered(int quantity, Item item){
this.quantity=quantity;
this.item=item;
}
public void setQuantity(int x){
quantity=quantity + x;
}
}