Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
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