โ Back to Encapsulation
Question 466
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: 100
Expected Output:
100
Topics:
Encapsulation
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.