Hendrix College, 1600 Washington Ave, Conway AR 72032
|ACM API||Swing API|
|Part 1 description||SolarSystem.java||SolarSystem.java|
|Part 2 description||SolarSystem.java||SolarSystem.java|
To teach object-oriented concepts in Java during CS1, I use a matched pair of short, guided assignments emphasizing the application of computers to the n-body problem and particularly to space navigation. This has the advantage of not only teaching object-oriented concepts, but also seeing an application of computers and reviewing some basic physics. Both assignments display the simulation graphically. Though the assignments were built for a class using the ACM Java Task Force's API, the assignments themselves has little direct reference to this API; it was little trouble to port the assignments so that they use Swing alone.
The assignments are cumulative. In course evaluations, students often report that they appreciate such cumulative assignments. But this also introduce the problem of students who don't complete the first part and so are at a disadvantage for the second. This pair attempts to address this issue by keeping the first part fairly short, though it does often require a bit of instructor help. Another way to address the problems of students failing to complete the first part is to schedule them so that students start the second a full week afer the first is due; that way, students who submit the first portion late will still be able to start the second on time.
The first assignment is a simple
n-body simulation for six bodies, including the sun,
the inner four planets, and a comet (Encke). The student's job is to
write a class
Body that manages a body's position within
the solar system, which includes the physical equations for computing
force. Many students are not quite able to get these physical equations
exactly right and will require instructor help to debug them.
This assignment is intended as the first assignment where students develop their own classes. The assignment provides a skeleton class to the students, and they are told to add several specified methods into the class. The student will also be required to add some new instance variables representing the body's current velocity in the x- and y-direction.
The second assignment is meant as a first
assignment after discussing how one writes subclasses and overrides
methods. It adds a
Spaceship class to the mix of the
preceding assignment, in order to represent a ship that is controlled
via the keyboard. Because the spaceship is itself a body in the system,
subject to the same gravitational forces, it is naturally a subclass
Body class of the previous assignment. However,
the instance method that updates a body's velocity must be overridden
to account not only for gravity but also for the force exerted by
the ship's rockets.