Here is a general guide/pseudocode for your OOD N-Body Simulation
Planet ADT
Attributes: x, y, vx, vy, m
Behaviors:
Getter methods(accessors):
one for each attribute
overload toString method
Setter methods (mutators):
one for each attribute
update method with three arguments: mass, x position and y position of another body to calculate the distance between the two bodies, the force between the two bodies, the new velocity in vx and vy components.
position method: to calculate the new x and y coordinates using the updated vx and vy with deltaT
draw method: to “draw” the image
Dynamic System ADT
Attributes: Planet array
Behaviors:
motion method:
Accessor and mutator. It passes the mass, x and y positions from one body to another in the array of planets by using nested “for” loops.
draw method to show new positions
System Simulator “main”:
Set the universe scale
Create each planet and sun (as a planet)
Create array of planets
Create Dynamic System with the array of planets
Optional but pretty useful —> Threads:
while (true) { motion draw try { Thread.sleep(150); } catch (InterruptedException e) { System.out.println("Error sleeping"); } }