Make a method to get area, result should be 2000→ println(rect1.sumArea(rect2))

MyRect rect1;
MyRect rect2;

void setup(){
  size(240,120);
  rectMode(CENTER);
  rect1=new MyRect(20,20,40,30);
  rect2=new MyRect(30,50,20,40);

  println(rect1.sumArea(rect2));
}
 void draw(){
   rect1.drawShape(2);
   rect2.drawShape(4);

}
class MyRect {
  int x;
  int y;
  int width;
  int height;
  
  MyRect(int tempX, int tempY, int tempW, int tempH) {
    x=tempX;
    y=tempY;
    width=tempW;
    height=tempH;
  }
  int getArea() {
    return width*height;
  }
  int sumArea(MyRect rect){
     rect=

  }
    
  void drawShape(int weight) {
    strokeWeight(weight);
    rect(x, y, width, height);
  }
}
1 Like
int sumArea(MyRect rect){
 
return width * height +
 rect.width * rect.height ;

}
2 Likes

Thank you so much Chrisir!

1 Like

This function gives you the sum of rect1 and rect2

1 Like

yes ,
I want the sum of rect1 and rect2

1 Like