Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

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

Calculus

Authors: Ron Larson, Bruce H. Edwards

10th Edition

1285057090, 978-1285057095

More Books

Students also viewed these Programming questions

Question

Does log 81 (2401) = log 3 (7)? Verify the claim algebraically.

Answered: 1 week ago