CJCoding With Joseph
15free / daySign inCreate account

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 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 — print one after the last line.

Hints4 available
Topics:
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.