Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Following the example of the Circle class in our lecture handout, design a class

ID: 3920072 • Letter: F

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 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 i.e. The Rectangle class contains the following .A private int data field named width that defines the width of the rectangle .A private int data field named height that defines the height of the rectangle .A constructor that creates a rectangle with the specified width and height or creates a rectangle with default values (e.g. 1x1). .A get_width method that returns the width of the rectangle .A get height method that returns the height of the rectangle 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

Explanation / Answer

class Rectangle: def __init__(self, w, h): self.__width = w self.__height = h def get_width(self): return self.__width def get_height(self): return self.__height r = Rectangle(3, 4) print(r.get_width(), r.get_height())