CommencerCommencer gratuitement

Calculate total sales

An online store processes daily sales transactions. Each sale amount needs to be increased by 10% tax before calculating the total revenue for financial reporting.

Cet exercice fait partie du cours

Input/Output and Streams in Java

Afficher le cours

Instructions

  • Use .map() to increase each sale amount by 10%.
  • Sum all updated values using .reduce().

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

import java.util.List;

public class SalesCalculator {
    public static void main(String[] args) {
        List sales = List.of(200.0, 450.0, 700.0, 150.0, 300.0);

        double totalSalesAfterTax = sales.stream()
        	// Apply 10% tax increase to each transaction
            .____(amount -> amount * 1.1) 
            // Sum up all the updated sales values.
            .____(0.0, (sum, value) -> ____ + ____);

        System.out.println("Total Sales After Tax: $" + totalSalesAfterTax);
    }
}
Modifier et exécuter le code