โ Back to Encapsulation
Question 496
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: 20 18 IfWidthis set to -3 it becomes 1, soWidth = -3,Height = 5prints: 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.