Skip to content

Instantly share code, notes, and snippets.

@iyengarajay
Last active July 13, 2016 10:54
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 iyengarajay/ec074f45357b8b5aa4141accbeb3c047 to your computer and use it in GitHub Desktop.
Save iyengarajay/ec074f45357b8b5aa4141accbeb3c047 to your computer and use it in GitHub Desktop.
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