Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//Complete this class. public class Vector2D { } 1. Vector2D.java: This file des

ID: 3567289 • Letter: #

Question

//Complete this class.
public class Vector2D {

}

1. Vector2D.java: This file describes an abstraction of a two dimensional vector, a Vector2D object. This class has two private attributes of type double, e.g. an x position and a y position. These values are set by the constructor. This file also contains a distance method that takes as input another Vector2D object and returns the distance between the argument vector and this vector reference, recall d = root (vx-wx)^2+(uy-wy)^2, where u and w are vectors and d is the Euclidean distance that separates them.

Explanation / Answer

Here you go :)

public class Vector2D

{
   private double xVal;
   private double yVal;
  
   public Vector2D(double xVal,double yVal)
   {
       this.xVal=xVal;
       this.yVal=yVal;
   }

   public double getxVal() {
       return xVal;
   }

   public double getyVal() {
       return yVal;
   }
  
   public double distance(Vector2D v)
   {
       return Math.sqrt(Math.pow(this.getxVal()-v.getxVal(), 2)+Math.pow(this.getyVal()-v.getyVal(), 2));
   }
}