Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class called line to hold two X,Y coordinate pairs. Since two coordinat

ID: 3911679 • Letter: C

Question

Create a class called line to hold two X,Y coordinate pairs.

Since two coordinate pairs can describe a line solve the standard y = mx + bequation for slope and y-intercept (b).

? Create two constructors for this line. One an empty one and one the takes are the parameter

Create a mutator function that will allow the user to update the parameters of the line class.

? Create a method to calculate and return the slope.

? Create a method to calculate and return the y-intercept.

? Create a method to determine if the line is vertical. It should

? Create a method to determine if the line is horizontal . It

? Create a method to display the parameters of the line.

Finally, treating these coordinate pairs as the lower and upper

Explanation / Answer

import java.io.*;
import java.util.*;
class Line
{
double x1,x2,y1,y2,m;
Line()
{}
Line(double x1,double y1,double x2,double y2)
{
this.x1=x1;
this.y1=y1;
this.x2=x2;
this.y2=y2;
}
public void mutator(double x1,double y1,double x2,double y2)
{
this.x1=x1;
this.y1=y1;
this.x2=x2;
this.y2=y2;
}
public double slope()
{
m=(y2-y1)/(x2-x1);
return m;
}
public boolean vertical()
{
if(x2-x1==0.0)
return true;
return false;
}
public boolean horizontal()
{
if(y2-y1==0.0)
return true;
return false;
}
public void display()
{
if(vertical())
System.out.println("a="+x1+"b=0.0");
else if(horizontal())
System.out.println("a=0.0"+"b="+y1);
else
{
double b=y1-(m*x1);
double a=b/m;
System.out.println("a="+a+"b="+b);
}
}
public static void main()
{
double area=0.0;
Line l=new Line(10,20,12,34);
if(l.vertical() || l.horizontal())
area=0.0;
else
{
slope();
area=((y1-(m*x1))*(y1-(m*x1)))/m;
}
System.out.println(area);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote