Question
Following the example of the Circle class in our lecture handout, design a class named Rectangle to represent a rectangle. A rectangle object stores a
Following the example of the Circle class in our lecture handout, design a class named Rectangle to represent a rectangle.
A rectangle object stores a width attribute and a height attribute. Start by defining a class that is called Rectangle, but which contains exactly three methods. One method should be the special __init__ method, or the constructor method for the class. This constructor method should accept the width and height of the rectangle as inputs, and should store these values in attribute variables called __width and __height respectively. Note that you are required to define the object variables as private data fields of the class. The other two methods are the accessor methods for the private variables, named as get_width and get_height.
Note - keep a copy of your solution to this task because you will be extending it step by step in subsequent tasks.
For example:
Test | Result |
r = Rectangle(3, 4) print(r.get_width(), r.get_height()) | 3 4 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started