Write a non-static method named intersection that takes an instance of Challenge
ID: 3833287 • Letter: W
Question
Write a non-static method named intersection that takes an instance of ChallengeLine as a parameter and
// returns an instance of the PointXY class (provided) at the intersection of the input line and this line.
You may use public class PointXY{ for help
public class PointXY{
// Instance variables are declared inside the class definition and outside any methods
// Private variables cannot be access from outside the class
private double x;
private double y;
// The default constructor creates a point on the origin
public PointXY(){
this.x = 0;
this.y = 0;
}
// A constructor that sets the initial position of the point
public PointXY(double x, double y){
this.x = x;
this.y = y;
}
// public getter, or accessor, methods to allow access the private instance variables from other classes/objects
public double getX(){
return this.x;
}
public double getY(){
return this.y;
}
// public setter, or mutator, methods to allow other classes/objects to change the private instance variables
public void setX(double x){
this.x = x;
}
public void setY(double y){
this.y = y;
}
// Define how an object of this type is printed (We will cover Overrides on Friday)
@Override
public String toString(){
return "(" + x + ", " + y + ")";
}
Need the correct asnwer thank you
Explanation / Answer
You might have to change the name because you have not pasted ChallengeLine code here: The logic is correct , This is how intersection work, Answer is 100% correct and I am sure about it. public PointXY Intersect(Line l) { double x = (l.b - this.b) / (this.m - line.m); double y = this.m * x + this.b; PointXY p = new PointXY(x,y); return p; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.