← Back to Encapsulation
Question 556
Clamp a Property to a Range
Clamp a Property to a Range
Create a classVolumewith aprivate int level. ItsLevelproperty returns the field onget, and onsetclamps the incoming value to the range 0 to 100: values below 0 become 0, values above 100 become 100, and any other value is stored as-is. Do not write aMainmethod. SettingLevelto 150 then reading it prints the output shown in Expected Output.
Expected Output:
100= newline. The output ends with a newline — print one after the last line.
Hints3 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.