package stream;

import lombok.Getter;

import java.util.Arrays;
import java.util.List;

public class StreamExample07 {
    public static void main(String[] args) {
        List<Product> products = Arrays.asList(
                new Product("Apple", 1.20),
                new Product("Banana", 0.80),
                new Product("Orange", 1.00)
        );

        double totalCost = products.stream().mapToDouble(Product::getPrice).sum();

        System.out.println("Total Cost: " + totalCost); // 输出: Total Cost: 3.0
    }

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

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