package stream;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class StreamExample15 {
    public static void main(String[] args) {
        List<Product> products = Arrays.asList(
                new Product("Laptop", 999.99),
                new Product("Smartphone", 499.99),
                new Product("Tablet", 299.99)
        );

        // 使用 Collectors.summingDouble 计算价格总和
        double totalPrice = products.stream()
                .collect(Collectors.summingDouble(Product::getPrice));

        System.out.println("Total Price: " + totalPrice);
    }

    @Getter
    static
    class Product {
        private final String name;
        @Getter
        private final double price;

        public Product(String name, double price) {
            this.name = name;
            this.price = price;
        }
    }
}
