Question: Q4) 25 Points Create a class called Vector. The class Vector must contain 3 instance variables. Each instance variable must be declared as private.

Q4) 25 Points Create a class called Vector. The class Vector must

Q4) 25 Points Create a class called Vector. The class Vector must contain 3 instance variables. Each instance variable must be declared as private. private double x: private double y; private double z; Your class should have the following public methods: 1. public Vector(double xcoord, double ycoord, double zcoord) This is the constructor of your vector class. It should initialize 3 private instance variables, called x, y, z with the values of the input variables xcoord, ycoord, and zcoord respectively. 2. public double getX() This method should return the value of the instance variable x 3. public double getY() This method should return the value of the instance variable y 4. public double getZ() This method should return the value of the instance variable z 5. public Vector add(Vector v) This method should add the vector which is passed as a parameter to the calling vector (this vector) 6. public double dotProduct(Vector v) This method should compute the dot product of this vector with the vector given as parameter. 7. public double computeMagnitude() This method should compute the magnitude of the vector. 8. public void normalize() This method should normalize this vector. 9. public Vector scaleVector(double factor) This method should scale the vector by the factor listed as a parameter. Create a main method and test the above methods.

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 Programming Questions!