Write a calculator that calculates a sum of integers passed in a form of string. It should return a sum represented as a string.
Example input:
"1, 2, 3"
Example output:
"6"
Also, there are two different invalid input types:
1. StringCalculatorFunctional.sum("") -> "Calculation failed"
2. StringCalculatorFunctional.sum("bad input") -> "Calculation failed"
If a string contains integers, but also an element which isn't an integer, sum should be calculated from remaining numbers.
E.g.:
Input: "1, 2, bad input, 3"
Output: "6"
- Develop a helper method with the following signature:
private static Optional<Integer> parseIntHelper(String number); - Convert split string into a stream
- Use map-reduce paradigm:
- APIs for use: