Validated Rectangle
hardQuestion 586Build 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 the output shown in Expected Output.
If Width is set to -3 it becomes 1, so Width = -3, Height = 5 prints:
5
12
Expected output
20 18
= newline. The output ends with a newline, so 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.