the left hand side of the assignment must be a variable?

I’m having a bit of trouble with one function in my problem and it’s giving me the answer that I’ve put as the title. I’m pretty dang sure I haven’t done anything wrong, but it’s still throwing the error.


public class Line {
	public Vec2D p1, p2;
	public Line(Vec2D p1, Vec2D p2){
		this.p1 = p1;
		this.p2 = p2;
	}
	public boolean intersects(Line l){
		if( ( ((p1.x - p2.x)(l.p1.y - l.p2.y)) - ((p1.y + p2.y)(l.p1.x - l.p2.x)) ) == 0) return false; // here's where the error is
		return true;
	}
}

Any ideas?

EDIT: wow I feel stupid. I’ve been in calc class too long and forgot to put the * symbols in… DISREGARD THIS THREAD

What are you supposed to do between these groups? [icode](p1.x - p2.x)(l.p1.y - l.p2.y)[/icode], Multiply them? If so put an asterisk ([icode]*[/icode]) in between the groups. The whole code which fixes.


public class Line
{
    public Vec2D p1, p2;
  
    public Line(Vec2D p1, Vec2D p2)
    {
        this.p1 = p1;
        this.p2 = p2;
    }
  
    public boolean intersects(Line l)
    {
        if ((((p1.x - p2.x)*(l.p1.y - l.p2.y)) - ((p1.y + p2.y)*(l.p1.x - l.p2.x))) == 0) return false;
        return true;
    }
}

Hope this works now.

Also fun fact, since that whole expression results in a boolean anyway, you can just return it rather than checking if it’s true or false and returning true or false:


public boolean intersects(Line l)
{
    return (((p1.x - p2.x)*(l.p1.y - l.p2.y)) - ((p1.y + p2.y)*(l.p1.x - l.p2.x))) != 0;
}