Hi, I am with an app and I want to do something. I have the following
structure of the objects:
Invoice class : has some properties and a List<InvoiceProduct>
InvoiceProduct class: has some properties (such as quantity and a Product )
Product class: has some properties of the product.
What I want to do is that when I create an Invoice the value subtotal is in
0. And when I start adding products to the invoice the subtotal value
changes (this is the sum of all products * quantity).
I tried making only a getter on Invoice class like this:
@MemberOrder(sequence = "6")
public double getSubtotal() {
double total = 0;
if(!products.isEmpty()) {
for(InvoiceProduct ip: products) {
total += (ip.getQuantity() * ip.getProduct().getPrice());
}
}
return total;
}
But after adding items, the subtotal remains 0. What am I doing bad?
Thanks
PS: the picture of what i have now http://imgur.com/rNIaPEW