Created
October 19, 2016 08:38
-
-
Save flying3615/a5c61ccf5b987ae88f09c52ac0a140a8 to your computer and use it in GitHub Desktop.
Main for Sale calculator
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
package Java_FP.FP; | |
/** | |
* Created by liuyufei on 18/10/16. | |
*/ | |
public class Example { | |
final static double[] EXPECTED_SALES_JAN_TO_DEC = | |
new double[]{42.0, 45.6, 43.6, 50.2, 55.6, 54.7, | |
58.0, 57.3, 62.0, 60.3, 71.2, 88.8 | |
}; | |
public static void main(String[] args) { | |
final FunctionOverTime sales = | |
FunctionOverTime.monthByMonth(EXPECTED_SALES_JAN_TO_DEC); | |
final FunctionOverTime fixedCost = FunctionOverTime.constant(15.0); | |
final FunctionOverTime incrementalCosts = FunctionOverTime.line(5.1,0.15); | |
//high order function!!! | |
final FunctionOverTime profit = | |
FunctionOverTime.combinationOf3( | |
sales,incrementalCosts,fixedCost, | |
(s,ic,fc) -> s-ic-fc | |
); | |
double total = 0.0; | |
for (int i = 1; i <= 12; i++) { | |
total += profit.valueAt(i); | |
} | |
System.out.println("Total profits for the year: " + total); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment