Assignment 7: Dance of the Ions
Fall 2007, David Matuszek

Purposes of this assignment:

General idea of the assignment:

A number of ions (charged atoms) are placed in a two-dimensional rectangular box. The ions repel each other with a force inversely proportional to the square of their distance. That is, if they are one unit apart, they repel each other with a force of one; if they are two units apart, with a force of 1/4, or 0.25; if five units, with a force of 1/25, or 0.04; and so on. Every ion is affected by every other ion.

Ions that are close together will move apart, as each ion tries to get as far away from its neighbors as possible. After a while, the ions should settle down into a more-or-less "stable" position, and not move very much more.

In addition, some ions may be "glued in place" and unable to move.


Create an Ion class and an IonBox class. Ions come in two flavors, "free" (able to move about) and "fixed" (glued in place).

The Ion class will have:

The IonBox class will have:

Most importantly, write JUnit tests to convince me that your methods work, and that the ions reach a stable position as far from one another as possible. And follow all the "best practices" that we have been talking about, such as writing tests first, keeping methods short and single purpose, etc.

I'm leaving more unspecified in this assignment than in previous assignments. It's up to you to fill in the details. I do want the above methods, so that I can do a bit of my own testing.

Programming hints:

Due date:

Thursday, November 1, before midnight. Turn in your program electronically, using Blackboard. (See my Instructions for Using Zip Files and Blackboard). Only assignments submitted via Blackboard will be accepted--do not send your program by email. The usual late penalty of 5 points per day (out of 100 points) will apply.