Answered step by step
Verified Expert Solution
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.
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started