Lab 3, CSC 102, Spring 2012
1 The Lab
For each of the following, "develop a method" includes a one-line comment and a test case in a Test Case class called Lab3.
Design the class XYVec, that represents a 2-dimensional vector using cartesian coordinates.
Use the "Source > Generate hashCode() and equals()" menu entry to generate hashCode and equals methods. (Go with the defaults in the resulting dialog box.) This will allow you to write test cases on instances of this class.
Develop the method mag on the XYVec class that returns the magnitude of the vector
Develop the method add on the XYVec class that accepts another XYVec and retuns their sum.
Develop the SpaceShip class, that contains a location (XYVec) and a velocity (XYVec). Create hashMap and equals methods as before.
Develop the vMove method on the SpaceShip class that accepts nothing and returns a new SpaceShip whose velocity is the same and whose location differs by the velocity.
Develop the avMove method on the SpaceShip class that accepts an acceleration (XYVec) and returns a new SpaceShip whose location differs by the existing velocity and whose velocity differs by the given acceleration.
Develop the accelerateTowards method on the SpaceShip class that accepts a position and returns the a new SpaceShip that is the result of accelerating the SpaceShip towards the position at 9.8 (mumbles)/(mumble)^2.