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

Add a method named dotProduct that takes as an argument a another vector c2 and

ID: 3729454 • Letter: A

Question

Add a method named dotProduct that takes as an argument a another vector c2 and returns a new vector object that represents the product of the target object and c2 vector.

GIVEN JAVA CODE:

public class Vector3D {

// instance variable or properties
private double x;
private double y;
private double z;
// constructors
public Vector3D(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
// getters
public double getX() {
return x;
}
public double getY() {
return y;
}
public double getZ() {
return z;
}
// setters
public void setX(double x) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
public void setZ(double z) {
this.z = z;
}
// instance methods
public double getMagnitude() {
double sumSquares = (this.x * this.x) + (this.y * this.y) + (this.z * this.z);
double result = Math.sqrt(sumSquares);
return result;
}
public Vector3D normalized() {
double newX = this.x / this.getMagnitude();
double newY = this.y / this.getMagnitude();
double newZ = this.z / this.getMagnitude();
Vector3D result = new Vector3D(newX, newY, newZ);
return result;
}
}

Explanation / Answer

public class Vector3D { // instance variable or properties private double x; private double y; private double z; // constructors public Vector3D(double x, double y, double z) { this.x = x; this.y = y; this.z = z; } // getters public double getX() { return x; } public double getY() { return y; } public double getZ() { return z; } // setters public void setX(double x) { this.x = x; } public void setY(double y) { this.y = y; } public void setZ(double z) { this.z = z; } // instance methods public double getMagnitude() { double sumSquares = (this.x * this.x) + (this.y * this.y) + (this.z * this.z); double result = Math.sqrt(sumSquares); return result; } public Vector3D normalized() { double newX = this.x / this.getMagnitude(); double newY = this.y / this.getMagnitude(); double newZ = this.z / this.getMagnitude(); Vector3D result = new Vector3D(newX, newY, newZ); return result; } public Vector3D dotProduct(Vector3D v2){ Vector3D result = new Vector3D(this.x*v2.x,this.y*v2.y,this.z*v2.z); return result; } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote