משימת מיון מלבנים לבית

כתבו פעולה חיצונית שמקבלת כפרמטר מערך חד ממדי של MyRect

הפעולה תמיין את המלבנים לפי שטחם, מהקטן ביותר למלבן עם השטח הגדול
ביותר

ותדפיס את הפרש השטחים של שני המלבנים הגדול ביותר והקטן ביותר

רצוי ומומלץ להשתמש בפעולת עזר

יש להשלים את הפעולה area שמחלקה MyRect שמחזירה את שטח המלבן.

להלן חלק מהמחלקה MyRect

public class MyRect {

       private Point p1,p2;

       private final int MAX_ROWS = 30;

       private final int MAX_COLS = 30;

      

       public MyRect(Point p1, Point p2) {

              this.p1 = p1;

              this.p2 = p2;

       }

 

       public Point getP1() {

              return p1;

       }

 

       public void setP1(Point p1) {

              this.p1 = p1;

       }

 

       public Point getP2() {

              return p2;

       }

 

       public void setP2(Point p2) {

              this.p2 = p2;

       }

       private boolean isInRect(int row,int col) {

              int max_X = (int)Math.max(p1.getX(), p2.getX());

              int min_X = (int)Math.min(p1.getX(), p2.getX());

              int max_Y = (int)Math.max(p1.getY(), p2.getY());

              int min_Y = (int)Math.min(p1.getY(), p2.getY());

              return row >= min_Y && row <= max_Y && col >= min_X && col <= max_X;

       }

       public void print() {

              String str = "";

              for (int row=0;row<MAX_ROWS;row++) {

                     for (int col=0;col<MAX_COLS;col++) {

                           if (isInRect(row,col)) {

                                  str += "X";

                           }

                           else {

                                  str += " ";

                           }

                     }

                     str += "\n";

              }

              System.out.println(str);

       }

      

}