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

**URL:** <https://discourse.processing.org/t/make-a-method-to-get-area-result-should-be-2000-println-rect1-sumarea-rect2/12402>\
**Category:** Coding Questions\
**Created:** [June 30, 2019, 9:35am UTC](https://discourse.processing.org/t/make-a-method-to-get-area-result-should-be-2000-println-rect1-sumarea-rect2/12402 "2019-06-30T09:35:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://discourse.processing.org/u/henry)\
**Post date:** [June 30, 2019, 9:35am UTC](https://discourse.processing.org/t/make-a-method-to-get-area-result-should-be-2000-println-rect1-sumarea-rect2/12402/1 "2019-06-30T09:35:07Z")

</div>

```auto
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);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 30, 2019, 10:02am UTC](https://discourse.processing.org/t/make-a-method-to-get-area-result-should-be-2000-println-rect1-sumarea-rect2/12402/2 "2019-06-30T10:02:24Z")

</div>

> [@henry](#):
>
> int sumArea(MyRect rect){  
> rect=
> 
> }

```auto
int sumArea(MyRect rect){
 
return width * height +
 rect.width * rect.height ;

}

```

---

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://discourse.processing.org/u/henry)\
**Post date:** [June 30, 2019, 10:32am UTC](https://discourse.processing.org/t/make-a-method-to-get-area-result-should-be-2000-println-rect1-sumarea-rect2/12402/3 "2019-06-30T10:32:28Z")

</div>

Thank you so much Chrisir!

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 30, 2019, 10:57am UTC](https://discourse.processing.org/t/make-a-method-to-get-area-result-should-be-2000-println-rect1-sumarea-rect2/12402/4 "2019-06-30T10:57:15Z")

</div>

This function gives you the sum of rect1 and rect2

---

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://discourse.processing.org/u/henry)\
**Post date:** [June 30, 2019, 12:03pm UTC](https://discourse.processing.org/t/make-a-method-to-get-area-result-should-be-2000-println-rect1-sumarea-rect2/12402/5 "2019-06-30T12:03:54Z")

</div>

yes ,  
I want the sum of rect1 and rect2
