ManipulateurRectangle.java 1.77 KB
import java.util.*;

public class ManipulateurRectangle{

    Rectangle[] tabRe;
    
    public void creerTableauRectangle(){
        Scanner sc = new Scanner(System.in);
        int nbRect;
        System.out.println("Nb Rectangle ?");
        nbRect = sc.nextInt();
        
        tabRe = new Rectangle[nbRect];
        
        for(int i = 0; i< tabRe.length;i++){
            tabRe[i] = creerRectangle();
        }
        
        
    }

    public Rectangle creerRectangle(){
        Scanner sc = new Scanner(System.in);
        
        double[] valsPoint= new double[4];
        for(int i = 0;  i < valsPoint.length; i++){
            System.out.println("Coord"+i+"= ?");
            valsPoint[i] = sc.nextDouble();
        }
        
        return new Rectangle(valsPoint[0],valsPoint[1],valsPoint[2],valsPoint[3]);
    }

    public String toString(){
        String res="";
        for(int i = 0; i< tabRe.length;i++){
             res+= tabRe[i].toString()+"\n"; 
        }
        return res;
    }
    
    public Rectangle max(Rectangle[] t){
        Rectangle res = null;
        if(t.length>0){
            res = t[0];
            double surfaceMax = t[0].surface();
            for(int i = 1;  i < tabRe.length; i++){
                double tmp = t[i].surface();
                if( tmp > surfaceMax){
                res = t[i];
                surfaceMax = tmp;
                }
            }
            
        }
        return res;
    }
    
    public void decalerRectangles(double decX, double decY){
            for(int i = 0;  i < tabRe.length; i++){
                tabRe[i].origin.setLocation(tabRe[i].origin.getX()+decX,tabRe[i].origin.getY()+decY);
                tabRe[i].corner.setLocation(tabRe[i].corner.getX()+decX,tabRe[i].corner.getY()+decY);
            }
    }
}