In a project for my CS class, I am supposed to use a double value to scale a LineSegment and return a new LineSegment whose start Point is the same start Point of the old LineSegment, but with a new end point from being scaled. I am unsure of how to do this. I attempted to multiply the line segment by scalar, but that did not work and gave me an incompatible typing error. Here is my code.
public class LineSegment {
private final Point start;
private final Point end;
public LineSegment(Point start, Point end) {
this.start = start;
this.end = end;
}
public double slope() {
return ((end.getY()-start.getY())/(end.getX()-start.getX()));
}
public double yIntercept() {
return (start.getY()-(this.slope()*start.getX()));
}
public Point getStart() {
return this.start;
}
public Point getEnd() {
return this.end;
}
public double length() {
return (Math.sqrt(Math.pow((end.getX()-start.getX()),2) + Math.pow((end.getY()-start.getY()),2)));
}
public LineSegment scaleByFactor(double scalar) {
return null;
}
@Override
public String toString() {
return ("y = " + this.slope() + "x +" + this.yIntercept());
}
}