Project 3: N-Body Simulation

Start: Tuesday 9/30; Due: Friday 10/17, by the beginning of class


Overview

This assignment is also taken from the projects on the book's web site. In this case, the assignment is the N-Body Simulation. After reading through that page, be sure to read my comments below for some clarification and suggestions. I will discuss the underlying math and physics in class.

You should work on this project individually.

Specific tasks

  1. Create a Java Project named "Project3".
  2. In order to do this program, you will need (1) the stdlib.jar library file provided by the book's authors; and (2) some other resource files you will need such as the planets.txt file they describe and some image and sound files. It is best to store these files in your Eclipse project, since that way we will have access to your full environment when you hand in your project. So, right-click on Project3 and create two directories called lib and resources.
  3. (I will show how to get stdlib.jar and configure the class path in lab, but I am including the instructions anyway, for completeness and reference.) Download the stdlib.jar file and copy it into the lib folder. You then need to tell Eclipse about this library file by configuring your build path. To do this, right-click on Project3 in Eclipse and select Build Path > Configure Build Path... In the window that pops up, you should be in the Libraries tab of Java Build Path; if not, then go there. Then click on the Add Jars... button and choose stdlib.jar in the lib directory under Project3.
  4. The Programming Assignments portion of the Textbook's website has useful checklists for each of the programming assignments. In particular, the checklist for the N-Body Simulation gives some useful tips on downloading from the COS 126 ftp site. You will need to download the contents of the nbody folder there, and then copy those files into the resources directory you created in step 2 above. Alternatively, you can download the nbody.zip, expand it by double-clicking in the Finder, and then copying it to the resources directory.
  5. The assignment from the textbook site shows how to run the program from the command line using input redirection (the < operator) in order to read the planets.txt file as StdIn. I would suggest you instead do all your work in Eclipse. In order to do this, you can provide the name of the input file as a third command argument after the finishing time and time step, without using <. Your program then needs to start with a little extra code to open up the specified file and use it as StdIn. I am providing that code for you in this starting version of NBody.java. I will talk about this in lab.
  6. I recommend you read through checklist for the N-Body Simulation, in particular the section titled "Possible Progress Steps", before embarking on the programming.
  7. Finally, if you enjoy this and want to add some enhancements, there are some suggestions in the N-Body Simulation assignment page as well as in the checklist for the N-Body Simulation.

What you must do/hand in

Running your program with the supplied data file planets.txt should result in the same behavior (including background image, images for the planets, and the 2001 midi file being played) as the animation at the bottom of the N-Body Simulation page. It should also print out the description of the ending state as shown there; this numerical information helps check that your simulation really is correct, as opposed to just looking plausible. You must also fill out our version of the readme.txt file (not the Princeton version on the textbook site). If you do any additional extra credit work, be sure to note it in that file.

Gradesheet

We will use this gradesheet when grading your lab.

Submission

Use the same procedure to submit your code as in the previous project. Submit the zip file via Moodle. This is described in our step by step instruction on submitting code. Be sure to select f-mcs-178-003, which is the lab section.