# Motorbike contructor help

**URL:** https://discourse.processing.org/t/motorbike-contructor-help/25421
**Category:** Coding Questions
**Tags:** homework
**Created:** [November 14, 2020, 2:07pm UTC](https://discourse.processing.org/t/motorbike-contructor-help/25421 "2020-11-14T14:07:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![TheGullible1](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TheGullible1](https://discourse.processing.org/u/TheGullible1)
#### Post date: [November 14, 2020, 2:07pm UTC](https://discourse.processing.org/t/motorbike-contructor-help/25421/1 "2020-11-14T14:07:34Z")

</div>

im trying to add a constructor to my code and I think I don’t understand how to do it

my code:

```auto
Motorbike redBike;
Motorbike blueBike;

void setup() //called only once at the start
{
  size(500,100);
  Motorbike(30, RED );
  //redBike.y = 30;
  //redBike.colour = RED;
  Motorbike(60, BLUE);
 // blueBike.y = 60;
  //blueBike.colour = BLUE;
}

void draw() //60 times a second
{
  background(125);
  redBike.update();
  blueBike.update();
  
} 

```

class code:

```auto
final color RED = color(255,0,0);
final color BLUE = color(0,0,255);

class Motorbike
{
 int x = 5; //members
 int y;
 int speed=2;
 int size=30;
 color colour;

 void render()
 {
   float wheelHeight = size/3;
   fill(colour);
   triangle(x,y,x+size,y,x+size/2,y-size/2); //built-in triangle routine
   drawWheel(x,y,wheelHeight);
   drawWheel(x+size,y,wheelHeight);
 }
 
 void drawWheel(int x,int y,float size)
 {
    float inner = size*2/3;
    fill(0);
    ellipse(x,y,size,size);
    fill(255);
    ellipse(x,y,inner,inner);
 }
 void move() {
    speed = (int)random(5.0); //a random step [0..5]
    x=x+speed; 
 }

 void update() {
   move();
   render();
 }
 
 Motorbike(int y,color col){ //constructor
   this.y = y;
   this.speed = (int)random(5.0);
   this.colour = col;
 }

} //end of class description

```

so this is my constructor code which I have added to my class Motorbike:

```auto
Motorbike(int y,color col){ //constructor
   this.y = y;
   this.speed = (int)random(5.0);
   this.colour = col;
 }

```

this is what I don’t understand what to do here with that constructor code:

```auto
void setup() //called only once at the start
{
  size(500,100);
  Motorbike(30, RED );
  //redBike.y = 30;
  //redBike.colour = RED;
  Motorbike(60, BLUE);
 // blueBike.y = 60;
  //blueBike.colour = BLUE;
}

```

Also explain what the constructor does in the code please, that would be helpful to me, thanks.

---

<div class="post-metadata">

### Author: ![TheGullible1](https://avatars.discourse-cdn.com/v4/letter/t/7bcc69/32.png) [@TheGullible1](https://discourse.processing.org/u/TheGullible1)
#### Post date: [November 14, 2020, 2:37pm UTC](https://discourse.processing.org/t/motorbike-contructor-help/25421/2 "2020-11-14T14:37:55Z")

</div>

So i worked it out myself, lol

```auto
Motorbike redBike;
Motorbike blueBike;

void setup() //called only once at the start
{
  size(500,100);
  redBike = new Motorbike(30,RED);
 // redBike.y = 30;
 // redBike.colour = RED;
  blueBike = new Motorbike(60,BLUE);
  //blueBike.y = 60;
  //blueBike.colour = BLUE;
}

```
