public class Vector { private double x; // x coordinate private double y; // y coordinate private Vector() { } public Vector(double a, double b) { x = a; y = b; } public double getXCoordinate() { return x; } public double getYCoordinate() { return y; } public void setXCoordinate(double a) { x = a; } public void setYCoordinate(double b) { y = b; } // Returns the magnitude of this vector: |this|. public double magnitude() { double squareX = getXCoordinate() * getXCoordinate(); double squareY = getYCoordinate() * getYCoordinate(); return Math.Sqrt(squareX + squareY); } // Returns a vector that is the scalar multiple of s and // this vector: s * this. public Vector scalarMultiple(double s) { double scalarX = s * getXCoordinate(); double scalarY = s * getYCoordinate(); return new Vector(scalarX, scalarY); } // Returns the vector sum of this vector and v: this + v. public Vector sum(Vector v) { double sumX = this.getXCoordinate() + v.getXCoordinate(); double sumY = this.getYCoordinate() + v.getYCoordinate(); return new Vector(sumX, sumY); } }