ManipulateurRectangle.java 1.9 KB
package rectangles;
import java.util.*;

public class ManipulateurRectangle{

    public Rectangle[] tabRect;
    
    public void creerTableauRectangle(){
        Scanner sc = new Scanner(System.in);
        int nbRect=0;
        System.out.println("Nb Rectangle ?");
        nbRect = sc.nextInt();
        
        
        if(nbRect<1 ){
        	nbRect = 1;
        }
            tabRect = new Rectangle[nbRect];
        
            for(int i = 0; i< tabRect.length;i++){
                tabRect[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< tabRect.length;i++){
             res+= tabRect[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 < tabRect.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 < tabRect.length; i++){
                tabRect[i].origin.setLocation(tabRect[i].origin.getX()+decX,tabRect[i].origin.getY()+decY);
                tabRect[i].corner.setLocation(tabRect[i].corner.getX()+decX,tabRect[i].corner.getY()+decY);
            }
    }
}