← Back to Encapsulation
Question 581
Validation Method Returning Bool
Validation Method Returning Bool
TheUserclass has a private fieldage. AddSetAge(int value)that stores the value and returnstrueonly when it is between 0 and 120 inclusive; otherwise it leavesageunchanged and returnsfalse. AddGetAge()that returns the stored age. The tester prints the result ofSetAgeon one line, then the age on the next. Do NOT write aMainmethod. ForSetAge(25)the program prints the output shown in Expected Output. ForSetAge(-5)the program prints: False 0
Expected Output:
True 25
= newline. The output ends with a newline — 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.