Practice Practical 2

Instructions

The equation of a line whose slope is m and having y-intercept b is given by . 
Create an instantiable class, either the MyLine or Line API, with instance variables, constructor, and methods as indicated below:

public class MyLine

MyLine ( double x1, double y1, double x2, double y2)

double m                                                                             store the slope of the line

double b                                                                              store the line’s y-intercept

double getM(    )                                                              a public method returning the slope of the line

double  getB()                                                                   a public method returning the y-intercept

String toString()                                                                                String representation                                                      

boolean contains( double x, double y)                   Returns true if the point (x, y)lies on the line and

                                                                                                false otherwise


Use TestMyLine.java as a client to test and demonstrate your work.  A solution

 

 

 

 

 

 

 

public class Line

Line ( Point p1, Point p2)

double m                                                                             store the slope of the line

double b                                                                              store the line’s y-intercept

double getM(    )                                                              a public method returning the slope of the line

double  getB()                                                                   a public method returning the y-intercept

String toString()                                                                                String representation                                                    

boolean contains( Point p)                                           Returns true if the point (x, y)lies on the line and
                                                                                                                                false otherwise


Use TestLine.java as a client to test and demonstrate your work.  A solution