CJCoding With Joseph

Clamp a Property to a Range

Create a class Volume with a private int level. Its Level property returns the field on get, and on set clamps 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 a Main method.

Setting Level to 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.