In this assignment, you will implement simple ADTs for particles in a gravity simulation program. We provide the driver and the main content class. You need to implement ADTs for ``points,'' ``vectors'' and ``particles.''
A Point is a simple immutable class with two fields of type
double. By ``immutable,'' we mean that all fields are
declared final--they are not modified once the object is
constructed. We will use a convention that private fields should have
names preceded by an underscore, so the two fields should be named
_x and _y.
The class provides the following operations:
getX().)
(3.0,-1.5)''.
A Vector represents a direction (in two dimensional space).
We use it to represent velocities (directed movement) of particles.
A Vector is implemented as
an immutable class with two double fields (_dx and _dy)
and the following operations:
<1.0,-2.5>''.
A Particle is a mutable class with four fields:
It provides the following operations:
scale),
update the velocity
add).
This method can assume that the argument particle is not null
and that it is at a different location. (If the two particles
coincided, then
would cause the computation to blow up.)
Your code should use methods of the Vector and
Point ADTs to do most of the work. We will penalize code
that calls the x() or dx() methods directly instead
of using high-level methods.
We provide two programs to test your ADTs with: one a unit test driver
which consists of static methods in a class Test, and the
other a gravity simulation
reached through a class Main. The gravity simulation uses
a graphical animation class called ThreeParticles that should
be placed in the edu.uwm.cs351 package along with the ADTs.
The unit test will by default print an error message for
each failed test and count the number of tests passed and failed.
If you fail a test in an earlier section, it will completely
skip tests in later sections. (If Point isn't working, there isn't
any sense in testing Particle.)
When debugging your program, it makes more sense to have the
test driver stop on the first error found so that you can use
Eclipse to go directly to the failed test. This behavior
can be achieved by adding -throw as a ``Program Argument''
on the ``Arguments'' tab of the ``Run Configuration'' for Test.
$CLASSHOME/src/homework1. Here, and in all assignments,
we use $CLASSHOME as a shorthand for /afs/cs.uwm.edu/users/classes/cs351.
If you want to have this definition work for you, you can add
the following line at the end of the file ``.cshrc''
in your home directory:
setenv CLASSHOME /afs/cs.uwm.edu/users/classes/cs351You may also find it useful to create a ``symbolic link'' to this directory from your home directory. My link is called
cs351.
Your task is to write the following files:
homework/1
directory can be your Eclipse project directory).
We recommend that you install Eclipse (free download available from http://www.eclipse.org) and OpenAFS (free download available from http://www.openafs.org) on a network capable computer, for example, a Windows 7 laptop.
Then, once you have authenticated and have AFS tokens (using Network
Identity Manager on Windows 7, or using kinit and aklog
on MacOSX/Linux), you should create a Java project in Eclipse with the
following steps:
>New>Java Project''
AFS-Homework-1,
and unselect ``use default location'' and instead
use:
\\afs\cs.uwm.edu\users\classes\cs351\401\pantherid\homework\1
/afs/cs.uwm.edu/users/classes/cs351/401/pantherid/homework/1
>Package.''
edu.uwm.cs351 where most of your
code will go.
The order is
exactly backward to what you may expect. Don't
scramble the parts.
>File System.''
\\afs\cs.uwm.edu\users\classes\cs351\src\homework1
/afs/cs.uwm.edu/users/classes/cs351/src/homework1
Main.java and
Test.java and then click ``Finish.''
edu.uwm.cs351 and again select ``Import...''
and import from the same directory again, but this time grab
ThreeParticles.java
If you find OpenAFS being too unreliable, you may create a second Java project in the default location and copy and paste files from the local project to the AFS project when you want to get feedback from instructors or to be graded. We don't recommend this option because many people forget to copy in the latest copy of their files into AFS and then don't get credit for their work.
In later assignments, we often distribute partially implemented
``skeleton files'' with names such as
Sequence.java.SKEL. This should be imported into the correct
package as with a Java file. Afterward the successful import, use
``Refactor>Rename'' to rename the file without the .SKEL
suffix. We use this convention so that (1) it is clear that this file
is incomplete and (2) so you do not accidentally import a skeleton
file on top of a Java file you have been working on.
We will not be repeating these instructions for later assignments. Please keep a reference to them.