Collisions - part2.takeStep(); if...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// *********************************************************** // Collisions.java // // Program to simulate particles moving in space. // *********************************************************** public class Collisions { public static void main (String[] args) { final int BOUNDARY = 2000000; final int MAXSTEPS = 100000; int collisions = 0; RandomWalk part1 = new RandomWalk(MAXSTEPS, BOUNDARY, -3, 0); RandomWalk part2 = new RandomWalk(MAXSTEPS, BOUNDARY, 3, 0); for (int i=0; i<MAXSTEPS; i++) { part1.takeStep();
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: part2.takeStep(); if (samePosition(part1,part2)) collisions++; } System.out.println(collisions + &quot; collisions&quot;); } //----------------------------------------------------// Returns true if the two particles are in the same position, // false otherwise. //----------------------------------------------------public static boolean samePosition(RandomWalk part1, RandomWalk part2) { return part1.getX() == part2.getX() &amp;&amp; part1.getY() == part2.getY(); } }...
View Full Document

Ask a homework question - tutors are online