Skip to content

Instantly share code, notes, and snippets.

@nachivpn
Last active July 30, 2017 18:37
Show Gist options
  • Save nachivpn/7ab59c51248c32cb6087a4061b71c9c8 to your computer and use it in GitHub Desktop.
Save nachivpn/7ab59c51248c32cb6087a4061b71c9c8 to your computer and use it in GitHub Desktop.
discountedPrice.java
Double discount;
//apply discount to a given price and return discounted price
public Double discountedPrice(Double originalPrice){
Optional<Double> optionalDiscount = Optional.ofNullable(discount);
return optionalDiscount
.map(discount -> originalPrice - originalPrice * discount)
.orElse(originalPrice);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment