Calculating total price
<p>I have an abstract class <code>Transaction</code>, where I would like to calculate total price of each <code>Transaction</code>. The total price is calculated by getting the price of each <code>Product</code> in <code>Map</code> and then multiply that price by quantity of each <code>Product</code>. I just don't know how to multiply these prices by quantities which are as values in the <code>Map</code>. Can anyone help me, please? I tried almost everything and nothing works.</p>

<pre><code>public abstract class Transaction
{
    //Attributes
    ...

    //Links

    Map&lt;Product,Integer&gt; products;

    //Constructor

    Transaction()
    {
        id = newTrId.incrementAndGet();
        date = new Date();
        products = new HashMap&lt;&gt;();
    }

    abstract void addProduct(Product aProduct, int aQuantity);


    BigDecimal calculateTotal()
    {
        BigDecimal total = new BigDecimal(0);

        for(Product eachProduct : products.keySet())
        {
            total.add(eachProduct.getPrice());
        }
        for (Integer eachProduct : products.values())
        {

        }

        return total;
    }
}
</code></pre>