here is a recommended plan of attack. it breaks down the project into "milestones". we recommend that you complete Milestone 1 before Spring break. tips: + [Molecule] save function $energy$ for the end -- simply compute kinetic energy "inline" where you need it. + [Molecule, World] hold off on computing and printing stats until after you've gotten Molecules drawn moving around + to SLOW things DOWN or SPEED things UP, change the number 20 in the statement $sleep(20)$ in Project5.run to alter the number of milliseconds the program pauses between computing successive time steps. [remark: this project is missing two complications on exercise 3 -- there is no acceleration and there is no need for sorting.] =============================================================================== Milestone 1 =============================================================================== + obtain Project5.java from Part 5 of the writeup. run your program -- it should throw up an empty graphics window. note: it will be a while before anything is drawn. + [Molecule] declare all the instance variables run your program -- fix any syntax errors. + [Molecule] define the constructor to initialize all the instance variables, including its random position and velocity. note: remember that a Molecule has a radius, and we want it completely inside the world. for example, if a molecule has radius 5, and the container has width 50, then the legal x and y coordinates range from 0+5 to 50-5. run your program -- fix any syntax errors. + [World] declare instance variables for 3 Molecules. inside constructor $World$, instantiate the 3 Molecules as specified in Part 9. run your program -- fix any errors. + [Molecule] define method $paint$. run your program -- fix any syntax errors. + [World] complete method $mypaint$ to tell all the Molecules to draw (paint) themselves. run your program -- *now* you should see something! run your program a number of times at each specified size of the World --given in method $run$ of class $Project5$-- to verify that the Molecules are placed randomly in the World. =============================================================================== Milestone 2 =============================================================================== + [Molecule] define method $move$. updated position without bouncing off walls = current position + velocity * timestep. to bounce off walls, check for the updated position to be too small or too large. if so, compute the "bounced position" via the "d=2w-b" formula given in section (week of march 14). remember to account for the molecules having radii. remember to change the vx or vy velocity appropriately. run your program -- fix any syntax errors. + [World] complete method $move$ to tell all the Molecules to move. run your program -- verify that Molecules bounce off the walls. =============================================================================== Milestone 3 =============================================================================== + [Molecule] define method $collide$. tip: check that extents do *not* overlap (easier than checking that they do overlap). if so, update the velocities by using the equations from Part 8. make sure you apply the equations correctly, e.g. keep track of which molecule is the "1" molecule and which is the "2" molecule, and don't forget the minus signs ("-") for dvx2, dvy2. remember to *add* the *changes* (dvx1,dvy1) and (dvx2,dvy2) of velocity to the original velocities (vx,vy) and (vx2,vy2), respectively. run your program -- fix any syntax errors. + [World] modify method $move$ to test for collisions between all pairs of Molecules *before* telling them all to move. run your program. verify that collisions "look" about right. you will probably notice that some molecules bounce even though they would not hit or bounce before they would hit. those are consequences of our sloppy test (overlapping extents) for collisions. =============================================================================== Milestone 4 =============================================================================== + [World, Molecule] initialize/maintain/compute the statistics and print them out. (this can be done without defining method $energy$.) run your program. check that (PV)/(NT) converges (reasonably near) to 1. (it is easy to forget some factors: kinetic energy is *HALF* mass times velocity-squared, change in momentum applied to the top wall is *TWICE* mass times vertical speed.) + finish anything you haven't done yet, e.g. $energy$ =============================================================================== Bonus Milestone =============================================================================== + only now, after getting the core project to work, should you begin to consider doing the bonuses. you should also NOT rush to get the early bonus points: bonus points count less than core points, so it would be wise to get a higher core score rather than try for bonus points, which already require you to get a 4/4 core score or better.