Skip to content

Instantly share code, notes, and snippets.

Last active July 13, 2016 10:54
What would you like to do?
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
public class Customer {
private List<Double> drinks = new ArrayList<>();
private Function<Double, Double> billingStrategy;
public Customer(Function<Double, Double> billingStrategy){
public void add(double price, int quantity){
drinks.add(billingStrategy.apply(price * quantity));
public void printBill(){
double sum = 0;
for(Double drink: drinks){
System.out.println("Total Bill : "+sum);
public void setStrategy(Function<Double, Double> billingStrategy){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment