Question: 2 . Import Class a ) Implement a class Rectangle with two attributes, width and height. b ) Implement an init method with an optional
Import Class a Implement a class Rectangle with two attributes, width and height. b Implement an init method with an optional parameter type. Set the default value of the attributes of width and height to c Implement a display method to print the values of width and height. d Implement a setWidth method to assign width to the instance variable. e Implement a setHeight method to assign height to the instance variable. f Implement a getWidth method to return the value of the instance variable width. g Implement a getHeight method to return the value of the instance variable height. h Implement an area method to return the value of area of a rectangle. i Save Rectangle class as rectangle.py j Import Rectangle class from rectangle.py k Employs the Rectangle class methods above to set and get various measurements of a rectangle. Instantiate two objects of type rectangle, one with arguments one without. r Rectangle r Rectangle Call display to print width and height. Call area in print to display the area of r and r Call setWidth and setHeight to update width and height to of r Call getWidth in print to display the updated width of r Call getHeight in print to display the updated height of r Call area in print to display the area of r Example Output Width: Height: Area:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
