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

In the language python: (The rectangle class) design a class named rectangle to

ID: 3854493 • Letter: I

Question

In the language python:

(The rectangle class) design a class named rectangle to represent a rectangle. The class contains:

-Two data field named width and height

-a constructor that creates a rectangle with a specified width and height. The default values 1 and 2 for the width and height, respectively

-a method named getArea() that returns the area of this rectangle

-a method named getPerimeter() that returns the perimenter

-Define width and height as private data fields of the class

-Include the public methods getWidth( ) and getHeight( ) in the class

Test these functions with calls from main( ) for the two given data sets

Sample output:     

          A 4 x 40 rectangle has an area of 160 and a perimeter of 88.

All four numbers in bold above should be produced by appropriate function calls to the getter methods of the class.

Repeat the output for the 3.5 x 35.7 rectangle.

have the output print to one decimal place

Create a UML (Unified Modeling Language) diagram for your Rectangle class.

Explanation / Answer

class rectangle:
def __init__(self, height, width):
self.height = height
self.width = width
  
def getWidth(self):
print("The width of the rectangle is: ",self.width)
  
def getHeight(self):
print("The Height of the rectangle is: ",self.height)
  
def getArea(self):
print("The Area of the rectangle is: ",round((self.width * self.height),1))
  
def getPerimeter(self):
print("The Perimeter of the rectangle is: ",round((2*(self.width + self.height)),1))

x = rectangle(4, 40)
x.getHeight()
x.getWidth()
x.getArea()
x.getPerimeter()

y = rectangle(3.5, 35.7)
y.getHeight()
y.getWidth()
y.getArea()
y.getPerimeter()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote