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); } // Returns the dot product of this vector and v: this . v. public double dotProduct(Vector v) { double productX = this.getXCoordinate() * v.getXCoordinate(); double productY = this.getYCoordinate() * v.getYCoordinate(); return productX + productY; } // Returns the difference of this vector and v: this - v. public Vector difference(Vector v) { Vector reverse = v.scalarMultiple(-1) return this.sum(reverse); } // Returns the vector in the set {this, v} that has the greatest // magnitude. public vector maximum(Vector v) { if (this.magnitude() > v.magnitude()) return this; else return v; } // Returns the linear combination of this vector, v, a and b: // (a * this) + (b * v). public Vector linearCombination(Vector v, double a, double b) { Vector v1 = this.scalarMultiple(a); Vector v2 = v.scalarMultiple(b); return v1.sum(v2); } // Returns the normalization of this vector to v: this norm v. public Vector normalization(Vector v) { double scalar = v.magnitude / this.magnitude(); return this.scalarMultiple(scalar); } }