Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please fill in code based on instructions given in code. this is java. /** * This class defines a 3D vector * */ public class

please fill in code based on instructions given in code. this is java.

/**

* This class defines a 3D vector

*

*/

public class Vector3D {

// define instance variables here

/**

* Creates the vector (0.0, 0.0, 0.0).

* This is the default constructor.

*/

public Vector3D() {

// insert your code here

}

/**

* Creates the vector (x, y, z).

* @param x is the x-component of the vector

* @param y is the y-component of the vector

* @param z is the z-component of the vector

*/

public Vector3D(double x, double y, double z) {

// insert your code here

}

/**

* Creates a vector with the same components as another vector.

* This is the copy constructor.

* @param other

* a vector to copy the components from

*/

public Vector3D(Vector3D other) {

// insert your code here

}

/**

* Returns the x component of the vector.

* @return the x component of the vector.

*/

public double getX() {

// insert your code here and change the return statement

return 0;

}

/**

* Sets the x component of the vector.

* @param x the new value of the x component.

*/

public void setX(double x) {

// insert your code here

}

/**

* Returns the y component of the vector.

* @return the y component of the vector.

*/

public double getY() {

// insert your code here and change the return statement

return 0;

}

/**

* Sets the y component of the vector.

* @param y the new value of the y component.

*/

public void setY(double y) {

// insert your code here

}

/**

* Returns the z component of the vector.

* @return the z component of the vector.

*/

public double getZ() {

// insert your code here and change the return statement

return 0;

}

/**

* Sets the z component of the vector.

* @param z the new value of the z component.

*/

public void setZ(double z) {

// insert your code here

}

/**

* Adds a vector to this vector and changes the components of this vector.

* To add, the counterpart components are added together.

* @param other is the vector that is added to this vector.

* @return this Vector3D object

*/

public Vector3D add(Vector3D other) {

// insert your code here and change the return statement

return new Vector3D();

}

/**

* Subtracts a vector from this vector and changes the components of this vector.

* To subtract, the counterpart components are subtracted.

* @param other is the vector that is subtracted from this vector.

* @return this Vector3D object

*/

public Vector3D subtract(Vector3D other) {

// insert your code here and change the return statement

return new Vector3D();

}

/**

* Multiplies this vector by a scalar.

* @param scalar is the scalar that is multiplied by this vector

* @return this vector after multiplication

*/

public Vector3D scalarMultiplication(double scalar) {

// insert your code here and change the return statement

return new Vector3D();

}

/**

* computes the DOT product of this vector and the given vector

* @param other is the given vector, whose DOT product with this vector is given

* @return the DOT product of this and the other vector.

*/

public double dotProduct(Vector3D other) {

// insert your code here and change the return statement

return 0;

}

/**

* Returns the magnitude of this vector.

* @return the magnitude of this vector.

*/

public double magnitude() {

// insert your code here and change the return statement

return 0;

}

/**

* Returns a string representation of the vector as [x, y, z],

* where x, y and z are teh components of teh vector.

* @return a string representation of the vector

*/

@Override

public String toString() {

// insert your code here and change the return statement

return "";

}

/**

* Determines if the difference between the magnitude of this vector and the other vector

* is smaller than the given threshold.

* @param other the other vector that is compared with this vector

* @param threshold a positive double, which shows the accepted magnitude difference between the two vectors

* @return true if the difference between magnitude of the

* two vectors is less than threshold and false otherwise

*/

public boolean equalTo(Vector3D other, double threshold) {

// insert your code here and change the return statement

return true;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions