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.
This exercise is part of the course
Input/Output and Streams in Java
Exercise instructions
- Use
.map()
to increase each sale amount by 10%. - Sum all updated values using
.reduce()
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample 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);
}
}