← Back to Encapsulation
Question 586
Validated Rectangle
Validated Rectangle
Build theRectangleclass with two propertiesWidthandHeight. Each setter must reject values that are not greater than 0 by storing 1 instead. Also add read-only propertiesArea(Width times Height) andPerimeter(2 times the sum of Width and Height). The tester printsArea, thenPerimeter. Do NOT write aMainmethod. ForWidth = 4andHeight = 5the program prints the output shown in Expected Output. IfWidthis set to -3 it becomes 1, soWidth = -3,Height = 5prints: 5 12
Expected Output:
20 18
= newline. The output ends with a newline — 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.