Using Python 3 Programming: State a class Rectangle that has three instance vari
ID: 3906066 • Letter: U
Question
Using Python 3 Programming:
State a class Rectangle that has three instance variables: a point (an object of the
class Point previously defined, corresponding to the left bottom corner), a rational
width and a rational height.
Implement in this class a constructor with three arguments, a point and two
rational values, to be assigned to the three instance variables. No default values
should be stated (the constructor must be called with three arguments).
Write a method named perimeter that returns the perimeter of the rectangle.
Write a method named area that returns the area of the rectangle.
Write a method named getOrigin that returns a reference to the point rep-
resenting the left bottom corner of the rectangle.
Write a method named toString that returns a string containing, on the same
line, the string representing the bottom left corner, followed by the rectangle
width and height, formatted as follows (the values will di er depending on
each object):
(0.0,0.0), L=2, H=5.5
The class point previously defined:
Explanation / Answer
Solution:
Sample Run:
(0.0,0.0), L=2, H=5.5
Rectangle's Perimeter is 15.0
Rectangle's Area is 11.0
Rectangle's Origin is (0.0,0.0)
Note: If you have any doubt before giving negative feedback do discuss in comment section. If this really helped you ot then dont forget to give a bug thumbs up.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.