Write a generic class Result<T> that holds either a value or an error message:
- a private constructor and two static generic factory methods,
Result.ok(value)andResult.fail(message); isOk(),get()(throwsIllegalStateExceptionon an error),getOrElse(T fallback),getError(), andtoString()→Ok(21)orError(…).
In ResultApp, write Result<Integer> parseAge(String) (errors: 'abc' is not a number, 200 is not a valid age; valid ages are 0–130) and Result<String> initial(String name) (the first letter in upper case; error '42' is not a name if the name does not start with a letter). main reads name age pairs and prints a line per pair, then how many ages were valid and their average.
For the input
Lina 21 omar 19 42 30 Mei abc Ana 200
the program prints
Lina: initial Ok(L), age Ok(21), used: L/21
omar: initial Ok(O), age Ok(19), used: O/19
42: initial Error('42' is not a name), age Ok(30), used: ?/30
Mei: initial Ok(M), age Error('abc' is not a number), used: M/-1
Ana: initial Ok(A), age Error(200 is not a valid age), used: A/-1
Valid ages: 3 of 5, average 23