Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Vector3D.java contains the following code: public class Vector3D { // define instance variables here /** * Creates the vector (0.0, 0.0, 0.0) . * This

image text in transcribedimage text in transcribedimage text in transcribed

Vector3D.java contains the following code:

public class Vector3D { // define instance variables here /** * Creates the vector (0.0, 0.0, 0.0). * This is the default constructor. */ public Vector3D() { }

/** * 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) { }

/** * 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) { }

/** * 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) { } /** * 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) { }

/** * 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; } }

1. Setup Please download Lab3.zip that is attached to this description. o . Open eclipse. Click on File and select Import. Choose Existing Projects into Workspace and click Next. Click on Select Archive File and then Browse. Find Lab3.zip and click Finish. Please make sure that you do not already have a project called Labs, otherwise eclipse cannot import it for you. You should see two files, one is called Vector3D.java and one Vector3DTester.java. 0 2. Important Notes: To practice testing, we only provided a set of incomplete test cases. You should make sure that you add enough test cases to the tester that tests your code thoroughly. Please have a look at the tester code Vector3DTester, in which you'll see that some of the testers do not have a meaningful implementation. We have kept it empty for you to fill it in and test your code thoroughly. 3. JavaDoc generation The javaDoc has been written for you. All you need to do is to generate it as an HTML file to make it easier for navigation. For this, right click on Vector3D.java -> select export -> javaDoc -> Next. It will ask you for the location in which you want to store the documentation. Enter the path and then click Finish. If you look at the location in which you stored the documentation, you'll see there is a file called index.html. Clicking on this file, shows the documentation of the project in your browser. 4. Programming Task This lab assumes that you are familiar with 3-dimensional vectors. If you are not familiar with the basic mathematical operations, review this link, which is about 2D-vectors. 3D vectors are the same as 2D vectors except that it has one more component. 1.1. Basics of the Class and Encapsulation First start with implementing the correct class variables and the accessor methods getX(), getY(), getz(), setX(), setY() and setz() in order to encapsulate the data. These methods are needed by the testers. This class has three constructors, to set the values of the instance variable. A 3D vector has 3 components x, y, and z. Use the unit tester to test your constructors as you complete them. 1.2. Add the methods Add the methods of the class one at a time. Read the API of each method to guide your implementation. Now switch to the tester code and complete the test case that tests the method. When you were happy with the result, implement the next method. Please note that as usual you should not change the signature of the methods (i.e. name, return type, access modifier and parameters)

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

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions