# Problem with Coding Train 9.4

**URL:** <https://discourse.processing.org/t/problem-with-coding-train-9-4/14437>\
**Category:** Coding Questions\
**Created:** [October 5, 2019, 12:38am UTC](https://discourse.processing.org/t/problem-with-coding-train-9-4/14437 "2019-10-05T00:38:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![redisred](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/redisred/32/6657_2.png) [@redisred](https://discourse.processing.org/u/redisred)\
**Post date:** [October 5, 2019, 12:38am UTC](https://discourse.processing.org/t/problem-with-coding-train-9-4/14437/1 "2019-10-05T00:38:08Z")

</div>

I’m trying to implement Daniel’s example of the bubbles array and I can’t for the life of me figure out why it’s not working. I should be getting 3 ascending bubbles, but I’m only getting 1, which I suspect might be all 3 on top of each other. Any help would be appreciated!

**Bubble Class:**

```auto
class Bubble {
  float x;
  float y;
  float diameter;

  Bubble(float tempD) {
    x = random(width);
    y = height;
    diameter = tempD;
  }

  void ascend() {
    y--;
  }
  void display() {
    stroke(0);
    fill(127);
    ellipse(x, y, diameter, diameter);
  }
}

```

**Bubbles Sketch:**

```auto
Bubble[] bubbles = new Bubble[2];

int i;

void setup() {
  size(640, 360);
  for (int i = 0; i < bubbles.length; i++) {
    bubbles[i] = new Bubble(30);
  }
}

void draw() {
  background(255);
  fill(0);
  for (int i = 0; i < bubbles.length; i++); 
  {
    bubbles[i].ascend();
    bubbles[i].display();
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 5, 2019, 12:46am UTC](https://discourse.processing.org/t/problem-with-coding-train-9-4/14437/2 "2019-10-05T00:46:23Z")

</div>

please format your code posting,  
using the `</> Prefromatted text` button from the editor header menu

why not link to the book chapter / video / code  
so we not have to search

* * *

please find the changes, different coding style …

```auto
// ___________________________________________________________________ Bubble Class:

class Bubble {
  float x,y,diam;
  Bubble(float _diam) {
    x = random(width);
    y = height;
    diam = _diam;
  }
  
  void ascend() {
    y--;
  }
  
  void display() {
    stroke(0);
    fill(127);
    ellipse(x, y, diam, diam);
    ascend();
  }
}

// _______________________________________________________________________ Bubbles Sketch:

Bubble[] bubbles = new Bubble[2];

void setup() {
  size(640, 360);
  for (int i = 0; i < bubbles.length; i++ ) bubbles[i] = new Bubble(30);
}

void draw() {
  background(255);
  for (int i = 0; i < bubbles.length; i++) bubbles[i].display();
}

```

> [@redisred](#):
>
> getting 3 ascending bubbles

your array only long 2, means index 0 , 1 only  
why you not print

```auto
println(bubbles.length);

```
