Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Starter code: Section 2 : The Line class ( 5 pts ) The Line class represents a 2 D line that stores two Point 2

Starter code: Section 2: The Line class (5 pts) The Line class represents a 2D line that stores two Point2D objects and provides the distance between the two points and the slope of the line using the property methods getDistance and get Slope. The constructor of the Point2D class has been provided in the starter code. Methods Type Name float getDistance float getSlope Description Returns the distance between two Point2D objects Returns the slope of the line that passes through the two points Special methods Type Name Description str str bool Line repr eq mul Gets a legible representation of the Line in the form y=me + b Determines if two Line objects are equal Returns a new Line object where each coordinate is multiplied by a positive integer Preconditions: get Distance(self) A property method (behaves like an attribute) that gets the distance between the two Point2D objects that created the Line. The formula to calculate the distance between two points in a two- dimensional space is: d=(x2- xy)2+(y2- y2)2 Returns a float rounded to 3 decimals. To round you can use the round method as round(value, #ofDigits) Output float Returns the distance between the two point objects that pass through the Line getSlope(self) A property method (behaves like an attribute) that gets the slope (gradient) of the Line object. The formula to calculate the slope using two points in a two-dimensional space is: y2-yi m = X2- X1 Returns a float rounded to 3 decimals. To round you can use the round method as round(value, #ofDigits) Output float Returns the slope of the line, float inf float for undefined slope (denominator is zero)Section 2: The Line class Examples: >>> pl - Point2D(-7,-9)>>> P2= Point 2D(1,5.6)>>> line1= Line (p1, p2)>>> line1.getDistance 16.648>>> line1.getslope 1.825 str and repr A special method that provides a legible representation for instances of the Line class. Objects will be represented using the "slope-intercept" equation of the line: y = mx + b To find b, substitute m with the slope and y and x for any of the points and solve for b. b must be rounded to 3 decimals. To round you can use the round method as round(value, #ofDigits) Output str Slope-intercept equation of the line, representation must be adjusted if mor bare 0, or if b is positive negative Undefined' for undefined slope str Examples: >>> P1= Point 2D(-7,-9)>>> P2= Point 2D(1,5.6)>>> line1= Line(p1, p2)>>> line1 y =1.825x +3.775>>> line5=Line(Point 2D(6,48), Point 2D(9,21)>>> lines y =-9.0x +102.0>>> line6-Line(Point2D(2,6), Point 2D(2,3))>>> line6.getDistance 3.0>>> line6.getslope inf >>> line 6 Undefined >>> line 7=Line(Point 2D(6,5), Point2D(9,5))>>> line 7 y =5.0Section 2: The Line class eg A special method that determines if two Line objects are equal. For instances of this class, we will define equality as two lines having the same points. To simplify this method, you could try defining equality in the Point2D class Output bool True if lines have the same points, False otherwise A special method to support the * operator. Returns a new Line object where the x,y attributes of every Point2D object is multiplied by the integer. The only operations allowed are integer*Line and Line" integer, any other non-integer values return None. You will need to override both the "normal" version and the "right side" version to support such operations. Output Line A new Line object where pointl and point2 are multiplied by an integer Examples: >>> p1= Point2D(-7,-9)>>> P2= Point 2D(1,5.6)>>> line1= Line (p1, p2)>>> line2= line1*4>>> isinstance(line2, Line) True >>> line2 y =1.825x +15.1>>> line3=4*line1>>> line 3 y =1.825x +15.1>>> line1==line2 False >>> line3==line2 True >>> line5==9 Falseclass Line: >>> p1= Point 2D(-7,-9)>>> p2= Point 2D(1,5.6)>>> line1= Line (p1, p2)>>> line1.getDistance 16.648>>> line1.gets lope 1.825>>> line 1 y =1.825x +3.775>>> line2= line1*4>>> line2.getDistance 66.592>>> line2.getslope 1.825>>> line 2 y =1.825x +15.1>>> line 1 y =1.825x +3.775>>> line3=4* line1>>> line 3 y =1.825x +15.1>>> line1==line2 False >>> line3==line2 True >>> line5=Line(Point 2D(6,48), Point 2D(9,21))>>> line5 y =-9.0x +102.0>>> line5==9 False >>> line6=Line(Point 2D(2,6), Point 2D(2,3))>>> line.getDistance 3.0>>> line6. gets lope inf >>> line 6 Undefined >>> line 7=Line(Point 2D(6,5), Point 2D(9,5))>>> line 7.getslope 0.0>>> line 7 y =5.0 def __init__(self, pointi, point2): #--- YOUR CODE STARTS HERE pass #--- YOUR CODE STARTS HERE def getDistance(self): pass #--- YOUR CODE STARTS HERE def getslope(self): pass #--- YOUR CODE CONTINUES HERE

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

Step: 3

blur-text-image

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

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions

Question

Whats the difference between the UNION and UNION ALL set operators?

Answered: 1 week ago