File tree Expand file tree Collapse file tree
java/examples/Topics/Simulate/MultipleParticleSystems Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ class ParticleSystem {
1616 }
1717
1818 void run () {
19- // Cycle through the ArrayList using Iterator we are deleting
19+ // Cycle through the ArrayList using Iterator, because we are deleting while iterating
2020 Iterator<Particle > it = particles. iterator();
2121 while (it. hasNext()) {
2222 Particle p = it. next();
@@ -28,7 +28,14 @@ class ParticleSystem {
2828 }
2929
3030 void addParticle () {
31- particles. add(new Particle (origin));
31+ Particle p;
32+ // Add either a Particle or CrazyParticle to the system
33+ if (int (random (0 , 2 )) == 0 ) {
34+ p = new Particle (origin);
35+ } else {
36+ p = new CrazyParticle (origin);
37+ }
38+ particles. add(p);
3239 }
3340
3441 void addParticle (Particle p ) {
@@ -37,11 +44,7 @@ class ParticleSystem {
3744
3845 // A method to test if the particle system still has particles
3946 boolean dead () {
40- if (particles. isEmpty()) {
41- return true ;
42- } else {
43- return false ;
44- }
47+ return particles. isEmpty();
4548 }
4649
4750}
You can’t perform that action at this time.
0 commit comments