Complete Specifications for the Vector3D Class
This is your chance to create an API You
will create a class for doing computation with complex numbers.
It will have all features listed here. Use the ideas from the
BigFraction
case study. Your final product should have
a similar appearance to the product in the textbook.
Static Constants Our class will have
three static constants as shown here. Initialize them in a
static
block.
Vector3D.I
This is i.Vector3D.J
This is j.Vector3D.K
This is k.
State Your class will have private state variables for the coefficients of i, j, and k.
Methods Your public interface will look like this. You may add any private or other methods as you see fit.
/** * DO NOT change this interface in any way * Your program will be compiled against this interface, so your methods * must have exactly these signatures or your program will fail to compile. */ public interface IVector3D { /** * @param that anohter IVector3D * @return the dot product of this vector and that. */ public int dot(IVector3D that); /** * @param that anohter IVector3D * @return the cross product of this vector and that. */ public IVector3D cross(IVector3D that); /** * @param scalar a integer we are scalar multiplying this vector by * @return the that*this */ public IVector3D scalarMultiply(int scalar); /** * @param scalar a integer we are scalar multiplying this vector by * @return this + that */ public IVector3D add(IVector3D that); /** * @param scalar a integer we are scalar multiplying this vector by * @return this - that */ public IVector3D subtract(IVector3D that); /** * @return the length of this vector */ public double magnitude(); /** * @param that another vector * @return the angle between this and that in radians in [0,π] */ // public double angleBetween(IVector3D that); }
This is a shell file for your class.
/* * This is a class of 3D immutible vectors with * integer coefficients. */ public class Vector3D implements IVector3D { //initialize in a static block public static final Vector3D I = null; public static final Vector3D J = null; public static final Vector3D K = null; /* * @param a coefficient of I * @param b coefficient of J * @param c coefficient of K * This makes ai + bj + ck */ public Vector3D(int a, int b, int c) { } /** * This makes the zero vector */ public Vector3D() { } /** * @param that anohter IVector3D * @return the dot product of this vector and that. */ public int dot(IVector3D that) { return 0; } /** * @param that anohter IVector3D * @return the cross product of this vector and that. */ public Vector3D cross(IVector3D that) { return null; } /** * @param scalar a integer we are scalar multiplying this vector by * @return the that*this */ public Vector3D scalarMultiply(int scalar) { return null; } /** * @param scalar a integer we are scalar multiplying this vector by * @return this + that */ public Vector3D add(IVector3D that) { return null; } /** * @param scalar a integer we are scalar multiplying this vector by * @return this - that */ public Vector3D subtract(IVector3D that) { return null; } /** * @return the length of this vector */ public double magnitude() { return 0; } /** * @param that another vector * @return the angle between this and that in radians in [0,π] */ public double angleBetween(IVector3D that) { return 0.0; } /** * @return A string representation of the form ai + bj + ck. * Make sure you have negative terms not looking like crap. */ @Override public String toString() { return ""; } @Override public boolean equals(Object o) { return false; } }
Javadoc You will also javadoc this class so it is usable by someone who does not see your code. This is an important part of the project.
Shell Code Download the shell code on the left; there are two files Vector3D.java and IVector3D.java. Place them in the same folder and open them with DrJava. They will compile right out of the box, since all methods bear an appropriate stub. Keep them in the same directory.
Do not change the contents of IVector3D.java
at all. Do
not change any of the method names or signaures in
Vector3D.java
. Doing either of these will cause your project
to fail to compile for me. You may add methods to this class if you wish.
Of course, you may also add private methods to do tasks behind the
scenes.