Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1a: Extending Geometric Shapes (2 points) Add the method area to the classes Line and Rectangle that returns the area of the given shapes.

image text in transcribedimage text in transcribedimage text in transcribed

Question 1a: Extending Geometric Shapes (2 points) Add the method area to the classes Line and Rectangle that returns the area of the given shapes. The area of a line is always 0 class Shape: def setorigin(self, x, y): self.x, self.y- x, y def move(self, dx, dy): """Move by dx and dy"" self.x, self.y self.x + dx, self.ydy class Line(Shape): def-init--(self, x, y, u, v): "Line with start point (x, y) and end point (u, v)" Shape.setOrigin(self, x, y) self , u, self .v u, v def move(self, dx, dy): Shape.move(self, dx, dy) self , u, self.v self.u + dx, self .v + dy def area (self) pass # Replace this line with your body def str_(self): return "Line from"str(self.x) +", str(self.y) ") to (" str(self.u)", " str(self.v) + ")" class Rectangle(Shape): def _init__(self, x, y, w, h): Rectangle at (x, y) with width w and height h"" Shape.setOrigin(self, x, y) self , w, self . h w, h def area(self) pass # Replace this line with your body def str (self): return "Rectangle at (" str(self.x)", " + str(self.y) "), width"str(self.w) +", height "str(self.h) r Rectangle(-2, -3, 2, 3) 1 = Line(1, 2, 5, 6) str(r) "Rectangle at (-2, -3), width 2, str(1) "Line from (1, 2) to (5, 6)" height 3

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building The Data Warehouse

Authors: W. H. Inmon

4th Edition

0764599445, 978-0764599446

More Books

Students also viewed these Databases questions