Last active
July 30, 2017 18:37
-
-
Save nachivpn/7ab59c51248c32cb6087a4061b71c9c8 to your computer and use it in GitHub Desktop.
discountedPrice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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