Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created May 31, 2019 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/1e07d7962b90cdf16ab20ec7ecccb41d to your computer and use it in GitHub Desktop.
Save jasongorman/1e07d7962b90cdf16ab20ec7ecccb41d to your computer and use it in GitHub Desktop.
public class ShoppingBasket {
private final List<BasketItem> basket = new ArrayList<>();
void addItem(BasketItem basketItem) {
basket.add(basketItem);
}
double total() {
double total = basket.stream()
.mapToDouble(i -> i.getPrice() * i.getQuantity())
.sum();
return total;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment