CJCoding With Joseph

Validated Rectangle

Build the Rectangle class with two properties Width and Height. Each setter must reject values that are not greater than 0 by storing 1 instead. Also add read-only properties Area (Width times Height) and Perimeter (2 times the sum of Width and Height). The tester prints Area, then Perimeter. Do NOT write a Main method.

For Width = 4 and Height = 5 the program prints:
20
18

If Width is set to -3 it becomes 1, so Width = -3, Height = 5 prints:
5
12

Expected Output:

20
18
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.