-1
I have the attribute valorTotal this value must be represented by the sum of all items in the Item class that are in the list items, I am trying to make the sum of all the items in the list that are Bigdecimal, but when I execute the value is 0, IE, is not calculating, I would like to understand this.
package br.com.improving.carrinho;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
public class CarrinhoCompras {
    private  Collection<Item> items = new ArrayList<Item>();
    private BigDecimal valorTotal = BigDecimal.ZERO;
    public CarrinhoCompras(Item item) {
        items = new ArrayList<Item>();
        items.add(item);
    }
    public CarrinhoCompras() {
    }
    public void adicionarItem(Produto produto, BigDecimal valorUnitario, int quantidade) {
        Item item = new Item(produto, valorUnitario, quantidade);
        if (item != null) {
            items.add(item);
            }
    }
    public void adicionarItem(Item item) {
        if (item != null) {
            items.add(item);
        }
    }   
    public boolean removerItem(Produto produto) {
        Item item = new Item(produto );
            items.remove(item);
        return true;
        /*if(items.stream().anyMatch()
                        if (produto != null) {          
            this.items.remove(produto); 
        */
    }
   public boolean removerItem(int posicaoItem) {
            return true;
            }
    public BigDecimal getValorTotal() {
        items.forEach(item -> this.valorTotal.add(item.getValorTotal()));
        return this.valorTotal;
    }
.
Your question is a bit confused, try to improve it and point out exactly where the problem is giving.
– Pedro Gaspar
I’ve made changes now, I’m sorry!
– Hedgar Bezerra