Difference between revisions of "Vector class lab assignment"

From WLCS
(Created page with "=== Resources === * [https://www.mathsisfun.com/algebra/vectors.html MathIsFun - Vectors] * [https://www.mathsisfun.com/polar-cartesian-coordinates.html Converting from Polar to ...")
 
Line 1: Line 1:
=== Resources ===
+
== Resources ==
 
* [https://www.mathsisfun.com/algebra/vectors.html MathIsFun - Vectors]
 
* [https://www.mathsisfun.com/algebra/vectors.html MathIsFun - Vectors]
 
* [https://www.mathsisfun.com/polar-cartesian-coordinates.html Converting from Polar to Cartesian]
 
* [https://www.mathsisfun.com/polar-cartesian-coordinates.html Converting from Polar to Cartesian]
  
=== Vector class ===
+
== Vector class ===
 
* Create a Vector class using the following specifications (HINT: Use any of your notes or other classes as resources):
 
* Create a Vector class using the following specifications (HINT: Use any of your notes or other classes as resources):
  

Revision as of 10:28, 15 October 2015

Resources

Vector class =

  • Create a Vector class using the following specifications (HINT: Use any of your notes or other classes as resources):

BE SURE TO COMMENT YOUR CODE

Attributes (private):

  • double magnitude (default: 0)
  • double direction (default: 0)

Methods (public)

  • Vector() - default constructor
  • Vector(double r, double theta) - specific constructor
  • void setMag(double newMag)
  • void setDir(double newDir)
  • double getMag()
  • double getDir()
  • double getX()
    • returns the Cartesian x-coordinate of the Vector (look at Resources to convert Polar->Cartesian)
  • double getY()
    • returns the Cartesian y-coordinate of the Vector (look at Resources to convert Polar->Cartesian)
  • String toString() - returns a String representation of the Vector
  • Vector add(Vector v)
    • returns a new Vector after calculating the Vector addition of itself and Vector v
  • Vector sub(Vector v)
    • returns a new Vector after calculating the Vector subtraction of itself and Vector v

Testing your Vector class

  • Write your own main method to test out all the methods in the Vector class