Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created May 31, 2019 08:45
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/1e4a4fffa7ea76983ea8661e88c391fa to your computer and use it in GitHub Desktop.
Save jasongorman/1e4a4fffa7ea76983ea8661e88c391fa to your computer and use it in GitHub Desktop.
public class ShoppingBasket {
private final List<Object[]> basket = new ArrayList<>();
void addItem(String productCode, String productDescription, double price, int quantity) {
Object[] item = new Object[] {
productCode ,
productDescription ,
price ,
quantity
};
basket.add(item);
}
double total() {
double total = basket.stream()
.mapToDouble(i -> (double)i[ShoppingCartTest.PRICE] * (int)i[ShoppingCartTest.QUANTITY])
.sum();
return total;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment