java - Learning basics about objects -
public class vector { private final double deltax,deltay; public vector(double deltax, double deltay) { this.deltax = deltax; this.deltay = deltay; public vector plus(vector(a, b)){ return new vector(this.deltax+a,this.deltay+b); }
why not work when trying create method add new vector existing one? defining deltax horizontal component , deltay vertical.
you aren't using correct syntax. method should be:
public vector plus(vector other) { return new vector(this.deltax + other.deltax, this.deltay + other.deltay); }
that way, can pass vector instances method.
Comments
Post a Comment