Skip to content

Instantly share code, notes, and snippets.

@iyengarajay
Last active July 13, 2016 10:54
Embed
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){
this.billingStrategy=billingStrategy;
}
public void add(double price, int quantity){
drinks.add(billingStrategy.apply(price * quantity));
}
public void printBill(){
double sum = 0;
for(Double drink: drinks){
sum+=drink;
}
System.out.println("Total Bill : "+sum);
}
public void setStrategy(Function<Double, Double> billingStrategy){
this.billingStrategy=billingStrategy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment