Question
if i have this code: (how can i implemment a new method called pointIsOntheLine This method is called to find if the specified Point lies
if i have this code: (how can i implemment a new method called pointIsOntheLine
This method is called to find if the specified Point lies on 'this' line.
Parameters:
p - The point we are checking to see if it lies on the 'this' line.
Returns:
Returns true if the specified Point lies on 'this' line. Returns false otherwise.
code: public class Line { private double slope; private double yIntercept;
public Line(double slope, double yIntercept) { super(); this.slope = slope; this.yIntercept = yIntercept; }
public Line(Point p1, Point p2) { double dy = p2.getY() - p1.getY(); double dx = p2.getX() - p1.getX();
this.slope = dy / dx; this.yIntercept = p1.getY() - (this.slope * p1.getX()); }
// slope getters and setters public double getSlope() { return this.slope; }
public void setSlope(double slope) { this.slope = slope; return; }
// Getters and setters yIntercept public double getyIntercept() { return this.yIntercept; }
public void setyIntercept(double yIntercept) { this.yIntercept = yIntercept; return; }
// Is parallel to public boolean isParallelTo(Line Line) { boolean answer = false; if ((this.getSlope() == Line.getSlope()) && (this.getyIntercept() != Line.getyIntercept())) { answer = true; } return answer; }
// Is Perpendicular public boolean isPerpendicularTo(Line Line) { boolean answer = false; if (this.slope == -(1 / Line.getSlope())) { answer = true; } return answer; }
// Intersection public Point intersection(Line Line) { double x = (Line.getyIntercept() - this.yIntercept) / (this.slope - Line.getSlope()); double y = this.slope * x + this.yIntercept; if ((this.isParallelTo(Line))) { } return null; }
// equals @Override public boolean equals(Object obj) { // TODO Auto-generated method stub boolean answer = false; if (obj instanceof Line) { Line p = (Line) obj;
if ((this.slope == p.getSlope()) && (this.yIntercept == p.getyIntercept())) { answer = true; } } return answer; }
// to String @Override public String toString() { return ("Y = " + this.slope + "* X + " + this.yIntercept); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started