I cant figure out this error: "The Constructor "Cat(int, int, float)" does not exist. HELP!!!!

edited December 2017 in Questions about Code
 Cat[] cats = new Cat [20]; //array of cats

 void setup() {
   size(800, 800);

   for (int i = 0; i < cats.length; i++) {
     cats[i] = new Cat(width/2, height*2, random(1,6));
   }
 }
 //random is a function that takes two arguments, ex. (20,200), which are always in parenthesis

 void draw() {
   background (255);
  //  float G; //background color to look like outer space 
  // for(int bg = 0; bg < height; bg ++){
   //  G = map(bg, 0, height, 0, 200);
   //  stroke(0,0,G);
   //  line(0, bg, width, bg);

   for(int i = 0; i < cats.length; i ++) {
       cats[i].move();
       cats[i].display(); 
   } 
 }
 //NEWTAB !!!
 // an array of this drawing (cat) will have multiple of these which move left to right until shot

 class Cat {
   float x;
   float y; // location
   float xSpeed;
   float ySpeed;

 //constructor function
   Cat(float xTemp, float yTemp) {
     x = xTemp;
     y = yTemp;
     xSpeed = random(-2, 2);
     ySpeed = random(-2, 2);

   }
   void move() {

     if (x <0 || x > width) {
       xSpeed = xSpeed * -1;
     }
     if (y <0 || y >= height/2) {
       y = y * -1;
     }
     x = x + xSpeed;
     y = y + xSpeed;
   }

    void display() { 
     stroke(0);
     fill(210,105,30);
     triangle(x-48, y-15, x-51, y-55, x-11, y-40); //ear
     triangle(x+48, y-15, x+51, y-55, x+15, y-40); //ear  

     stroke(0);
     fill(205,133,63);
     ellipse(x, y, 100, 85); //head

     fill(0);
     triangle(x-9, y-8, x+13, y-8, x+2, y+6); //nose 

     line(x-14, y+3, x+18, y+10); //whisker1
     line(x-14, y+10, x+18, y+3); //whisker2^

     fill(255);
     ellipse(x-11, y-18, 20, 10); //left outter eye
     ellipse(x+15, y-18, 20, 10); // right outter eye

     fill(0);
     ellipse(x-11, y-18, 5, 10); //left inner eye
     ellipse(x+15, y-18, 5, 10); //right inner eye

     ellipse(x+4, y+25, 45, 25); //mouth

     fill(255);
     triangle(x-10, y+15, x+0, y+12, x-5, y+30); //left tooth
     triangle(x+15, y+14, x+5, y+12, x+10, y+30); //right tooth
   }
 }

Answers

  • The anwser is that you don't have a constructor that accepts 3 parameters, 2 ints and a float. Add this constructor

      Cat(float xTemp, float yTemp, float rndNumber) {
        x = xTemp;
        y = yTemp;
        xSpeed = random(-2, 2);
        ySpeed = random(-2, 2);
       // You obviously need to do something with rndNumber???
      }
    
Sign In or Register to comment.