Question: Vector3D.java Your task is to complete the implementation of a streamlined Vector3D class that describes a vector in R 3 . This class consists of

Vector3D.java

Your task is to complete the implementation of a streamlined Vector3D class that describes a vector in R3 . This class consists of three instance variables, all of type double, called x, y, and z. (DO NOT change the signature of any method or implement any additional ones). Provide the missing code segment where indicated in the class below:

public class Vector3D {

// The x, y and z coordinates of this 3-D vector.

private double x,y,z;

// constructs a three-vector whose x, y, and z coordinates are 0.0, 0.0, and 0.0, respectively.

public Vector3D() {

// TO DO (A)

}

/** constructs a three-vector

* @param xVal the value of the first coordinate

* @param yVal the value of the second coordinate

* @param zVal the value of the third coordinate

*/

public Vector3D(double xVal, double yVal, double zVal) {

// TO DO (B)

}

/**

* @return the length of the vector

*/

public double length() {

// TO DO (C)

}

/**

* Computes the cross product of this vector and the specified 3-D vector.

* @param v a 3-D vector

* @return a 3-D Vector representing the cross product of two 3-D vectors.

*/

public Vector3D cross(Vector3D v) {

// TO DO (D)

}

/**

* Computes the scalar product of this vector and the specified number.

* @param n a scalar.

* @return a 3-D vector represent the scalar product

*/

public Vector3D times(double n) {

// TO DO (E)

}

/**

* Computes the unit vector of this vector.

* Given a 3-D vector v = , its unit vector is

* @return a 3-D unit vector

*/

public Vector3D unit() {

// TO DO (G)

}

/**

* Gives a string representation of a 3-d vector in this format: .

* @return a string representing this 3-D vector.

*/

public String toString() {

// TO DO (H)

}

/**

* Compares two 3-Vectors.

* @param o an Object reference

* @return false when this object does not have the same coordinates as the specified Vector3D object that o holds; otherwise, true

*/

public boolean equals(Object o) {

// TO DO (I)

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!