Question: Problem 2 [26 points ] Straight Lines. In this problem, you are asked to implement a class for straight lines called StraightLine. As you know,
![Problem 2 [26 points ] Straight Lines. In this problem, you](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66fa34380aa31_39966fa343788081.jpg)
Problem 2 [26 points ] Straight Lines. In this problem, you are asked to implement a class for straight lines called StraightLine. As you know, a straight line in two dimensions is represented in standard form by the linear equation ax+by=c. In this representation, a is called the x coefficient, b is called the y coefficient, and c is called the constant coefficient. Thus the main instance attributes for straight line objects will be the three coeflicients a,b, and c Implement the following methods for the StraightLine class. Recall once again that self is always the first parameter for a method of the class. Your implementation should appear in a module called problen2.py. A test module called test2.py is also provided, which imports your problem2.py module. When you are ready, test your implementation of the StraightLine class by typing python3 test2.py. 1. _-_init_.: The constructor should create three instance attributes, which are the coelficients a,b, and c of the standard form equation of the line. The parameters to the constructor are initial values for these coefficients. Provide default values for all three attributes. 2. ._str.s: This method returns a printable version of a straight line, which is a "nice" string representation of the linear equation. This means that only non-zero coefficients of x and y should be printed, and if a coefficient is negative, the - (minus sign) must be embedded in the string. For example, the straight line 2x5y=4 should be represented by the following string (note that a=2,b=5, and c=4 for this line): 2x5y=4 and not as 2x+5y=4 Similarly, the straight line 5x=6 should be represented as 5x=6 and not as 5x+0y=6 3. _-repr_: This method returns a meaningful string representation of the straight line. For example, 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 undefined; the method should return None in this case. 5. yintercept: This method returns the y intercept of the line If the line is vertical, then return None (since there is no y intercept for vertical lines). 6. xintercept: This method returns the x intercept of the line. If the line is horizontal, then return None (since there is no x intercept for horizontal lines). 3 7. paralle1: This method has a parameter L which is another StraightLine object. It returns True if the line is parallel to L and False otherwise. 8. perpendicular: This method has a parameter L which is another StraightLine object. It returns True if the line is perpendicular to L and False otherwise. 9. intersection: This method has a parameter L which is another StraightLine object. It returns the point of intersection between the line and L. Return the point as a 2-tuple. If L is parallel to the line, then your function should return None (since tno parallel lines do not intersect). 10. --eq_-: This method overloads 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. 11. _ne_: This method overloads the inequality operator
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
