Validation Method Returning Bool
mediumQuestion 581The User class has a private field age. Add SetAge(int value) that stores the value and returns true only when it is between 0 and 120 inclusive; otherwise it leaves age unchanged and returns false. Add GetAge() that returns the stored age. The tester prints the result of SetAge on one line, then the age on the next. Do NOT write a Main method.
For SetAge(25) the program prints the output shown in Expected Output.
For SetAge(-5) the program prints:
False
0
Expected output
True 25
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Encapsulation
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your output
Run your code to see the output here...
Test cases
Run your code to see test case results.