Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

problem 2 PYTHON Problem 2 [36 points ] Straight Lines. In this problem, you are asked to inppetment a cliss fot straight lins called StraightLine,

problem 2
PYTHON
image text in transcribed
Problem 2 [36 points ] Straight Lines. In this problem, you are asked to inppetment a cliss fot straight lins called StraightLine, A strajght line in two dimensonons is repeesented in standard form by the linear equation ax+by=c. In this repscsentation, a is called the x coefficient, b is called the y coefficient, and c is called the constant coefficient. Thas the main instance attributes for straight line objects will be the three confficients a,b, and c Imptement the following methods for the StraightLine class. Feeall onee again that self is always the first parameter for a axethod of the class. Your implementation should appear in at module called problen2.py. A test module called test-straight line.py is also provided, which imports your problen2.py module. When you are ready, test your implenentation of the StraightLine class by typing python3 test streightline, py at the cosnmand line. 1. Init. The constnuctor should ereate three instance attributes, which are the coefficients a0b, and c of the standard form equation of the line. The parameters to the constractor are initial valaes for these coelticients. Provide default values of 1 for all three attributes. 2. atr \& This mothod returas a printubbe version of a straight line, which is a "nice" string representation of the litear equation. This ineans that only non-zero coeflicients of x and y slould be priated, and if a coefticient is negative, the - (minus sign) must be embodded in the string. For example, if a=2,b=5, and c=4 for a straight line, its string representation should be "2x- 2y=4 and not " 2x+5y=4. Sienilarly, if a=5,b=0, and c=6 for a straight line, its string representatiot should be " 5x= 6n and not75x+0y=6n. 3. repr... This method returns a mesuiagful string repesentation of the straight line. For exazople, this could be the same string returned by the ..str -. method. 4. slope: This method returns the slope of the line. If the line is vertical, the slope is umethned and the method should return lione in this case. 5. yintercept: This method returns the y intercept of the line If the line is vertical, then retum None (since there is no y intercept for vertical lines). 6. xintercept: This method retirns the x interoept of the line. If the line is horizontal, then return None (sinee there is no x intereept for borimotal lines). 7. paralle1: This method has a parameter L which is another StraightLine object. It returns Tre if the line is parallel to L and Falee othervise. 8. perpendicular: This method has a parameter L which is atwother Straightline object. It returis True if the line is perpendicular to L and False otherwise 9. internection: This method has a parameter L which is another Straightl.ine object. It returns the point of intersection between the line and L. Return the point as a 2-tuple. If L is paralled to the liae, then your function should return None (since two parallel lines do not intersect). 10. -eq-a This method overhods the equality operator =. We say that two StraightLine objects are equal if and only if they have the same slope and y-intercept. Make sure that your code handles vertical lines correctly; two sertical lines are equal if and oaly if their x-intercepts are equal. 11. ne. _This methoe overkads the inequality operator in

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

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions